ContextKeySet .java

net.minecraft.util.context.ContextKeySet (class, 56 lines): members: allowed, required, Builder. strings: " is already optional", " is already required".

net.minecraft.util.contextclass56 linescommon1.5 KB

API Surface (6)

Set<ContextKey<?>> required()
Set<ContextKey<?>> allowed()
String toString()
ContextKeySet.Builder required(final ContextKey<?> param)
ContextKeySet.Builder optional(final ContextKey<?> param)
ContextKeySet build()

Fields & Constants (2)

required
allowed

String literals (3)

"Parameter "
" is already optional"
" is already required"

Code Graph: Dependencies (1)

Edges (calls / imports / inherits / references) resolved by graphify from the AST. Every chip opens the class source.

Full Source

ContextKeySet.java56 lines · Minecraft 26.3 · verbatim
1
package net.minecraft.util.context;
2
3
import com.google.common.base.Joiner;
4
import com.google.common.collect.Sets;
5
import java.util.Set;
6
7
public class ContextKeySet {
8
	private final Set<ContextKey<?>> required;
9
	private final Set<ContextKey<?>> allowed;
10
11
	private ContextKeySet(final Set<ContextKey<?>> required, final Set<ContextKey<?>> optional) {
12
		this.required = Set.copyOf(required);
13
		this.allowed = Set.copyOf(Sets.union(required, optional));
14
	}
15
16
	public Set<ContextKey<?>> required() {
17
		return this.required;
18
	}
19
20
	public Set<ContextKey<?>> allowed() {
21
		return this.allowed;
22
	}
23
24
	@Override
25
	public String toString() {
26
		return "[" + Joiner.on(", ").join(this.allowed.stream().map(k -> (this.required.contains(k) ? "!" : "") + k.name()).iterator()) + "]";
27
	}
28
29
	public static class Builder {
30
		private final Set<ContextKey<?>> required = Sets.newIdentityHashSet();
31
		private final Set<ContextKey<?>> optional = Sets.newIdentityHashSet();
32
33
		public ContextKeySet.Builder required(final ContextKey<?> param) {
34
			if (this.optional.contains(param)) {
35
				throw new IllegalArgumentException("Parameter " + param.name() + " is already optional");
36
			}
37
38
			this.required.add(param);
39
			return this;
40
		}
41
42
		public ContextKeySet.Builder optional(final ContextKey<?> param) {
43
			if (this.required.contains(param)) {
44
				throw new IllegalArgumentException("Parameter " + param.name() + " is already required");
45
			}
46
47
			this.optional.add(param);
48
			return this;
49
		}
50
51
		public ContextKeySet build() {
52
			return new ContextKeySet(this.required, this.optional);
53
		}
54
	}
55
}
56

Decompiled Minecraft 26.3 source of ContextKeySet (net/minecraft/util/context/ContextKeySet.java) with Mojang official mappings, stored verbatim on the site.