CodepointMap.java

net.minecraft.client.gui.font.CodepointMap

信息

  • 全限定名:net.minecraft.client.gui.font.CodepointMap
  • 类型:public class
  • 包:net.minecraft.client.gui.font
  • 源码路径:src/main/java/net/minecraft/client/gui/font/CodepointMap.java
  • 起始行号:L12
  • 职责:

    TODO

字段/常量

  • BLOCK_BITS

    • 类型: int
    • 修饰符: private static final
    • 源码定位: L13
    • 说明:

      TODO

  • BLOCK_SIZE

    • 类型: int
    • 修饰符: private static final
    • 源码定位: L14
    • 说明:

      TODO

  • IN_BLOCK_MASK

    • 类型: int
    • 修饰符: private static final
    • 源码定位: L15
    • 说明:

      TODO

  • MAX_BLOCK

    • 类型: int
    • 修饰符: private static final
    • 源码定位: L16
    • 说明:

      TODO

  • BLOCK_COUNT

    • 类型: int
    • 修饰符: private static final
    • 源码定位: L17
    • 说明:

      TODO

  • empty

    • 类型: T[]
    • 修饰符: private final
    • 源码定位: L18
    • 说明:

      TODO

  • blockMap

    • 类型: T[][]
    • 修饰符: private final
    • 源码定位: L19
    • 说明:

      TODO

  • blockConstructor

    • 类型: IntFunction<T[]>
    • 修饰符: private final
    • 源码定位: L20
    • 说明:

      TODO

内部类/嵌套类型

  • net.minecraft.client.gui.font.CodepointMap.Output
    • 类型: interface
    • 修饰符: public
    • 源码定位: L110
    • 说明:

      TODO

构造器

public CodepointMap(IntFunction<T[]> blockConstructor, IntFunction<T[][]> blockMapConstructor) @ L22

  • 构造器名:CodepointMap
  • 源码定位:L22
  • 修饰符:public

参数:

  • blockConstructor: IntFunction<T[]>
  • blockMapConstructor: IntFunction<T[][]>

说明:

TODO

方法

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

public void clear() @ L29

  • 方法名:clear
  • 源码定位:L29
  • 返回类型:void
  • 修饰符:public

参数:

说明:

TODO

public T get(int codepoint) @ L33

  • 方法名:get
  • 源码定位:L33
  • 返回类型:T
  • 修饰符:public

参数:

  • codepoint: int

说明:

TODO

public T put(int codepoint, T value) @ L39

  • 方法名:put
  • 源码定位:L39
  • 返回类型:T
  • 修饰符:public

参数:

  • codepoint: int
  • value: T

说明:

TODO

public T computeIfAbsent(int codepoint, IntFunction<T> mapper) @ L55

  • 方法名:computeIfAbsent
  • 源码定位:L55
  • 返回类型:T
  • 修饰符:public

参数:

  • codepoint: int
  • mapper: IntFunction

说明:

TODO

public T remove(int codepoint) @ L74

  • 方法名:remove
  • 源码定位:L74
  • 返回类型:T
  • 修饰符:public

参数:

  • codepoint: int

说明:

TODO

public void forEach(CodepointMap.Output<T> output) @ L87

  • 方法名:forEach
  • 源码定位:L87
  • 返回类型:void
  • 修饰符:public

参数:

  • output: CodepointMap.Output

说明:

TODO

public IntSet keySet() @ L102

  • 方法名:keySet
  • 源码定位:L102
  • 返回类型:IntSet
  • 修饰符:public

参数:

说明:

TODO

代码

@OnlyIn(Dist.CLIENT)
public class CodepointMap<T> {
    private static final int BLOCK_BITS = 8;
    private static final int BLOCK_SIZE = 256;
    private static final int IN_BLOCK_MASK = 255;
    private static final int MAX_BLOCK = 4351;
    private static final int BLOCK_COUNT = 4352;
    private final T[] empty;
    private final @Nullable T[][] blockMap;
    private final IntFunction<T[]> blockConstructor;
 
    public CodepointMap(IntFunction<T[]> blockConstructor, IntFunction<T[][]> blockMapConstructor) {
        this.empty = (T[])((Object[])blockConstructor.apply(256));
        this.blockMap = (T[][])((Object[][])blockMapConstructor.apply(4352));
        Arrays.fill(this.blockMap, this.empty);
        this.blockConstructor = blockConstructor;
    }
 
    public void clear() {
        Arrays.fill(this.blockMap, this.empty);
    }
 
    public @Nullable T get(int codepoint) {
        int block = codepoint >> 8;
        int offset = codepoint & 0xFF;
        return this.blockMap[block][offset];
    }
 
    public @Nullable T put(int codepoint, T value) {
        int block = codepoint >> 8;
        int offset = codepoint & 0xFF;
        T[] blockData = this.blockMap[block];
        if (blockData == this.empty) {
            blockData = (T[])((Object[])this.blockConstructor.apply(256));
            this.blockMap[block] = blockData;
            blockData[offset] = value;
            return null;
        } else {
            T previous = blockData[offset];
            blockData[offset] = value;
            return previous;
        }
    }
 
    public T computeIfAbsent(int codepoint, IntFunction<T> mapper) {
        int block = codepoint >> 8;
        int offset = codepoint & 0xFF;
        T[] blockData = this.blockMap[block];
        T current = blockData[offset];
        if (current != null) {
            return current;
        } else {
            if (blockData == this.empty) {
                blockData = (T[])((Object[])this.blockConstructor.apply(256));
                this.blockMap[block] = blockData;
            }
 
            T result = mapper.apply(codepoint);
            blockData[offset] = result;
            return result;
        }
    }
 
    public @Nullable T remove(int codepoint) {
        int block = codepoint >> 8;
        int offset = codepoint & 0xFF;
        T[] blockData = this.blockMap[block];
        if (blockData == this.empty) {
            return null;
        } else {
            T previous = blockData[offset];
            blockData[offset] = null;
            return previous;
        }
    }
 
    public void forEach(CodepointMap.Output<T> output) {
        for (int block = 0; block < this.blockMap.length; block++) {
            T[] blockData = this.blockMap[block];
            if (blockData != this.empty) {
                for (int offset = 0; offset < blockData.length; offset++) {
                    T value = blockData[offset];
                    if (value != null) {
                        int codepoint = block << 8 | offset;
                        output.accept(codepoint, value);
                    }
                }
            }
        }
    }
 
    public IntSet keySet() {
        IntOpenHashSet result = new IntOpenHashSet();
        this.forEach((codepoint, value) -> result.add(codepoint));
        return result;
    }
 
    @FunctionalInterface
    @OnlyIn(Dist.CLIENT)
    public interface Output<T> {
        void accept(int codepoint, T value);
    }
}

引用的其他类