jigcell.compare.data
Class EditableDataElement

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
All Implemented Interfaces:
java.awt.datatransfer.Transferable, java.io.Serializable, IDataElement, IEditableDataElement
Direct Known Subclasses:
PackedDoubleDataElement, TreeDataElement

public abstract class EditableDataElement
extends DataElement
implements IEditableDataElement

A helper implementation for editable data element classes. Handles the parsing of a text representation of an element and provides a default implementation for nearly every method required by IEditableDataElement. EditableDataElement is not synchronized and in particular does not protect against concurrent edits.

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
protected static class EditableDataElement.EditableDataElementDelegate
          Persists the element using a flat string rather than trying to save the values table.
 
Nested classes/interfaces inherited from interface jigcell.compare.IDataElement
IDataElement.Type
 
Field Summary
protected static java.lang.Double DOUBLE_NaN
          NaN
protected static java.lang.Double DOUBLE_NINFINITY
          -Infinity
protected static java.lang.Double DOUBLE_PINFINITY
          +Infinity
protected static java.lang.String MESSAGE_PARSEBLOCKERROR
          Message when unable to parse element text due to bad block nesting
protected static java.lang.String MESSAGE_PARSEERROR
          Message when unable to parse element text
protected static java.lang.String MESSAGE_PARSEEXTRAERROR
          Message when unable to parse element text due to too much input
protected static java.lang.String MESSAGE_PARSELITERALERROR
          Message when unable to parse element text due to unterminated literal
protected static char PATTERN_FP
          Pattern indicating value is floating point
protected  EditableDataElement prototypeChild
          Prototypical instance of a subelement
protected static java.lang.String TOKEN_ALL
          All of the tokens used by the parser
protected static java.lang.String TOKEN_BLOCKELEMENT
          Token to separate block elements
protected static java.lang.String TOKEN_BLOCKEND
          Token to end a block
protected static java.lang.String TOKEN_BLOCKSTART
          Token to start a block
protected static java.lang.String TOKEN_LITERAL
          Token to delimit a 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
EditableDataElement()
           
 
Method Summary
protected abstract  EditableDataElement constructNew()
          Constructs a new element of the same type as this element.
 void copyValue(long pos1, long pos2)
          Copies a value within the element.
static EditableDataElement createElement(EditableDataElement element, java.io.Reader reader)
          Generates the map for an element from a streaming input.
private static EditableDataElement createElement(EditableDataElement element, StreamingStringTokenizer tokenizer, long pos)
          Generates the map for an element from a text string.
static IEditableDataElement createElement(IDataElement element)
          Generates an element from an existing DataElement.
static IEditableDataElement createElement(java.io.Reader reader)
          Generates an element from streaming input.
static IEditableDataElement createElement(java.lang.String text)
          Generates an element from a text string.
static IEditableDataElement createElementSafe(IDataElement element)
          Generates an element from an existing DataElement.
static IEditableDataElement createElementSafe(java.io.Reader reader)
          Generates an element from streaming input.
static IEditableDataElement createElementSafe(java.lang.String text)
          Generates an element from a text string.
static IEditableDataElement createScalarElement(boolean value)
          Generates an element from a boolean.
static IEditableDataElement createScalarElement(double value)
          Generates an element from a double.
static IEditableDataElement createScalarElement(long value)
          Generates an element from a long.
static IEditableDataElement createScalarElement(java.lang.String value)
          Generates an element from a string.
 boolean[] forceSlice(boolean[] slice, long start, int length, long stride)
          A dense, homogeneous subset of this element represented as a boolean list. If slice cannot hold the requested range, a new array is created and returned. Slice may be null. If the given length has no valid meaning, the value is null. Elements not of type boolean are suitably coerced. Past the defined range of the list, all values are considered false. Position 0 in the returned slice corresponds to position start in the original element.
 double[] forceSlice(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 length has no valid meaning, the value is null. Elements not of type real are suitably coerced. Past the defined range of the list, all values are considered NaN. Position 0 in the returned slice corresponds to position start in the original element.
 IDataElement[] forceSlice(IDataElement[] slice, long start, int length, long stride)
          A dense, homogeneous subset of this element represented as a list of elements. If slice cannot hold the requested range, a new array is created and returned. Slice may be null. If the given length has no valid meaning, the value is null. Elements not of type list are suitably coerced. Past the defined range of the list, all values are considered scalars of no type. Position 0 in the returned slice corresponds to position start in the original element.
 long[] forceSlice(long[] slice, long start, int length, long stride)
          A dense, homogeneous subset of this element represented as an integral list. If slice cannot hold the requested range, a new array is created and returned. Slice may be null. If the given length has no valid meaning, the value is null. Elements not of type integral are suitably coerced. Past the defined range of the list, all values are considered 0. Position 0 in the returned slice corresponds to position start in the original element.
 boolean getBooleanValue(long pos)
          The element at position pos represented as a boolean. If the given position has no valid meaning for this element, the value is false.
protected  java.lang.Object getChecked(long pos)
          Gets the value at a position.
protected abstract  java.lang.Object getDirect(long pos)
          Gets the value at a position.
 long getIntegralValue(long pos)
          The element at position pos represented as an integer. If the given position has no valid meaning for this element, the value is 0.
 IDataElement getListValue(long pos)
          This element at position pos represented as a list. If the given position has no valid meaning for this element, the value is null.
 java.lang.String getLiteralValue(long pos)
          The element at position pos represented as a string literal. If the given position has no valid meaning for this element, the value is null. The literal is not quoted.
 EditableDataElement getPrototypeChild()
          The prototypical instance of a subelement.
 double getRealValue(long pos)
          The element at position pos represented as a real. If the given position has no valid meaning for this element, the value is NaN.
 IDataElement.Type getType()
          The type of this element.
 IDataElement.Type getType(long pos)
          The type of the element at position pos. If the given position has no valid meaning for this object, the type is TYPE_NONE.
 void makeList()
          Converts this element to a list.
 void moveValue(long pos1, long pos2)
          Moves a value within the element.
protected  void putChecked(long pos, java.lang.Object value)
          Sets the value at a position.
protected abstract  void putDirect(long pos, java.lang.Object value)
          Sets the value at a position.
protected abstract  void removeDirect(long pos)
          Removes the value at a position.
protected abstract  void setLengthDirect(long length)
          Sets the known length of an element.
 void setPrototypeChild(EditableDataElement prototypeChild)
          Sets the prototypical instance of a subelement
 void setValue(boolean value)
          Sets the element to a boolean.
 void setValue(double value)
          Sets the element to a double.
 void setValue(IDataElement value)
          Sets the element to a list.
 void setValue(long value)
          Sets the element to a long.
 void setValue(long pos, boolean value)
          Sets an element value to a boolean.
 void setValue(long pos, double value)
          Sets an element value to a double.
 void setValue(long pos, IDataElement value)
          Sets an element value to a list.
 void setValue(long pos, long value)
          Sets an element value to a long.
 void setValue(long pos, java.lang.String value)
          Sets an element value to a string.
 void setValue(java.lang.String value)
          Sets the element to a String.
 void setValueInterpreted(long pos, java.lang.String value)
          Sets an element value by parsing the textual representation of an element.
 void setValueInterpreted(java.lang.String value)
          Sets the element by parsing the textual representation of an element.
 void swapValues(long pos1, long pos2)
          Exchanges values within the element.
 void unsetValue(long pos)
          Deletes an element value.
 
Methods inherited from class jigcell.compare.data.DataElement
forceBooleanValue, forceBooleanValue, forceIntegralValue, forceIntegralValue, forceListValue, forceLiteralValue, forceLiteralValue, forceRealValue, forceRealValue, forceSlice, getBooleanValue, getIntegralValue, getLength, getLiteralValue, getLongObject, getRealValue, getSlice, getSlice, getSlice, getSlice, getSlice, getTransferData, isAvailable, isScalar, isSpecialNonNumeric, memoryLock, memoryUnlock, 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.IEditableDataElement
clear
 
Methods inherited from interface jigcell.compare.IDataElement
forceBooleanValue, forceBooleanValue, forceIntegralValue, forceIntegralValue, forceListValue, forceLiteralValue, forceLiteralValue, forceRealValue, forceRealValue, forceSlice, getBooleanValue, getIntegralValue, getLength, getLiteralValue, getRealValue, getSlice, getSlice, getSlice, getSlice, getSlice, isAvailable, isScalar, memoryLock, memoryUnlock, toString, toString, toString, toString, toString, toString, toString
 
Methods inherited from interface java.awt.datatransfer.Transferable
getTransferData, getTransferDataFlavors, isDataFlavorSupported
 

Field Detail

PATTERN_FP

protected static final char PATTERN_FP
Pattern indicating value is floating point

See Also:
Constant Field Values

DOUBLE_NaN

protected static final java.lang.Double DOUBLE_NaN
NaN


DOUBLE_NINFINITY

protected static final java.lang.Double DOUBLE_NINFINITY
-Infinity


DOUBLE_PINFINITY

protected static final java.lang.Double DOUBLE_PINFINITY
+Infinity


MESSAGE_PARSEBLOCKERROR

protected static final java.lang.String MESSAGE_PARSEBLOCKERROR
Message when unable to parse element text due to bad block nesting

See Also:
Constant Field Values

MESSAGE_PARSEERROR

protected static final java.lang.String MESSAGE_PARSEERROR
Message when unable to parse element text

See Also:
Constant Field Values

MESSAGE_PARSEEXTRAERROR

protected static final java.lang.String MESSAGE_PARSEEXTRAERROR
Message when unable to parse element text due to too much input

See Also:
Constant Field Values

MESSAGE_PARSELITERALERROR

protected static final java.lang.String MESSAGE_PARSELITERALERROR
Message when unable to parse element text due to unterminated literal

See Also:
Constant Field Values

TOKEN_ALL

protected static final java.lang.String TOKEN_ALL
All of the tokens used by the parser

See Also:
Constant Field Values

TOKEN_BLOCKELEMENT

protected static final java.lang.String TOKEN_BLOCKELEMENT
Token to separate block elements

See Also:
Constant Field Values

TOKEN_BLOCKEND

protected static final java.lang.String TOKEN_BLOCKEND
Token to end a block

See Also:
Constant Field Values

TOKEN_BLOCKSTART

protected static final java.lang.String TOKEN_BLOCKSTART
Token to start a block

See Also:
Constant Field Values

TOKEN_LITERAL

protected static final java.lang.String TOKEN_LITERAL
Token to delimit a literal

See Also:
Constant Field Values

prototypeChild

protected EditableDataElement prototypeChild
Prototypical instance of a subelement

Constructor Detail

EditableDataElement

public EditableDataElement()
Method Detail

createElement

public static IEditableDataElement createElement(IDataElement element)
Generates an element from an existing DataElement.

Parameters:
element - DataElement

createElement

public static EditableDataElement createElement(EditableDataElement element,
                                                java.io.Reader reader)
Generates the map for an element from a streaming input.

Parameters:
element - Element to populate
reader - Reader

createElement

public static IEditableDataElement createElement(java.lang.String text)
Generates an element from a text string.

Parameters:
text - String to parse

createElement

public static IEditableDataElement createElement(java.io.Reader reader)
Generates an element from streaming input.

Parameters:
reader - Reader

createElementSafe

public static IEditableDataElement createElementSafe(IDataElement element)
Generates an element from an existing DataElement. If an element cannot be created, an empty element is returned.

Parameters:
element - DataElement

createElementSafe

public static IEditableDataElement createElementSafe(java.lang.String text)
Generates an element from a text string. If an element cannot be created, an empty element in returned.

Parameters:
text - String to parse

createElementSafe

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

Parameters:
reader - Reader

createScalarElement

public static IEditableDataElement createScalarElement(boolean value)
Generates an element from a boolean.

Parameters:
value - Value

createScalarElement

public static IEditableDataElement createScalarElement(double value)
Generates an element from a double.

Parameters:
value - Value

createScalarElement

public static IEditableDataElement createScalarElement(long value)
Generates an element from a long.

Parameters:
value - Value

createScalarElement

public static IEditableDataElement createScalarElement(java.lang.String value)
Generates an element from a string.

Parameters:
value - Value

createElement

private static EditableDataElement createElement(EditableDataElement element,
                                                 StreamingStringTokenizer tokenizer,
                                                 long pos)
Generates the map for an element from a text string.

Parameters:
element - Element to populate
tokenizer - Tokenizer to obtain input from
pos - Initial position to store element data at

copyValue

public void copyValue(long pos1,
                      long pos2)
Copies a value within the element.

Specified by:
copyValue in interface IEditableDataElement
Parameters:
pos1 - Position to copy from
pos2 - Position to copy to

forceSlice

public boolean[] forceSlice(boolean[] slice,
                            long start,
                            int length,
                            long stride)
A dense, homogeneous subset of this element represented as a boolean list. If slice cannot hold the requested range, a new array is created and returned. Slice may be null. If the given length has no valid meaning, the value is null. Elements not of type boolean are suitably coerced. Past the defined range of the list, all values are considered false. Position 0 in the returned slice corresponds to position start in the original element.

Specified by:
forceSlice in interface IDataElement
Overrides:
forceSlice 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

forceSlice

public IDataElement[] forceSlice(IDataElement[] slice,
                                 long start,
                                 int length,
                                 long stride)
A dense, homogeneous subset of this element represented as a list of elements. If slice cannot hold the requested range, a new array is created and returned. Slice may be null. If the given length has no valid meaning, the value is null. Elements not of type list are suitably coerced. Past the defined range of the list, all values are considered scalars of no type. Position 0 in the returned slice corresponds to position start in the original element.

Specified by:
forceSlice in interface IDataElement
Overrides:
forceSlice 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

forceSlice

public double[] forceSlice(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 length has no valid meaning, the value is null. Elements not of type real are suitably coerced. Past the defined range of the list, all values are considered NaN. Position 0 in the returned slice corresponds to position start in the original element.

Specified by:
forceSlice in interface IDataElement
Overrides:
forceSlice 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

forceSlice

public long[] forceSlice(long[] slice,
                         long start,
                         int length,
                         long stride)
A dense, homogeneous subset of this element represented as an integral list. If slice cannot hold the requested range, a new array is created and returned. Slice may be null. If the given length has no valid meaning, the value is null. Elements not of type integral are suitably coerced. Past the defined range of the list, all values are considered 0. Position 0 in the returned slice corresponds to position start in the original element.

Specified by:
forceSlice in interface IDataElement
Overrides:
forceSlice 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

getBooleanValue

public boolean getBooleanValue(long pos)
The element at position pos represented as a boolean. If the given position has no valid meaning for this element, the value is false.

Specified by:
getBooleanValue in interface IDataElement
Overrides:
getBooleanValue in class DataElement
Parameters:
pos - Position

getIntegralValue

public long getIntegralValue(long pos)
The element at position pos represented as an integer. If the given position has no valid meaning for this element, the value is 0.

Specified by:
getIntegralValue in interface IDataElement
Overrides:
getIntegralValue in class DataElement
Parameters:
pos - Position

getListValue

public IDataElement getListValue(long pos)
This element at position pos represented as a list. If the given position has no valid meaning for this element, the value is null.

Specified by:
getListValue in interface IDataElement
Overrides:
getListValue in class DataElement
Parameters:
pos - Position

getLiteralValue

public java.lang.String getLiteralValue(long pos)
The element at position pos represented as a string literal. If the given position has no valid meaning for this element, the value is null. The literal is not quoted.

Specified by:
getLiteralValue in interface IDataElement
Overrides:
getLiteralValue in class DataElement
Parameters:
pos - Position

getPrototypeChild

public EditableDataElement getPrototypeChild()
The prototypical instance of a subelement.


getRealValue

public double getRealValue(long pos)
The element at position pos represented as a real. If the given position has no valid meaning for this element, the value is NaN.

Specified by:
getRealValue in interface IDataElement
Overrides:
getRealValue in class DataElement
Parameters:
pos - Position

getType

public IDataElement.Type getType()
The type of this element.

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

getType

public IDataElement.Type getType(long pos)
The type of the element at position pos. If the given position has no valid meaning for this object, the type is TYPE_NONE.

Specified by:
getType in interface IDataElement
Overrides:
getType in class DataElement
Parameters:
pos - Position

makeList

public void makeList()
Converts this element to a list.

Specified by:
makeList in interface IEditableDataElement

moveValue

public void moveValue(long pos1,
                      long pos2)
Moves a value within the element.

Specified by:
moveValue in interface IEditableDataElement
Parameters:
pos1 - The position to move from
pos2 - The position to move to

setPrototypeChild

public void setPrototypeChild(EditableDataElement prototypeChild)
Sets the prototypical instance of a subelement

Parameters:
prototypeChild - Instance

setValue

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

Specified by:
setValue in interface IEditableDataElement
Parameters:
value - Value

setValue

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

Specified by:
setValue in interface IEditableDataElement
Parameters:
value - Value

setValue

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

Specified by:
setValue in interface IEditableDataElement
Parameters:
value - Value

setValue

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

Specified by:
setValue in interface IEditableDataElement
Parameters:
value - Value

setValue

public void setValue(java.lang.String value)
Sets the element to a String.

Specified by:
setValue in interface IEditableDataElement
Parameters:
value - Value

setValue

public void setValue(long pos,
                     boolean value)
Sets an element value to a boolean.

Specified by:
setValue in interface IEditableDataElement
Parameters:
pos - Value position
value - Value

setValue

public void setValue(long pos,
                     IDataElement value)
Sets an element value to a list.

Specified by:
setValue in interface IEditableDataElement
Parameters:
pos - Value position
value - Value

setValue

public void setValue(long pos,
                     double value)
Sets an element value to a double.

Specified by:
setValue in interface IEditableDataElement
Parameters:
pos - Value position
value - Value

setValue

public void setValue(long pos,
                     long value)
Sets an element value to a long.

Specified by:
setValue in interface IEditableDataElement
Parameters:
pos - Value position
value - Value

setValue

public void setValue(long pos,
                     java.lang.String value)
Sets an element value to a string.

Specified by:
setValue in interface IEditableDataElement
Parameters:
pos - Value position
value - Value

setValueInterpreted

public void setValueInterpreted(java.lang.String value)
Sets the element by parsing the textual representation of an element.

Specified by:
setValueInterpreted in interface IEditableDataElement
Parameters:
value - Text to parse

setValueInterpreted

public void setValueInterpreted(long pos,
                                java.lang.String value)
Sets an element value by parsing the textual representation of an element.

Specified by:
setValueInterpreted in interface IEditableDataElement
Parameters:
pos - Value position
value - Text to parse

swapValues

public void swapValues(long pos1,
                       long pos2)
Exchanges values within the element.

Specified by:
swapValues in interface IEditableDataElement
Parameters:
pos1 - A position to exchange
pos2 - Another position to exchange

unsetValue

public void unsetValue(long pos)
Deletes an element value.

Specified by:
unsetValue in interface IEditableDataElement
Parameters:
pos - Value position

constructNew

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


getChecked

protected java.lang.Object getChecked(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 must be valid.

Parameters:
pos - Position

getDirect

protected abstract 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.

Parameters:
pos - Position

putChecked

protected void putChecked(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 must be valid.

Parameters:
pos - Position
value - Value

putDirect

protected abstract 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.

Parameters:
pos - Position
value - Value

removeDirect

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

Parameters:
pos - Position

setLengthDirect

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

Parameters:
length - Length of element