LocalSampleLogger.java

net.minecraft.util.debugchart.LocalSampleLogger

信息

  • 全限定名:net.minecraft.util.debugchart.LocalSampleLogger
  • 类型:public class
  • 包:net.minecraft.util.debugchart
  • 源码路径:src/main/java/net/minecraft/util/debugchart/LocalSampleLogger.java
  • 起始行号:L3
  • 继承:AbstractSampleLogger
  • 实现:SampleStorage
  • 职责:

    TODO

字段/常量

  • CAPACITY

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

      TODO

  • samples

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

      TODO

  • start

    • 类型: int
    • 修饰符: private
    • 源码定位: L6
    • 说明:

      TODO

  • size

    • 类型: int
    • 修饰符: private
    • 源码定位: L7
    • 说明:

      TODO

内部类/嵌套类型

构造器

public LocalSampleLogger(int dimensions) @ L9

  • 构造器名:LocalSampleLogger
  • 源码定位:L9
  • 修饰符:public

参数:

  • dimensions: int

说明:

TODO

public LocalSampleLogger(int dimensions, long[] defaults) @ L13

  • 构造器名:LocalSampleLogger
  • 源码定位:L13
  • 修饰符:public

参数:

  • dimensions: int
  • defaults: long[]

说明:

TODO

方法

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

protected void useSample() @ L18

  • 方法名:useSample
  • 源码定位:L18
  • 返回类型:void
  • 修饰符:protected

参数:

说明:

TODO

public int capacity() @ L29

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

参数:

说明:

TODO

public int size() @ L34

  • 方法名:size
  • 源码定位:L34
  • 返回类型:int
  • 修饰符:public

参数:

说明:

TODO

public long get(int index) @ L39

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

参数:

  • index: int

说明:

TODO

public long get(int index, int dimension) @ L44

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

参数:

  • index: int
  • dimension: int

说明:

TODO

private int wrapIndex(int index) @ L58

  • 方法名:wrapIndex
  • 源码定位:L58
  • 返回类型:int
  • 修饰符:private

参数:

  • index: int

说明:

TODO

public void reset() @ L62

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

参数:

说明:

TODO

代码

public class LocalSampleLogger extends AbstractSampleLogger implements SampleStorage {
    public static final int CAPACITY = 240;
    private final long[][] samples;
    private int start;
    private int size;
 
    public LocalSampleLogger(int dimensions) {
        this(dimensions, new long[dimensions]);
    }
 
    public LocalSampleLogger(int dimensions, long[] defaults) {
        super(dimensions, defaults);
        this.samples = new long[240][dimensions];
    }
 
    @Override
    protected void useSample() {
        int nextIndex = this.wrapIndex(this.start + this.size);
        System.arraycopy(this.sample, 0, this.samples[nextIndex], 0, this.sample.length);
        if (this.size < 240) {
            this.size++;
        } else {
            this.start = this.wrapIndex(this.start + 1);
        }
    }
 
    @Override
    public int capacity() {
        return this.samples.length;
    }
 
    @Override
    public int size() {
        return this.size;
    }
 
    @Override
    public long get(int index) {
        return this.get(index, 0);
    }
 
    @Override
    public long get(int index, int dimension) {
        if (index >= 0 && index < this.size) {
            long[] sampleArray = this.samples[this.wrapIndex(this.start + index)];
            if (dimension >= 0 && dimension < sampleArray.length) {
                return sampleArray[dimension];
            } else {
                throw new IndexOutOfBoundsException(dimension + " out of bounds for dimensions " + sampleArray.length);
            }
        } else {
            throw new IndexOutOfBoundsException(index + " out of bounds for length " + this.size);
        }
    }
 
    private int wrapIndex(int index) {
        return index % 240;
    }
 
    @Override
    public void reset() {
        this.start = 0;
        this.size = 0;
    }
}

引用的其他类