jigcell.compare.data
Class PackedDoubleDataElement

java.lang.Object
  extended by javax.swing.TransferHandler
      extended by jigcell.compare.impl.Transferer
          extended by jigcell.compare.data.DataElement
              extended by jigcell.compare.data.EditableDataElement
                  extended by jigcell.compare.data.PackedDoubleDataElement
All Implemented Interfaces:
java.awt.datatransfer.Transferable, java.io.Serializable, IDataElement, IEditableDataElement

public class PackedDoubleDataElement
extends EditableDataElement

An implementation of EditableDataElement that uses an array of doubles to store values. Only real values may be placed in this element. This structure is faster and smaller than a PackedTreeDataElement. Removing values from this element does not decrease the memory used until trimToSize (int) is called. PackedDoubleDataElement does not protect against concurrent edits. This element cannot index past 2^31-1. The maximum number of values this element can contain is approximately 2^29, but is likely to fail before then.

This code is licensed under the DARPA BioCOMP Open Source License. See LICENSE for more details.

Author:
Nicholas Allen
See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class jigcell.compare.data.EditableDataElement
EditableDataElement.EditableDataElementDelegate
 
Nested classes/interfaces inherited from interface jigcell.compare.IDataElement
IDataElement.Type
 
Field Summary
private  int length
          Element length
protected static java.lang.String MESSAGE_CHUNKSIZEERROR
          Error message when the chunk size is too small
protected static java.lang.Double NAN
          NaN
private  java.lang.Double scalar
          Placeholder for scalar value
private  int size
          Element pack size
protected static int SIZE_DEFAULTPACK
          Size of default element pack
private  double[] values
          Element values
 
Fields inherited from class jigcell.compare.data.EditableDataElement
DOUBLE_NaN, DOUBLE_NINFINITY, DOUBLE_PINFINITY, MESSAGE_PARSEBLOCKERROR, MESSAGE_PARSEERROR, MESSAGE_PARSEEXTRAERROR, MESSAGE_PARSELITERALERROR, PATTERN_FP, prototypeChild, TOKEN_ALL, TOKEN_BLOCKELEMENT, TOKEN_BLOCKEND, TOKEN_BLOCKSTART, TOKEN_LITERAL
 
Fields inherited from class jigcell.compare.data.DataElement
lockCount, LONGPOOL, PATTERN_FALSE, PATTERN_NAN, PATTERN_NINFINITY, PATTERN_NINFINITY2, PATTERN_NULL, PATTERN_PINFINITY, PATTERN_PINFINITY2, PATTERN_TRUE, PATTERN_VOID, SIZE_LONGPOOL
 
Fields inherited from class jigcell.compare.impl.Transferer
CSV_FOOTER, CSV_LINEPOSTPEND, CSV_LINEPREPEND, CSV_LINESEPARATOR, HTML_FOOTER, HTML_HEADPOSTPEND, HTML_HEADPREPEND, HTML_HEADSEPARATOR, HTML_LINEPOSTPEND, HTML_LINEPREPEND, HTML_LINESEPARATOR
 
Fields inherited from class javax.swing.TransferHandler
COPY, COPY_OR_MOVE, MOVE, NONE
 
Constructor Summary
PackedDoubleDataElement()
          Creates a new data element backed by an array of doubles.
PackedDoubleDataElement(int size)
          Creates a new data element with packed storage.
 
Method Summary
 void clear()
          Deletes all values in this element.
protected  EditableDataElement constructNew()
          Constructs a new element of the same type as this element.
static IEditableDataElement createElement(java.io.Reader reader)
          Generates a PackedDoubleDataElement from streaming input.
static IEditableDataElement createElementSafe(java.io.Reader reader)
          Generates a PackedDoubleDataElement from streaming input.
protected  java.lang.Object getDirect(long pos)
          Gets the value at a position.
 long getLength()
          The number of elements in this element, or 0 if this element is scalar.
 double[] getSlice(double[] slice, long start, int length, long stride)
          A dense, homogeneous subset of this element represented as a real list. If slice cannot hold the requested range, a new array is created and returned. Slice may be null. If the given start or length has no valid meaning for this element, the value is null. If the subset is not a dense list of reals or slices are not available, the value is null. Position 0 in the returned slice corresponds to position start in the original element.
 double[] getValues()
          The underlying array of this element.
 boolean isAvailable()
          Whether the element data can currently be worked with. Editing the internal state of a data generator while locked may cause subsequent calls to isAvailable to incorrectly report that the element data is available. The array store of this element is always available.
 void memoryLock()
          Forces the element to guarantee that the element data can currently be worked with. Implementations may or may not support reentrancy or other forms of multiple locking. Editing the internal state of a data generator while locked may cause subsequent calls to memoryLock to incorrectly terminate without guarantee that the element data can currently be worked with. Locking is unnecessary for this element.
 void memoryUnlock()
          Releases the element from the guarantee that the element data can currently be worked with. Implementations may or may not support reentrancy or other forms of multiple locking. Locking is unnecessary for this element.
protected  void putDirect(long pos, java.lang.Object value)
          Sets the value at a position.
protected  void removeDirect(long pos)
          Removes the value at a position.
protected  void setLengthDirect(long length)
          Sets the known length of an element.
 void setValue(IDataElement value)
          Sets the element to a list.
 void setValues(double[] values, int length)
          Sets the underlying array of this element.
 void trimToSize(int size)
          Trims the underlying array to a particular size.
 
Methods inherited from class jigcell.compare.data.EditableDataElement
copyValue, createElement, createElement, createElement, createElementSafe, createElementSafe, createScalarElement, createScalarElement, createScalarElement, createScalarElement, forceSlice, forceSlice, forceSlice, forceSlice, getBooleanValue, getChecked, getIntegralValue, getListValue, getLiteralValue, getPrototypeChild, getRealValue, getType, getType, makeList, moveValue, putChecked, setPrototypeChild, setValue, setValue, setValue, setValue, setValue, setValue, setValue, setValue, setValue, setValueInterpreted, setValueInterpreted, swapValues, unsetValue
 
Methods inherited from class jigcell.compare.data.DataElement
forceBooleanValue, forceBooleanValue, forceIntegralValue, forceIntegralValue, forceListValue, forceLiteralValue, forceLiteralValue, forceRealValue, forceRealValue, forceSlice, getBooleanValue, getIntegralValue, getLiteralValue, getLongObject, getRealValue, getSlice, getSlice, getSlice, getSlice, getTransferData, isScalar, isSpecialNonNumeric, toString, toString, toString, toString, toString, toString, toString, toString, toString, toString, toString, toString, toString, toString, toString, toString
 
Methods inherited from class jigcell.compare.impl.Transferer
addExtension, addFlavor, createCSVTable, createFormattedTable, createHTMLTable, getExceptionRecorder, getExpectedClasses, getExpectedClasses, getExpectedClasses, getFlavors, getFlavors, getPreferredExtensions, getPreferredExtensions, getTransferClass, getTransferDataFlavors, getTransferFlavor, isDataFlavorSupported, transfer
 
Methods inherited from class javax.swing.TransferHandler
canImport, createTransferable, exportAsDrag, exportDone, exportToClipboard, getCopyAction, getCutAction, getPasteAction, getSourceActions, getVisualRepresentation, importData
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface jigcell.compare.IDataElement
forceBooleanValue, forceBooleanValue, forceIntegralValue, forceIntegralValue, forceListValue, forceLiteralValue, forceLiteralValue, forceRealValue, forceRealValue, forceSlice, getBooleanValue, getIntegralValue, getLiteralValue, getRealValue, getSlice, getSlice, getSlice, getSlice, isScalar, toString, toString, toString, toString, toString, toString, toString
 
Methods inherited from interface java.awt.datatransfer.Transferable
getTransferData, getTransferDataFlavors, isDataFlavorSupported
 

Field Detail

NAN

protected static final java.lang.Double NAN
NaN


SIZE_DEFAULTPACK

protected static final int SIZE_DEFAULTPACK
Size of default element pack

See Also:
Constant Field Values

MESSAGE_CHUNKSIZEERROR

protected static final java.lang.String MESSAGE_CHUNKSIZEERROR
Error message when the chunk size is too small

See Also:
Constant Field Values

values

private double[] values
Element values


scalar

private java.lang.Double scalar
Placeholder for scalar value


length

private int length
Element length


size

private int size
Element pack size

Constructor Detail

PackedDoubleDataElement

public PackedDoubleDataElement()
Creates a new data element backed by an array of doubles.


PackedDoubleDataElement

public PackedDoubleDataElement(int size)
Creates a new data element with packed storage.

Parameters:
size - Pack size
Method Detail

createElement

public static IEditableDataElement createElement(java.io.Reader reader)
Generates a PackedDoubleDataElement from streaming input.

Parameters:
reader - Reader

createElementSafe

public static IEditableDataElement createElementSafe(java.io.Reader reader)
Generates a PackedDoubleDataElement from streaming input. If an element cannot be created, an empty element in returned.

Parameters:
reader - Reader

clear

public void clear()
Deletes all values in this element.


getLength

public long getLength()
The number of elements in this element, or 0 if this element is scalar.

Specified by:
getLength in interface IDataElement
Overrides:
getLength in class DataElement

getSlice

public double[] getSlice(double[] slice,
                         long start,
                         int length,
                         long stride)
A dense, homogeneous subset of this element represented as a real list. If slice cannot hold the requested range, a new array is created and returned. Slice may be null. If the given start or length has no valid meaning for this element, the value is null. If the subset is not a dense list of reals or slices are not available, the value is null. Position 0 in the returned slice corresponds to position start in the original element.

Specified by:
getSlice in interface IDataElement
Overrides:
getSlice in class DataElement
Parameters:
slice - Suggested container for the slice
start - First position to pull
length - Number of positions to pull
stride - Interval between positions to pull

getValues

public double[] getValues()
The underlying array of this element.


isAvailable

public boolean isAvailable()
Whether the element data can currently be worked with. Editing the internal state of a data generator while locked may cause subsequent calls to isAvailable to incorrectly report that the element data is available. The array store of this element is always available.

Specified by:
isAvailable in interface IDataElement
Overrides:
isAvailable in class DataElement

memoryLock

public void memoryLock()
Forces the element to guarantee that the element data can currently be worked with. Implementations may or may not support reentrancy or other forms of multiple locking. Editing the internal state of a data generator while locked may cause subsequent calls to memoryLock to incorrectly terminate without guarantee that the element data can currently be worked with. Locking is unnecessary for this element.

Specified by:
memoryLock in interface IDataElement
Overrides:
memoryLock in class DataElement

memoryUnlock

public void memoryUnlock()
Releases the element from the guarantee that the element data can currently be worked with. Implementations may or may not support reentrancy or other forms of multiple locking. Locking is unnecessary for this element.

Specified by:
memoryUnlock in interface IDataElement
Overrides:
memoryUnlock in class DataElement

setValue

public void setValue(IDataElement value)
Sets the element to a list.

Specified by:
setValue in interface IEditableDataElement
Overrides:
setValue in class EditableDataElement
Parameters:
value - Value

setValues

public void setValues(double[] values,
                      int length)
Sets the underlying array of this element.

Parameters:
values - Underlying array

trimToSize

public void trimToSize(int size)
Trims the underlying array to a particular size. If the trimmed size is smaller than the current length, the length will be reduced. This does nothing if the underlying array is smaller than the requested size.

Parameters:
size - Size

constructNew

protected EditableDataElement constructNew()
Constructs a new element of the same type as this element.

Specified by:
constructNew in class EditableDataElement

getDirect

protected java.lang.Object getDirect(long pos)
Gets the value at a position. Boolean values are represented by Boolean. Empty values are represented by null. Integral values are represented by Integer. Literal values are represented by String. Multiple values are represented by DataElement. Real values are represented by Double. The position of the object may be anything.

Specified by:
getDirect in class EditableDataElement
Parameters:
pos - Position

putDirect

protected void putDirect(long pos,
                         java.lang.Object value)
Sets the value at a position. Boolean values are represented by Boolean. Empty values are represented by null. Integral values are represented by Integer. Literal values are represented by String. Multiple values are represented by DataElement. Real values are represented by Double. The position of the object may be anything.

Specified by:
putDirect in class EditableDataElement
Parameters:
pos - Position
value - Value

removeDirect

protected void removeDirect(long pos)
Removes the value at a position. The position of the object may be anything.

Specified by:
removeDirect in class EditableDataElement
Parameters:
pos - Position

setLengthDirect

protected void setLengthDirect(long length)
Sets the known length of an element. The length of the object may be anything.

Specified by:
setLengthDirect in class EditableDataElement
Parameters:
length - Length of element