Class ArrayBinList
- java.lang.Object
-
- uk.ac.starlink.ttools.plot2.layer.ArrayBinList
-
- All Implemented Interfaces:
BinList
public abstract class ArrayBinList extends java.lang.Object implements BinList
Abstract subclass of BinList suitable for implementations based on arrays. The defining feature is that the the maximum bin count can be described as an int rather than a long.- Since:
- 5 Oct 2015
- Author:
- Mark Taylor
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface uk.ac.starlink.ttools.plot2.layer.BinList
BinList.Result
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
ArrayBinList(int size, Combiner combiner)
Constructor.
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected abstract void
addBin(int index, ArrayBinList other)
Accumulates the contents of a numbered bin from another BinList into the corresponding bin of this BinList.void
addBins(ArrayBinList other)
Accumulates all the data from another BinList into this one.protected abstract void
copyBin(int index, Combiner.Container container)
Copies bin content from a Container into the storage used by this implementation for a given bin.static BinList.Result
createDoubleMaskResult(java.util.BitSet mask, double[] values)
Returns a Result implementation based on a bin occupation mask and an array of bin content values.static ArrayBinList
fromHashBinList(HashBinList in)
Tries to create an ArrayBinList with the same content as a supplied HashBinList.Combiner.Container
getBinContainer(long index)
Returns a container representing the current contents of a given bin.protected abstract double
getBinResultInt(int index)
Variant of thegetValue
method that takes a 32-bit index.Combiner
getCombiner()
Returns the combination method used for bins.BinList.Result
getResult()
Returns an object containing the result values accumulated into the bins so far.long
getSize()
Returns the maximum number of bins.void
submitToBin(long lndex, double datum)
Adds a given numeric value to the bin at the given index.protected abstract void
submitToBinInt(int index, double value)
Variant of theaddToBin
method that takes a 32-bit index.
-
-
-
Constructor Detail
-
ArrayBinList
protected ArrayBinList(int size, Combiner combiner)
Constructor.- Parameters:
size
- bin countcombiner
- combiner
-
-
Method Detail
-
submitToBinInt
protected abstract void submitToBinInt(int index, double value)
Variant of theaddToBin
method that takes a 32-bit index.- Parameters:
index
- bin indexvalue
- increment for the current bin value
-
getBinResultInt
protected abstract double getBinResultInt(int index)
Variant of thegetValue
method that takes a 32-bit index.- Parameters:
index
- bin index- Returns:
- bin value
-
copyBin
protected abstract void copyBin(int index, Combiner.Container container)
Copies bin content from a Container into the storage used by this implementation for a given bin. The container must be one appropriate to this bin list's Combiner.- Parameters:
index
- bin indexcontainer
- combiner's container containing bin state
-
addBin
protected abstract void addBin(int index, ArrayBinList other)
Accumulates the contents of a numbered bin from another BinList into the corresponding bin of this BinList. The effect is the same as if all the data submitted to the given bin ofother
had been submitted to the corresponding bin of this.The other list must be of the same type as this one.
- Parameters:
index
- index of a non-empty bin in the other listother
- second ArrayBinList compatible with this one- Throws:
java.lang.ClassCastException
- ifother
's type does not match this one
-
submitToBin
public void submitToBin(long lndex, double datum)
Description copied from interface:BinList
Adds a given numeric value to the bin at the given index. In general, NaN values should not be submitted.- Specified by:
submitToBin
in interfaceBinList
- Parameters:
lndex
- bin indexdatum
- finite value to submit to the bin
-
getSize
public long getSize()
Description copied from interface:BinList
Returns the maximum number of bins. All bins have an index in the range 0..size-1.
-
getCombiner
public Combiner getCombiner()
Description copied from interface:BinList
Returns the combination method used for bins.- Specified by:
getCombiner
in interfaceBinList
- Returns:
- combiner
-
getResult
public BinList.Result getResult()
Description copied from interface:BinList
Returns an object containing the result values accumulated into the bins so far.It is up to implementations to decide how to implement this method. In some cases the return value may be an adapter that extracts results as required from the data structure used for value accumulation, but in others it may return a new data structure which copies the accumulated values to a more compact form up front. Therefore this may or may not be an expensive method, and the return value may or may not be affected by subsequent
BinList.submitToBin(long, double)
calls.
-
getBinContainer
public Combiner.Container getBinContainer(long index)
Description copied from interface:BinList
Returns a container representing the current contents of a given bin. This is only intended for reading; the effect of submitting additional data to the returned container is not defined.This method is here to support conversion between different BinList implementations.
- Specified by:
getBinContainer
in interfaceBinList
- Parameters:
index
- bin index- Returns:
- container instance reporting the current state of the bin; may be null if the bin is not populated
-
addBins
public void addBins(ArrayBinList other)
Accumulates all the data from another BinList into this one. The effect is the same as if all the data submitted toother
had been submitted to this.The other list must be compatible with this one; of the same type and with the same bin count.
- Parameters:
other
- second ArrayBinList compatible with this one- Throws:
java.lang.ClassCastException
- ifother
's type does not match this one
-
fromHashBinList
public static ArrayBinList fromHashBinList(HashBinList in)
Tries to create an ArrayBinList with the same content as a supplied HashBinList. Null may be returned if it can't be done.- Parameters:
in
- bin list whose data is to be copied- Returns:
- array bin list with copied content, or null if unsuccessful
-
createDoubleMaskResult
public static BinList.Result createDoubleMaskResult(java.util.BitSet mask, double[] values)
Returns a Result implementation based on a bin occupation mask and an array of bin content values.- Parameters:
mask
- bin occupation maskvalues
- data values per bin
-
-