# Class ArrayBinList

java.lang.Object
uk.ac.starlink.ttools.plot2.layer.ArrayBinList

All Implemented Interfaces:
  `BinList`

public abstract class ArrayBinList extends 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 BinList

`BinList.Result`

## Constructor Summary

Constructors
Modifier
Constructor
Description
`protected`
`ArrayBinList(int size, Combiner combiner)`
Constructor.

## Method Summary

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(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 the `getValue` 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 the `addToBin` method that takes a 32-bit index.

### Methods inherited from class Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

## Constructor Details

### ArrayBinList

protected ArrayBinList(int size, Combiner combiner)
Constructor.

Parameters:
  `size` - bin count
  `combiner` - combiner

## Method Details

### submitToBinInt

protected abstract void submitToBinInt(int index, double value)
Variant of the `addToBin` method that takes a 32-bit index.

Parameters:
  `index` - bin index
  `value` - increment for the current bin value

### getBinResultInt

protected abstract double getBinResultInt(int index)
Variant of the `getValue` 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 index
  `container` - 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 of `other` 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 list
  `other` - second ArrayBinList compatible with this one
Throws:
  `ClassCastException` - if `other`'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 interface `BinList`
Parameters:
  `lndex` - bin index
  `datum` - 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.

Specified by:
  `getSize` in interface `BinList`
Returns:
  bin count

### getCombiner

public Combiner getCombiner()
Description copied from interface: `BinList`
Returns the combination method used for bins.

Specified by:
  `getCombiner` in interface `BinList`
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.

Specified by:
  `getResult` in interface `BinList`
Returns:
  accumulated bin values

### 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 interface `BinList`
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 to `other` 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:
  `ClassCastException` - if `other`'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(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 mask
  `values` - data values per bin