Package net.glowstone.util
Class VariableValueArray
java.lang.Object
net.glowstone.util.VariableValueArray
- All Implemented Interfaces:
 Cloneable
- 
Constructor Summary
Constructors - 
Method Summary
Modifier and TypeMethodDescriptionstatic intcalculateNeededBits(int number) Calculates the number of bits that would be needed to store the given value.clone()voidfill(long[] data) Fills the backing array with pre-determined values.intget(int index) Returns a value.long[]intintlongincreaseBitsPerValueTo(int newBitsPerValue) Creates a new VariableValueArray with the contents of this one, and the given bits per value.voidset(int index, int value) Sets a value. 
- 
Constructor Details
- 
VariableValueArray
public VariableValueArray(int bitsPerValue, int capacity) Creates an instance.- Parameters:
 bitsPerValue- the number of bits into which each value must fitcapacity- 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- ifindexis out of range
 - 
set
public void set(int index, int value) Sets a value.- Parameters:
 index- the entry to setvalue- the value to set it to- Throws:
 IndexOutOfBoundsException- ifindexis out of rangeIllegalArgumentException- ifvalueis out of range
 - 
increaseBitsPerValueTo
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
 - 
getBacking
public long[] getBacking() - 
getCapacity
public int getCapacity() - 
getBitsPerValue
public int getBitsPerValue() 
 -