ContextKeySet.java

net.minecraft.util.context.ContextKeySet

信息

  • 全限定名:net.minecraft.util.context.ContextKeySet
  • 类型:public class
  • 包:net.minecraft.util.context
  • 源码路径:src/main/java/net/minecraft/util/context/ContextKeySet.java
  • 起始行号:L7
  • 职责:

    TODO

字段/常量

  • required

    • 类型: Set<ContextKey<?>>
    • 修饰符: private final
    • 源码定位: L8
    • 说明:

      TODO

  • allowed

    • 类型: Set<ContextKey<?>>
    • 修饰符: private final
    • 源码定位: L9
    • 说明:

      TODO

内部类/嵌套类型

  • net.minecraft.util.context.ContextKeySet.Builder
    • 类型: class
    • 修饰符: public static
    • 源码定位: L29
    • 说明:

      TODO

构造器

private ContextKeySet(Set<ContextKey<?>> required, Set<ContextKey<?>> optional) @ L11

  • 构造器名:ContextKeySet
  • 源码定位:L11
  • 修饰符:private

参数:

  • required: Set<ContextKey<?>>
  • optional: Set<ContextKey<?>>

说明:

TODO

方法

下面的方法块按源码顺序生成。

public Set<ContextKey<?>> required() @ L16

  • 方法名:required
  • 源码定位:L16
  • 返回类型:Set<ContextKey<?>>
  • 修饰符:public

参数:

说明:

TODO

public Set<ContextKey<?>> allowed() @ L20

  • 方法名:allowed
  • 源码定位:L20
  • 返回类型:Set<ContextKey<?>>
  • 修饰符:public

参数:

说明:

TODO

public String toString() @ L24

  • 方法名:toString
  • 源码定位:L24
  • 返回类型:String
  • 修饰符:public

参数:

说明:

TODO

代码

public class ContextKeySet {
    private final Set<ContextKey<?>> required;
    private final Set<ContextKey<?>> allowed;
 
    private ContextKeySet(Set<ContextKey<?>> required, Set<ContextKey<?>> optional) {
        this.required = Set.copyOf(required);
        this.allowed = Set.copyOf(Sets.union(required, optional));
    }
 
    public Set<ContextKey<?>> required() {
        return this.required;
    }
 
    public Set<ContextKey<?>> allowed() {
        return this.allowed;
    }
 
    @Override
    public String toString() {
        return "[" + Joiner.on(", ").join(this.allowed.stream().map(k -> (this.required.contains(k) ? "!" : "") + k.name()).iterator()) + "]";
    }
 
    public static class Builder {
        private final Set<ContextKey<?>> required = Sets.newIdentityHashSet();
        private final Set<ContextKey<?>> optional = Sets.newIdentityHashSet();
 
        public ContextKeySet.Builder required(ContextKey<?> param) {
            if (this.optional.contains(param)) {
                throw new IllegalArgumentException("Parameter " + param.name() + " is already optional");
            } else {
                this.required.add(param);
                return this;
            }
        }
 
        public ContextKeySet.Builder optional(ContextKey<?> param) {
            if (this.required.contains(param)) {
                throw new IllegalArgumentException("Parameter " + param.name() + " is already required");
            } else {
                this.optional.add(param);
                return this;
            }
        }
 
        public ContextKeySet build() {
            return new ContextKeySet(this.required, this.optional);
        }
    }
}

引用的其他类

  • ContextKey
    • 引用位置: 参数/字段/返回值