org.javaseis.properties
Class TraceProperties

java.lang.Object
  extended by org.javaseis.properties.TraceProperties
All Implemented Interfaces:
java.io.Serializable

public class TraceProperties
extends java.lang.Object
implements java.io.Serializable

The TraceProperites class provides trace properties support for JavaSeis datasets. This design uses Java Properties files for persistence, and a LinkedHashMap from the Collections interface to hold the property descriptions in memory at runtime. The descriptions provide the keyword name and location in the binary records. A Java NIO ByteBuffer holds the binary records in memory. Typed views (int, float, etc.) of the ByteBuffer are then used to return typed values for a particular element.

Author:
Chuck Mosher for JavaSeis.org
See Also:
Serialized Form

Field Summary
protected  java.nio.ByteBuffer _buffer
           
protected  java.util.Map<java.lang.String,PropertyDescription> _map
           
protected  int _recordLength
           
protected  int _traceIndex
           
protected  java.lang.String _version
           
 
Constructor Summary
TraceProperties()
          Constructs an instance of TraceProperites.
TraceProperties(java.nio.ByteBuffer buffer)
          Constructs an instance of TraceProperites.
TraceProperties(int numProps, PropertyDescription[] traceProps)
          Constructs an instance of TraceProperites.
 
Method Summary
 void addTraceProperty(PropertyDescription property)
          Adds specified trace property to storage.
 boolean exists(java.lang.String key)
          Gets specified trace property from storage.
 double getDouble(java.lang.String key)
          Gets a trace property value as a double.
 void getDoubleArray(java.lang.String key, double[] values)
          Gets a trace property value as a double array.
 float getFloat(java.lang.String key)
          Gets a trace property value as a float.
 void getFloatArray(java.lang.String key, float[] values)
          Gets a trace property value as a float array.
 int getInt(java.lang.String key)
          Gets a trace property value as an integer.
 void getIntArray(java.lang.String key, int[] values)
          Gets a trace property value as an integer array.
 long getLong(java.lang.String key)
          Gets a trace property value as a long.
 void getLongArray(java.lang.String key, long[] values)
          Gets a trace property value as a long array.
 int getNumProperties()
          Gets the number of trace properties.
 int getRecordLength()
          Gets the record length (in bytes) used for property storage.
 short getShort(java.lang.String key)
          Gets a trace property value as a short.
 void getShortArray(java.lang.String key, short[] values)
          Gets a trace property value as a short array.
 PropertyDescription[] getTraceProperties()
          Gets the trace properties currently stored.
 PropertyDescription getTraceProperty(java.lang.String key)
          Gets specified trace property from storage.
<T> T
getValue(java.lang.String key)
          Gets a trace property value as a typed-value.
 void load(java.io.InputStream istream)
          Loaded properties from specified input stream to buffer.
 void loadProMAX_C(java.io.InputStream istream, int propertyCount)
          Loaded properties from specified input stream to buffer, based on the VERSION_C_PROMAX format.
static void main(java.lang.String[] args)
          The "main" method used for testing.
 double putDouble(java.lang.String key, double value)
          Puts a trace property value as a double.
 double[] putDoubleArray(java.lang.String key, double[] values)
          Puts a trace property value as a double array.
 float putFloat(java.lang.String key, float value)
          Puts a trace property value as a float.
 float[] putFloatArray(java.lang.String key, float[] values)
          Puts a trace property value as a float array.
 int putInt(java.lang.String key, int value)
          Puts a trace property value as an integer.
 int[] putIntArray(java.lang.String key, int[] values)
          Puts a trace property value as an integer array.
 long putLong(java.lang.String key, long value)
          Puts a trace property value as a long.
 long[] putLongArray(java.lang.String key, long[] values)
          Puts a trace property value as a long array.
 short putShort(java.lang.String key, short value)
          Puts a trace property value as a short.
 short[] putShortArray(java.lang.String key, short[] values)
          Puts a trace property value as a short array.
<T> T
putValue(java.lang.String key, T value)
          Puts a trace property value as a typed-value.
 void setBuffer(java.nio.ByteBuffer buffer)
          Sets the byte buffer for property storage.
protected  void setBufferPosition(PropertyDescription property)
          Sets the buffer position, based on the current trace index and specified property.
protected  void setBufferPosition(java.lang.String key)
          Sets the buffer position, based on the current trace index and specified property keyword.
 void setTraceIndex(int traceIndex)
          Sets the trace property index to use for subsequent operations.
 void store(java.io.OutputStream ostream)
          Stores properties from buffer to specified output stream.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_buffer

protected java.nio.ByteBuffer _buffer

_map

protected java.util.Map<java.lang.String,PropertyDescription> _map

_recordLength

protected int _recordLength

_traceIndex

protected int _traceIndex

_version

protected java.lang.String _version
Constructor Detail

TraceProperties

public TraceProperties()
Constructs an instance of TraceProperites.


TraceProperties

public TraceProperties(java.nio.ByteBuffer buffer)
Constructs an instance of TraceProperites.

Parameters:
buffer - The byte buffer to use for properties storage.

TraceProperties

public TraceProperties(int numProps,
                       PropertyDescription[] traceProps)
Constructs an instance of TraceProperites.

Parameters:
numProps - The number of trace properties.
traceProps - The trace properties.
Method Detail

addTraceProperty

public void addTraceProperty(PropertyDescription property)
Adds specified trace property to storage.

Parameters:
property - The trace property to be added.

exists

public boolean exists(java.lang.String key)
Gets specified trace property from storage.

Parameters:
key - The keyword name of the trace property to be returned.
Returns:
The trace property.

getDouble

public double getDouble(java.lang.String key)
Gets a trace property value as a double.

Parameters:
key - The keyword name of the trace property.
Returns:
The double value of the trace property.

getDoubleArray

public void getDoubleArray(java.lang.String key,
                           double[] values)
Gets a trace property value as a double array.

Parameters:
key - The keyword name of the trace property.
values - The double values of the trace property.

getFloat

public float getFloat(java.lang.String key)
Gets a trace property value as a float.

Parameters:
key - The keyword name of the trace property.
Returns:
The float value of the trace property.

getFloatArray

public void getFloatArray(java.lang.String key,
                          float[] values)
Gets a trace property value as a float array.

Parameters:
key - The keyword name of the trace property.
values - The float values of the trace property.

getInt

public int getInt(java.lang.String key)
Gets a trace property value as an integer.

Parameters:
key - The keyword name of the trace property.
Returns:
The integer value of the trace property.

getIntArray

public void getIntArray(java.lang.String key,
                        int[] values)
Gets a trace property value as an integer array.

Parameters:
key - The keyword name of the trace property.
values - The integer values of the trace property.

getLong

public long getLong(java.lang.String key)
Gets a trace property value as a long.

Parameters:
key - The keyword name of the trace property.
Returns:
The long value of the trace property.

getLongArray

public void getLongArray(java.lang.String key,
                         long[] values)
Gets a trace property value as a long array.

Parameters:
key - The keyword name of the trace property.
values - The long values of the trace property.

getNumProperties

public int getNumProperties()
Gets the number of trace properties.

Returns:
The number of trace properties.

getRecordLength

public int getRecordLength()
Gets the record length (in bytes) used for property storage.

Returns:
The record length (in bytes).

getShort

public short getShort(java.lang.String key)
Gets a trace property value as a short.

Parameters:
key - The keyword name of the trace property.
Returns:
The short value of the trace property.

getShortArray

public void getShortArray(java.lang.String key,
                          short[] values)
Gets a trace property value as a short array.

Parameters:
key - The keyword name of the trace property.
values - The short values of the trace property.

getTraceProperties

public PropertyDescription[] getTraceProperties()
                                         throws java.io.IOException
Gets the trace properties currently stored.

Returns:
The array of trace properties.
Throws:
java.io.IOException - Thrown on properties error.

getTraceProperty

public PropertyDescription getTraceProperty(java.lang.String key)
Gets specified trace property from storage.

Parameters:
key - The keyword name of the trace property to be returned.
Returns:
The trace property.

getValue

public <T> T getValue(java.lang.String key)
Gets a trace property value as a typed-value.

Parameters:
key - The keyword name of the trace property.
Returns:
The typed-value of the trace property.

load

public void load(java.io.InputStream istream)
          throws java.io.IOException
Loaded properties from specified input stream to buffer.

Parameters:
istream - The input stream.
Throws:
java.io.IOException - Thrown on properties load errors.

loadProMAX_C

public void loadProMAX_C(java.io.InputStream istream,
                         int propertyCount)
                  throws java.io.IOException
Loaded properties from specified input stream to buffer, based on the VERSION_C_PROMAX format.

Parameters:
istream - The input stream.
propertyCount - The property count to load.
Throws:
java.io.IOException - Thrown on properties load errors.

main

public static void main(java.lang.String[] args)
                 throws SeisException,
                        java.io.IOException
The "main" method used for testing.

Parameters:
args - The arguments for testing.
Throws:
SeisException - Thrown on testing errors.
java.io.IOException

putDouble

public double putDouble(java.lang.String key,
                        double value)
Puts a trace property value as a double.

Parameters:
key - The keyword name of the trace property.
value - The double value of the trace property.
Returns:
The double value of the trace property.

putDoubleArray

public double[] putDoubleArray(java.lang.String key,
                               double[] values)
Puts a trace property value as a double array.

Parameters:
key - The keyword name of the trace property.
values - The double values of the trace property.
Returns:
The double values of the trace property.

putFloat

public float putFloat(java.lang.String key,
                      float value)
Puts a trace property value as a float.

Parameters:
key - The keyword name of the trace property.
value - The float value of the trace property.
Returns:
The float value of the trace property.

putFloatArray

public float[] putFloatArray(java.lang.String key,
                             float[] values)
Puts a trace property value as a float array.

Parameters:
key - The keyword name of the trace property.
values - The float values of the trace property.
Returns:
The float values of the trace property.

putInt

public int putInt(java.lang.String key,
                  int value)
Puts a trace property value as an integer.

Parameters:
key - The keyword name of the trace property.
value - The integer value of the trace property.
Returns:
The integer value of the trace property.

putIntArray

public int[] putIntArray(java.lang.String key,
                         int[] values)
Puts a trace property value as an integer array.

Parameters:
key - The keyword name of the trace property.
values - The integer values of the trace property.
Returns:
The integer values of the trace property.

putLong

public long putLong(java.lang.String key,
                    long value)
Puts a trace property value as a long.

Parameters:
key - The keyword name of the trace property.
value - The long value of the trace property.
Returns:
The long value of the trace property.

putLongArray

public long[] putLongArray(java.lang.String key,
                           long[] values)
Puts a trace property value as a long array.

Parameters:
key - The keyword name of the trace property.
values - The long values of the trace property.
Returns:
The long values of the trace property.

putShort

public short putShort(java.lang.String key,
                      short value)
Puts a trace property value as a short.

Parameters:
key - The keyword name of the trace property.
value - The shot value of the trace property.
Returns:
The short value of the trace property.

putShortArray

public short[] putShortArray(java.lang.String key,
                             short[] values)
Puts a trace property value as a short array.

Parameters:
key - The keyword name of the trace property.
values - The short values of the trace property.
Returns:
The short values of the trace property.

putValue

public <T> T putValue(java.lang.String key,
                      T value)
Puts a trace property value as a typed-value.

Parameters:
key - The keyword name of the trace property.
value - The typed-value of the trace property.
Returns:
The typed-value of the trace property.

setBuffer

public void setBuffer(java.nio.ByteBuffer buffer)
Sets the byte buffer for property storage.

Parameters:
buffer - The buffer to use for property storage.

setBufferPosition

protected void setBufferPosition(PropertyDescription property)
Sets the buffer position, based on the current trace index and specified property.

Parameters:
property - The trace property.

setBufferPosition

protected void setBufferPosition(java.lang.String key)
Sets the buffer position, based on the current trace index and specified property keyword.

Parameters:
key - The keyword name of the trace property.

setTraceIndex

public void setTraceIndex(int traceIndex)
Sets the trace property index to use for subsequent operations.

Parameters:
traceIndex - The trace index to set.

store

public void store(java.io.OutputStream ostream)
           throws java.io.IOException
Stores properties from buffer to specified output stream.

Parameters:
ostream - The output stream.
Throws:
java.io.IOException - Thrown on properties store errors.