jigcell.compare.data
Class CachedDataElement

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.CachedDataElement
All Implemented Interfaces:
java.awt.datatransfer.Transferable, java.io.Serializable, IDataElement

public class CachedDataElement
extends DataElement

A data element that provides a memory sensitive cache wrapped around another data element.

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 CachedDataElement.CachedDataElementDelegate
          Persists the element by creating a new wrapper around the cached element.
 
Nested classes/interfaces inherited from interface jigcell.compare.IDataElement
IDataElement.Type
 
Field Summary
protected  IDataElement cache
          Element for use in memory locking
protected  ExceptionRecorder exception
          Cached exception recorder for this transferer
protected  java.io.File file
          File where the data element can be found
protected  java.lang.ref.SoftReference ref
          Data element to cache
protected static java.lang.String TEMPFILE_PREFIX
          Prefix for temporary cache files
 
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
private CachedDataElement()
          Creates a new data element cache.
  CachedDataElement(IDataElement element)
          Creates a new data element cache.
 
Method Summary
protected  void createCachedElement(IDataElement element)
          Creates the backend representation of the cached 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  IDataElement getCachedElement()
          Retrieves the cached element for use.
protected  ExceptionRecorder getExceptionRecorder()
          The exception recorder this transferer should use.
 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.
 long getLength()
          The number of elements in this element, or 0 if this element is scalar.
 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.
 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.
 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.
 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.
 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.
private  void readObject(java.io.ObjectInputStream objectIn)
           
private  void writeObject(java.io.ObjectOutputStream objectOut)
           
 
Methods inherited from class jigcell.compare.data.DataElement
forceBooleanValue, forceBooleanValue, forceIntegralValue, forceIntegralValue, forceListValue, forceLiteralValue, forceLiteralValue, forceRealValue, forceRealValue, forceSlice, forceSlice, forceSlice, forceSlice, forceSlice, getBooleanValue, getIntegralValue, getLiteralValue, getLongObject, getRealValue, getSlice, 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, 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 java.awt.datatransfer.Transferable
getTransferDataFlavors, isDataFlavorSupported
 

Field Detail

TEMPFILE_PREFIX

protected static final java.lang.String TEMPFILE_PREFIX
Prefix for temporary cache files

See Also:
Constant Field Values

exception

protected transient ExceptionRecorder exception
Cached exception recorder for this transferer


file

protected transient java.io.File file
File where the data element can be found


cache

protected transient IDataElement cache
Element for use in memory locking


ref

protected transient java.lang.ref.SoftReference ref
Data element to cache

Constructor Detail

CachedDataElement

public CachedDataElement(IDataElement element)
                  throws java.io.IOException
Creates a new data element cache.

Parameters:
element - Element to cache
Throws:
java.io.IOException

CachedDataElement

private CachedDataElement()
Creates a new data element cache.

Method Detail

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

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

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

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

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.

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.

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.

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

createCachedElement

protected void createCachedElement(IDataElement element)
                            throws java.io.IOException
Creates the backend representation of the cached element.

Throws:
java.io.IOException

getCachedElement

protected IDataElement getCachedElement()
Retrieves the cached element for use.


getExceptionRecorder

protected ExceptionRecorder getExceptionRecorder()
The exception recorder this transferer should use. The recorder must be one that saves the last exception caught.

Overrides:
getExceptionRecorder in class Transferer

readObject

private void readObject(java.io.ObjectInputStream objectIn)
                 throws java.io.IOException,
                        java.lang.ClassNotFoundException
Throws:
java.io.IOException
java.lang.ClassNotFoundException

writeObject

private void writeObject(java.io.ObjectOutputStream objectOut)
                  throws java.io.IOException
Throws:
java.io.IOException