Class VariableValueArray

java.lang.Object
net.glowstone.util.VariableValueArray
All Implemented Interfaces:
Cloneable

public final class VariableValueArray extends Object implements Cloneable
  • Constructor Details

    • VariableValueArray

      public VariableValueArray(int bitsPerValue, int capacity)
      Creates an instance.
      Parameters:
      bitsPerValue - the number of bits into which each value must fit
      capacity - the number of entries
  • Method Details

    • calculateNeededBits

      public static int calculateNeededBits(int number)
      Calculates the number of bits that would be needed to store the given value.
      Parameters:
      number - the value
      Returns:
      The number of bits that would be needed to store the value.
    • fill

      public void fill(long[] data)
      Fills the backing array with pre-determined values.
      Parameters:
      data - the new backing array
    • getLargestPossibleValue

      public long getLargestPossibleValue()
    • get

      public int get(int index)
      Returns a value.
      Parameters:
      index - the entry to look up
      Returns:
      the entry value
      Throws:
      IndexOutOfBoundsException - if index is out of range
    • set

      public void set(int index, int value)
      Sets a value.
      Parameters:
      index - the entry to set
      value - the value to set it to
      Throws:
      IndexOutOfBoundsException - if index is out of range
      IllegalArgumentException - if value is out of range
    • increaseBitsPerValueTo

      public VariableValueArray increaseBitsPerValueTo(int newBitsPerValue)
      Creates a new VariableValueArray with the contents of this one, and the given bits per value.
      Parameters:
      newBitsPerValue - The new value. Must be larger than the current value ( getBitsPerValue()).
      Returns:
      A new VariableValueArray
      Throws:
      IllegalArgumentException - If newBitsPerValue is less than or equal to the current bits per value. Setting it to the same size would be a waste of resources, and decreasing could lead to data loss.
    • clone

      public VariableValueArray clone()
      Overrides:
      clone in class Object
    • getBacking

      public long[] getBacking()
    • getCapacity

      public int getCapacity()
    • getBitsPerValue

      public int getBitsPerValue()