simtools.data
Class AsciiFileDataSourceCollection

java.lang.Object
  extended by java.util.AbstractCollection<E>
      extended by java.util.AbstractList<E>
          extended by java.util.Vector
              extended by simtools.data.DataSourceCollection
                  extended by simtools.data.AsciiFileDataSourceCollection
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable, java.lang.Iterable, java.util.Collection, java.util.List, java.util.RandomAccess

public class AsciiFileDataSourceCollection
extends DataSourceCollection

A DataSourceCollection backed up by an ascii file containing the data source values. It could be a good idea to wrap a buffer around the collection, or around each individual source. The file is expected to be in the following format: on each line, there should be as many values as managed data sources The values may be integer (octal haxadecimal are OK) or floating point, and the maximum precision will be kept. For example, a 64-bit hexadecimal mask would be stored in a Long object.

Version:
1.0 2001
Author:
Nicolas Brodu
See Also:
Serialized Form

Nested Class Summary
 class AsciiFileDataSourceCollection.InvalidFormatException
           
 
Nested classes/interfaces inherited from class simtools.data.DataSourceCollection
DataSourceCollection.Container
 
Field Summary
protected  java.lang.String absoluteFileName
           
protected  java.lang.Object[] cachedEntry
           
protected  long cachedIndex
           
protected  java.lang.String charsetName
           
protected  boolean csv
           
protected  long currentIndex
           
static java.text.SimpleDateFormat dateFormat
           
static int DEFAULT_GRANULARITY
           
protected  java.io.RandomAccessFile file
           
protected  java.lang.String fileName
           
protected  int granularity
           
static java.lang.String ID_MARKER
           
protected  java.util.Vector indexOffset
           
protected  DataInfo[] info
           
static java.text.SimpleDateFormat longTimeFormat
           
protected  java.lang.Object[] max
           
protected  long maxReachedIndex
           
protected  java.lang.Object[] min
           
protected  DataInfo ourInfo
           
static java.text.SimpleDateFormat shortTimeFormat
           
protected  long sliceEnd
           
protected  int subsampling
          Subsampling allows to drop values in big files.
 
Fields inherited from class simtools.data.DataSourceCollection
buffers, endNotificationListeners, lastIndex, listeners, map, startIndex
 
Fields inherited from class java.util.Vector
capacityIncrement, elementCount, elementData
 
Fields inherited from class java.util.AbstractList
modCount
 
Constructor Summary
AsciiFileDataSourceCollection(java.io.File f, boolean csv)
           
AsciiFileDataSourceCollection(java.io.File f, int subsampling, boolean csv)
           
AsciiFileDataSourceCollection(java.io.File f, int subsampling, int desiredGranularity, boolean csv)
           
AsciiFileDataSourceCollection(java.io.File f, int subsampling, int desiredGranularity, java.lang.String charsetName, boolean csv)
           
AsciiFileDataSourceCollection(java.io.File f, int subsampling, java.lang.String charsetName, boolean csv)
           
AsciiFileDataSourceCollection(java.io.File f, java.lang.String charsetName, boolean csv)
           
 
Method Summary
 long computeLastIndex()
           
 java.lang.Object computeMax(int i)
           
 java.lang.Object computeMin(int i)
           
protected  java.lang.String convertToCharset(java.lang.String arg)
           
 java.lang.String getCharsetName()
           
 int getGranularity()
          get without an equivalent set: not possibly to change the granularity dynamically (do it yourself in subclass!!!)
 DataInfo getInformation()
           
 DataInfo getInformation(int i)
           
 java.lang.Object getMax(int i)
           
protected  java.lang.Object getMax(java.lang.Object o1, java.lang.Object o2)
          Returns the maximum of the 2 objects
 java.lang.Object getMin(int i)
           
protected  java.lang.Object getMin(java.lang.Object o1, java.lang.Object o2)
          Returns the minimum of the 2 objects
 int getSubsampling()
           
 java.lang.Object getValue(int i, long index)
          Function to get value does some buffer/cache handling job and should not be overloaded.
 java.lang.Object[] getValueArray(long index)
           
 java.lang.Object[] readFile()
           
 java.lang.Object[] readFile(boolean parse)
          Reads a line from the ascii file, and split tokens to read double values.
 java.lang.String readLineIgnoreComment()
           
 void setCharsetName(java.lang.String charsetName)
          Specify a charset for this file.
 void setSlice(long min, long max)
           
 void setSubsampling(int subsampling)
           
static java.lang.Number stringToDateNumber(java.lang.String v)
           
static java.lang.Number stringToTimeNumber(java.lang.String v)
           
 java.lang.Class valueClass(int i)
          Returns the more specialized superclass of all objects returned by the i-th data source.
 
Methods inherited from class simtools.data.DataSourceCollection
addEndNotificationListener, addListener, attachBuffer, bufferize, bufferize, bufferize, computeLastIndex, computeStartIndex, computeStartIndex, get, getByteMax, getByteMin, getByteValue, getCollectionContainers, getDoubleMax, getDoubleMin, getDoubleValue, getFloatMax, getFloatMin, getFloatValue, getIntegerMax, getIntegerMin, getIntegerValue, getKind, getLastIndex, getLastIndex, getLongMax, getLongMin, getLongValue, getShortMax, getShortMin, getShortValue, getStartIndex, getStartIndex, hashCode, isComparable, isCompound, notifyEndNotificationListeners, notifyListenersForCollectionRemoved, notifyListenersForDataSourceAdded, notifyListenersForDataSourceRemoved, notifyListenersForInfoChange, removeAllElements, removeEndNotificationListener, removeListener, sortedOrder
 
Methods inherited from class java.util.Vector
add, add, addAll, addAll, addElement, capacity, clear, clone, contains, containsAll, copyInto, elementAt, elements, ensureCapacity, equals, firstElement, get, indexOf, indexOf, insertElementAt, isEmpty, lastElement, lastIndexOf, lastIndexOf, remove, remove, removeAll, removeElement, removeElementAt, removeRange, retainAll, set, setElementAt, setSize, size, subList, toArray, toArray, toString, trimToSize
 
Methods inherited from class java.util.AbstractList
iterator, listIterator, listIterator
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.List
iterator, listIterator, listIterator
 

Field Detail

info

protected DataInfo[] info

min

protected java.lang.Object[] min

max

protected java.lang.Object[] max

cachedEntry

protected java.lang.Object[] cachedEntry

cachedIndex

protected long cachedIndex

charsetName

protected java.lang.String charsetName

subsampling

protected int subsampling
Subsampling allows to drop values in big files. Only one out of supsampling number lines is read. The first data line of the file is read, then (subsampling -1) lines are dropped, etc. Default is supsampling = 1, meaning all the lines are read.


DEFAULT_GRANULARITY

public static final int DEFAULT_GRANULARITY
See Also:
Constant Field Values

granularity

protected int granularity

indexOffset

protected transient java.util.Vector indexOffset

file

protected transient java.io.RandomAccessFile file

fileName

protected transient java.lang.String fileName

absoluteFileName

protected transient java.lang.String absoluteFileName

currentIndex

protected transient long currentIndex

maxReachedIndex

protected transient long maxReachedIndex

csv

protected final boolean csv

longTimeFormat

public static java.text.SimpleDateFormat longTimeFormat

shortTimeFormat

public static java.text.SimpleDateFormat shortTimeFormat

dateFormat

public static java.text.SimpleDateFormat dateFormat

ID_MARKER

public static final java.lang.String ID_MARKER
See Also:
Constant Field Values

ourInfo

protected DataInfo ourInfo

sliceEnd

protected long sliceEnd
Constructor Detail

AsciiFileDataSourceCollection

public AsciiFileDataSourceCollection(java.io.File f,
                                     boolean csv)
                              throws java.io.IOException,
                                     AsciiFileDataSourceCollection.InvalidFormatException
Throws:
java.io.IOException
AsciiFileDataSourceCollection.InvalidFormatException

AsciiFileDataSourceCollection

public AsciiFileDataSourceCollection(java.io.File f,
                                     java.lang.String charsetName,
                                     boolean csv)
                              throws java.io.IOException,
                                     AsciiFileDataSourceCollection.InvalidFormatException
Throws:
java.io.IOException
AsciiFileDataSourceCollection.InvalidFormatException

AsciiFileDataSourceCollection

public AsciiFileDataSourceCollection(java.io.File f,
                                     int subsampling,
                                     boolean csv)
                              throws java.io.IOException,
                                     AsciiFileDataSourceCollection.InvalidFormatException
Throws:
java.io.IOException
AsciiFileDataSourceCollection.InvalidFormatException

AsciiFileDataSourceCollection

public AsciiFileDataSourceCollection(java.io.File f,
                                     int subsampling,
                                     java.lang.String charsetName,
                                     boolean csv)
                              throws java.io.IOException,
                                     AsciiFileDataSourceCollection.InvalidFormatException
Throws:
java.io.IOException
AsciiFileDataSourceCollection.InvalidFormatException

AsciiFileDataSourceCollection

public AsciiFileDataSourceCollection(java.io.File f,
                                     int subsampling,
                                     int desiredGranularity,
                                     boolean csv)
                              throws java.io.IOException,
                                     AsciiFileDataSourceCollection.InvalidFormatException
Throws:
java.io.IOException
AsciiFileDataSourceCollection.InvalidFormatException

AsciiFileDataSourceCollection

public AsciiFileDataSourceCollection(java.io.File f,
                                     int subsampling,
                                     int desiredGranularity,
                                     java.lang.String charsetName,
                                     boolean csv)
                              throws java.io.IOException,
                                     AsciiFileDataSourceCollection.InvalidFormatException
Throws:
java.io.IOException
AsciiFileDataSourceCollection.InvalidFormatException
Method Detail

getCharsetName

public java.lang.String getCharsetName()
Returns:
Returns the charsetName. May be null if no charset is specified

setCharsetName

public void setCharsetName(java.lang.String charsetName)
Specify a charset for this file. All read operations will use this charset for converting the file bytes into characters. Null is the default, meaning no conversion is done.

Parameters:
charsetName - The charsetName to set. May be null for direct reading.

stringToTimeNumber

public static java.lang.Number stringToTimeNumber(java.lang.String v)

stringToDateNumber

public static java.lang.Number stringToDateNumber(java.lang.String v)

getInformation

public DataInfo getInformation(int i)
Overrides:
getInformation in class DataSourceCollection

getGranularity

public int getGranularity()
get without an equivalent set: not possibly to change the granularity dynamically (do it yourself in subclass!!!)


getSubsampling

public int getSubsampling()
Returns:

setSubsampling

public void setSubsampling(int subsampling)
Parameters:
subsampling -

getInformation

public DataInfo getInformation()
Overrides:
getInformation in class DataSourceCollection

getMin

public java.lang.Object getMin(int i)
                        throws UnsupportedOperation
Overrides:
getMin in class DataSourceCollection
Throws:
UnsupportedOperation

getMax

public java.lang.Object getMax(int i)
                        throws UnsupportedOperation
Overrides:
getMax in class DataSourceCollection
Throws:
UnsupportedOperation

setSlice

public void setSlice(long min,
                     long max)
Overrides:
setSlice in class DataSourceCollection

getValue

public java.lang.Object getValue(int i,
                                 long index)
                          throws DataException
Function to get value does some buffer/cache handling job and should not be overloaded. Use getValueArray. The generic API is uses, since we must allocate the Objects to parse the file, so there is no use overloading getTypeValue functions.

Specified by:
getValue in class DataSourceCollection
Throws:
DataException

computeMin

public java.lang.Object computeMin(int i)
                            throws UnsupportedOperation
Overrides:
computeMin in class DataSourceCollection
Throws:
UnsupportedOperation

computeMax

public java.lang.Object computeMax(int i)
                            throws UnsupportedOperation
Overrides:
computeMax in class DataSourceCollection
Throws:
UnsupportedOperation

computeLastIndex

public long computeLastIndex()
                      throws UnsupportedOperation
Overrides:
computeLastIndex in class DataSourceCollection
Throws:
UnsupportedOperation

readLineIgnoreComment

public java.lang.String readLineIgnoreComment()
                                       throws java.io.IOException
Throws:
java.io.IOException

convertToCharset

protected java.lang.String convertToCharset(java.lang.String arg)
                                     throws java.io.IOException
Throws:
java.io.IOException

readFile

public java.lang.Object[] readFile(boolean parse)
                            throws NoSuchIndex,
                                   DataException
Reads a line from the ascii file, and split tokens to read double values. There should be as many tokens on the line as managed data sources. Prerequisite: The file position must be consistent with currentIndex. That is, the line that will be read from the file should contain the values for currentIndex. currentIndex is increased and the index cache at granularity boundaries is kept up to date.

Parameters:
parse - If the values should be parsed or if they could be skipped Since this function has been called on each line when reaching EOF, it's possible to omit computations of min/max once we've done it once.
Returns:
A double array containing all the tokens.
Throws:
NoSuchIndex
DataException

getMax

protected java.lang.Object getMax(java.lang.Object o1,
                                  java.lang.Object o2)
                           throws java.lang.ClassCastException
Returns the maximum of the 2 objects

Parameters:
o1. - Must be of type Long or Double
o2. - Must be of type Long or Double
Returns:
the maximum
Throws:
java.lang.ClassCastException

getMin

protected java.lang.Object getMin(java.lang.Object o1,
                                  java.lang.Object o2)
Returns the minimum of the 2 objects

Parameters:
o1. - Must be of type Long or Double
o2. - Must be of type Long or Double
Returns:
the minimum

readFile

public java.lang.Object[] readFile()
                            throws NoSuchIndex,
                                   DataException
Throws:
NoSuchIndex
DataException

getValueArray

public java.lang.Object[] getValueArray(long index)
                                 throws DataException
Throws:
DataException

valueClass

public java.lang.Class valueClass(int i)
Description copied from class: DataSourceCollection
Returns the more specialized superclass of all objects returned by the i-th data source. Returns Object by default in the base implementation, subclass should specialize if possible.

Overrides:
valueClass in class DataSourceCollection