edu.iris.Fissures.seed.container
Class Blockette

java.lang.Object
  extended byedu.iris.Fissures.seed.container.SeedObject
      extended byedu.iris.Fissures.seed.container.Blockette
All Implemented Interfaces:
java.lang.Comparable, java.io.Serializable
Direct Known Subclasses:
CachedBlocketteDecorator

public class Blockette
extends SeedObject

Generic class of all SEED blockettes and Fixed Section Data Header (FSDH) contents. Intended to be instantiated by BlocketteFactory class. All of the constructors are protected permissions so that we can keep a rein on how the objects are created and invoked...they really have a dependency on the BlocketteFactory, since that class contains the background information on all of the supported blockette types.

Version:
4/28/2005
Author:
Robert Casey, IRIS DMC
Sid Hellman, ISTI
See Also:
Serialized Form

Method Summary
 int addChildBlockette(Blockette addBlockette)
          Add a child blockette to this blockette.
 int addDictionaryLookup(int abbrevLookupId)
          Add lookupId value from an outside abbreviation dictionary blockette to the lookupMap Vector in this blockette.
 int addDictionaryLookupIfNeeded(int abbrevLookupId)
          Add lookupId value from an outside abbreviation dictionary blockette to the lookupMap Vector in this blockette if it is not already there.
 void addFieldGrp(int fieldNum, java.util.Vector valueVec)
          Add a new repeat field group starting at the specified field number.
 void attachParent(Blockette parent)
          Designate the provided Blockette as this Blockette's parent.
 void attachWaveform(Waveform data)
          Attach waveform object to this blockette.
 void deleteFieldGrp(int fieldNum, int fieldIndex)
          Remove a repeat group at the indicated index.
 java.lang.String getCategory()
          Get the control header type of this blockette.
 Blockette getChildBlockette(int index)
          Get the child blockette associated with this blockette from the specified Vector index.
static float getDefaultVersion()
          Get the default SEED version for Blockettes.
 java.lang.String getDefinition()
          Return the entire description of this blockette type.
 int getDictionaryLookup(int index)
          Get the dictionary lookup value from the specified Vector index.
 java.util.Vector getFieldGrp(int fieldNum, int fieldIndex)
          Get a repeating field group cross-section in the form of a vector.
 java.lang.String getFieldLength(int fieldNum)
          Get the length of the field in bytes.
 java.lang.String getFieldMask(int fieldNum)
          Get the string expression of the mask or flag for this field.
 java.lang.String getFieldName(int fieldNum)
          Get the full name of the specified field.
 java.lang.Object getFieldObject(int fieldNum)
          Return the raw object assigned to this field number, regardless of the contents, or whether it is a repeat field or a repeat field with list values.
 int getFieldRepeat(int fieldNum)
          Get the field number that indicates the number of times this field repeats.
 java.lang.String getFieldType(int fieldNum)
          Get the letter that represents the field type.
 java.lang.Object getFieldVal(int fieldNum)
          Returns a single object value at the field number indicated.
 java.lang.Object getFieldVal(int fieldNum, int fieldIndex)
          Returns the value at the field number...NOTE that this is an Object.
 int getLookupId()
          Return the lookupId for this blockette.
 java.lang.String getName()
          Get the full name of this blockette.
 int getNumBytes()
          Returns the number of bytes read to generate this blockette.
 int getNumFields()
          Get the number of available fields in this blockette.
 Blockette getParentBlockette()
          Return the designated parent Blockette object.
 int getType()
          Return the blockette type number.
 float getVersion()
          Return the SEED version represented in this blockette.
 Waveform getWaveform()
          Get the attached waveform object.
 boolean hasParent()
          Return true if this Blockette has a designated parent.
 void initialize(byte[] blocketteStream, boolean swapFlag, boolean isData)
          Resets this Blockette object to initialization state.
 void initialize(byte[] blocketteStream, boolean swapFlag, boolean isData, float version)
          Resets this Blockette object to initialization state.
 void initialize(java.lang.String inputString)
          Resets this Blockette object to initialization state.
 void initialize(java.lang.String inputString, float version)
          Resets this Blockette object to initialization state.
 void initialize(java.lang.String inputString, java.lang.String delimiter, java.lang.String blank)
          Resets this Blockette object to initialization state.
 void initialize(java.lang.String inputString, java.lang.String delimiter, java.lang.String blank, float version)
          Resets this Blockette object to initialization state.
 void insertFieldGrp(int fieldNum, int fieldIndex, java.util.Vector valueVec)
          Insert a repeat group before the indicated index.
protected  void instanceInit()
          Initialize instance variables.
 boolean isIncomplete()
          Return true if this blockette was not completely specified.
 int numberofChildBlockettes()
          Return the number of child blockettes stored in this blockette.
 int numberofDictionaryLookups()
          Return the number of dictionary entries in the lookupMap.
 void removeChildBlockette(int index)
          Remove child blockette reference at the indicated index.
 void removeParent()
          Remove the parent reference in this Blockette.
 void removeWaveform()
          Remove the attached waveform object from this blockette.
 void replaceChildBlockette(int index, Blockette newBlockette)
          Replace child blockette at the indicated index with a new blockette.
 void setDictionaryLookup(int index, int abbrevLookupId)
          Set the lookupId value of an abbreviation dictionary blockette for a corresponding index value, replacing an existing entry at that index.
 void setFieldObject(int fieldNum, java.lang.Object fieldObj)
          Similar to setFieldVal, except that the provided object can be whatever construct is needed to reflect the field contents.
 void setFieldVal(int fieldNum, int fieldIndex, java.lang.Object value)
          Apply value contained in the provided object to the indicated field position in the blockette.
 void setFieldVal(int fieldNum, int fieldIndex, java.lang.Object value, boolean lenient)
          Apply value contained in the provided object to the indicated field position in the blockette.
 void setFieldVal(int fieldNum, java.lang.Object value)
          Apply value contained in the provided object to the indicated field position in the blockette.
 void setLookupId(int idValue)
          Set the lookupId value of this blockette.
protected  void setType(int i)
          allow explicit setting of the type -- use with caution!
 void setValuesFrom(java.lang.String inputString)
          Like initialize() except that the Blockette is not fully reset.
 void setValuesFrom(java.lang.String inputString, java.lang.String delimiter, java.lang.String blank)
          Like initialize() except that the Blockette is not fully reset.
 void setVersion(float ver)
          Set the SEED version that this blockette represents.
 java.lang.String toString()
          Convert entire Blockette contents into a tokenized string.
 java.lang.String toString(int fieldNum)
          Convert Blockette field value to a properly formatted string.
 java.lang.String toString(int fieldNum, int fieldIndex)
          Convert Blockette field value to a properly formatted string.
 java.lang.String toString(java.lang.String delimiter, java.lang.String blank)
          Convert entire Blockette contents into a tokenized string.
 java.lang.String translate(int fieldNum)
          Translate the value located at the blockette's field number, if there is one.
 
Methods inherited from class edu.iris.Fissures.seed.container.SeedObject
compareTo
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Method Detail

initialize

public void initialize(byte[] blocketteStream,
                       boolean swapFlag,
                       boolean isData,
                       float version)
                throws SeedException
Resets this Blockette object to initialization state. All previous information stored is removed. Used for optimization through object reuse. Is publicly callable and readies the object to be used again. Accept a stream of bytes that starts at byte zero of a blockette, with indicated flag to swap bytes to Java-endian (68000), flag indicating a binary data blockette, and SEED version number.

Throws:
SeedException

initialize

public void initialize(byte[] blocketteStream,
                       boolean swapFlag,
                       boolean isData)
                throws SeedException
Resets this Blockette object to initialization state. All previous information stored is removed. Used for optimization through object reuse. Is publicly callable and readies the object to be used again. Accept a stream of bytes that starts at byte zero of a blockette, with indicated flag to swap bytes to Java-endian (68000), and flag indicating a binary data blockette for default SEED version.

Throws:
SeedException

initialize

public void initialize(java.lang.String inputString,
                       java.lang.String delimiter,
                       java.lang.String blank,
                       float version)
                throws SeedException
Resets this Blockette object to initialization state. All previous information stored is removed. Used for optimization through object reuse. Is publicly callable and readies the object to be used again. Accept a delimited String as input, along with the SEED version this blockette will comply with. Delimiter characters are specified.

Throws:
SeedException

initialize

public void initialize(java.lang.String inputString,
                       java.lang.String delimiter,
                       java.lang.String blank)
                throws SeedException
Resets this Blockette object to initialization state. All previous information stored is removed. Used for optimization through object reuse. Is publicly callable and readies the object to be used again. Accept a delimited String as input. Default SEED version is used. Delimiter characters are specified.

Throws:
SeedException

initialize

public void initialize(java.lang.String inputString)
                throws SeedException
Resets this Blockette object to initialization state. All previous information stored is removed. Used for optimization through object reuse. Is publicly callable and readies the object to be used again. Accept a delimited String as input. Default SEED version is used. Default delimiter characters are used.

Throws:
SeedException

initialize

public void initialize(java.lang.String inputString,
                       float version)
                throws SeedException
Resets this Blockette object to initialization state. All previous information stored is removed. Used for optimization through object reuse. Is publicly callable and readies the object to be used again. Accept a delimited String as input. SEED version is specified. Default delimiter characters are used.

Throws:
SeedException

setValuesFrom

public void setValuesFrom(java.lang.String inputString,
                          java.lang.String delimiter,
                          java.lang.String blank)
                   throws SeedException
Like initialize() except that the Blockette is not fully reset. Just the field values are rewritten to be the contents of the offered delimited String.

Throws:
SeedException

setValuesFrom

public void setValuesFrom(java.lang.String inputString)
                   throws SeedException
Like initialize() except that the Blockette is not fully reset. Just the field values are rewritten to be the contents of the offered delimited String.

Throws:
SeedException

getType

public int getType()
Return the blockette type number. 0 (zero) will be returned if the blockette has not been initialized

Specified by:
getType in class SeedObject

getVersion

public float getVersion()
                 throws SeedException
Return the SEED version represented in this blockette.

Throws:
SeedException

isIncomplete

public boolean isIncomplete()
Return true if this blockette was not completely specified. Most likely due to a partial record used to create this blockette.


getNumBytes

public int getNumBytes()
                throws SeedException
Returns the number of bytes read to generate this blockette. When unset, value returned is 0. This must be used with caution. Do not interpret the return value as being the number of bytes that the current value set in the blockette would output when written as SEED. This is a value that is set once at blockette inception and only when generated from byte input. Use it to test for the number of bytes read from the byte stream when making this blockette.

Throws:
SeedException

toString

public java.lang.String toString(int fieldNum,
                                 int fieldIndex)
Convert Blockette field value to a properly formatted string. fieldIndex would be an index number of repeating field starting with count of 0.


toString

public java.lang.String toString(int fieldNum)
Convert Blockette field value to a properly formatted string. Shortened version of toString that assumes the field is a non-repeating field (no fieldIndex).


toString

public java.lang.String toString(java.lang.String delimiter,
                                 java.lang.String blank)
Convert entire Blockette contents into a tokenized string. The token delimiter is specified as a string. blank refers to a character that denotes a blank field value. The output can potentially be read in by the tokenized string variant of the Blockette() constructor (or setTokenString() method).


toString

public java.lang.String toString()
Convert entire Blockette contents into a tokenized string. Uses a default token and default blank marker.

Specified by:
toString in class SeedObject

getName

public java.lang.String getName()
                         throws SeedException
Get the full name of this blockette.

Throws:
SeedException

getCategory

public java.lang.String getCategory()
                             throws SeedException
Get the control header type of this blockette.

Throws:
SeedException

getNumFields

public int getNumFields()
                 throws SeedException
Get the number of available fields in this blockette.

Throws:
SeedException

getFieldName

public java.lang.String getFieldName(int fieldNum)
                              throws SeedException
Get the full name of the specified field.

Throws:
SeedException

getFieldType

public java.lang.String getFieldType(int fieldNum)
                              throws SeedException
Get the letter that represents the field type.

Throws:
SeedException

getFieldLength

public java.lang.String getFieldLength(int fieldNum)
                                throws SeedException
Get the length of the field in bytes. This is a string return because the field length for type V fields is of the form 'm-n', where m is the minimum value and n is the maximum value.

Throws:
SeedException

getFieldMask

public java.lang.String getFieldMask(int fieldNum)
                              throws SeedException
Get the string expression of the mask or flag for this field.

Throws:
SeedException

getFieldRepeat

public int getFieldRepeat(int fieldNum)
                   throws SeedException
Get the field number that indicates the number of times this field repeats. A value of 0 means that this field does not repeat.

Throws:
SeedException

getDefinition

public java.lang.String getDefinition()
                               throws SeedException
Return the entire description of this blockette type.

Throws:
SeedException

getFieldVal

public java.lang.Object getFieldVal(int fieldNum,
                                    int fieldIndex)
                             throws SeedException
Returns the value at the field number...NOTE that this is an Object. Use toString() to get string equivalent of returned Object and indexed iteration of that field if it is repeating. For a non-repeating field, fieldIndex is ignored. Null is returned if a stored null value is encountered. An out of bounds field number results in a thrown exception.

Throws:
SeedException

getFieldVal

public java.lang.Object getFieldVal(int fieldNum)
                             throws SeedException
Returns a single object value at the field number indicated. For repeating fields, the object returned is the first value in the repeating field.

Throws:
SeedException

getFieldGrp

public java.util.Vector getFieldGrp(int fieldNum,
                                    int fieldIndex)
                             throws SeedException
Get a repeating field group cross-section in the form of a vector. Returns a Vector that contains all of the fields in a repeat group, returning the value at fieldIndex in each, starting at fieldNum. An example of a repeat group is Response Blockette 53, fields 10 through 13. In wanting to get the third quartet of zero coefficients, the call to getFieldGrp would be fieldNum=10, fieldIndex=2. The result would be a Vector of size 4, with the third value from fields 10,11,12, and 13, in order.

Throws:
SeedException

getFieldObject

public java.lang.Object getFieldObject(int fieldNum)
Return the raw object assigned to this field number, regardless of the contents, or whether it is a repeat field or a repeat field with list values.

Parameters:
fieldNum - field number to return the assigned object from
Returns:
row object assigned to this field number

translate

public java.lang.String translate(int fieldNum)
                           throws SeedException
Translate the value located at the blockette's field number, if there is one. Some values in blockettes translate to a more elaborate description. Translate will return a specific String if there is a description to match the value at the blockette's field number. Otherwise, a default return such as 'Value Undefined' is returned.

Throws:
SeedException

getChildBlockette

public Blockette getChildBlockette(int index)
Get the child blockette associated with this blockette from the specified Vector index. Returns null in the case of the index exceeding the size of the Vector.


numberofChildBlockettes

public int numberofChildBlockettes()
Return the number of child blockettes stored in this blockette.


hasParent

public boolean hasParent()
Return true if this Blockette has a designated parent.


getParentBlockette

public Blockette getParentBlockette()
Return the designated parent Blockette object. The value could be null, which means that as far as this Blockette is concerned, there is no parent.


getWaveform

public Waveform getWaveform()
Get the attached waveform object. Return null if no Waveform object is attached.


getDictionaryLookup

public int getDictionaryLookup(int index)
Get the dictionary lookup value from the specified Vector index. Returns 0 in the case of the index exceeding the size of the Vector or no lookup present.


numberofDictionaryLookups

public int numberofDictionaryLookups()
Return the number of dictionary entries in the lookupMap. Note that the lookupMap starts counting from 1, not 0. Position 0 is reserved for internal use.


getLookupId

public int getLookupId()
Return the lookupId for this blockette.

Specified by:
getLookupId in class SeedObject

setVersion

public void setVersion(float ver)
                throws SeedException
Set the SEED version that this blockette represents.

Throws:
SeedException

setFieldVal

public void setFieldVal(int fieldNum,
                        int fieldIndex,
                        java.lang.Object value,
                        boolean lenient)
                 throws SeedException
Apply value contained in the provided object to the indicated field position in the blockette. Sets the value at the blockette's field number (and repeat index of that field if it is repeating). For a non-repeating field, fieldIndex is ignored. The lenient flag, when set to true, means this method will not return an exception with an improperly formatted value, but instead place a substitute character before adding it to the blockette.

Throws:
SeedException

setFieldVal

public void setFieldVal(int fieldNum,
                        int fieldIndex,
                        java.lang.Object value)
                 throws SeedException
Apply value contained in the provided object to the indicated field position in the blockette. Sets the value at the blockette's field number (and repeat index of that field if it is repeating). For a non-repeating field, fieldIndex is ignored.

Throws:
SeedException

setFieldVal

public void setFieldVal(int fieldNum,
                        java.lang.Object value)
                 throws SeedException
Apply value contained in the provided object to the indicated field position in the blockette. This method variant assumes the indicated field is not a repeat field.

Throws:
SeedException

setFieldObject

public void setFieldObject(int fieldNum,
                           java.lang.Object fieldObj)
Similar to setFieldVal, except that the provided object can be whatever construct is needed to reflect the field contents. A single value, a vector of values, or a vector of vectors with values. This allows bulk setting of a field, but must be used with caution. getFieldObject is the accessor method that complements this.

Parameters:
fieldNum - field number to apply this object to
fieldObj - object to apply to the indicated field number

addFieldGrp

public void addFieldGrp(int fieldNum,
                        java.util.Vector valueVec)
                 throws SeedException
Add a new repeat field group starting at the specified field number. valueVec should be a Vector of sufficient size to contain Objects to fill all of the fields in the repeat field group. i.e. if a repeat field group starts at field 7 and goes through field 9, then fieldNum should be 7 and valueVec should be size 3 with 3 assigned Objects to place in those fields...otherwise, an exception will be thrown. repeatField contains the field number that indicates the number of Repeating fields currently present in the blockette...it also acts to verify that this field is a repeating field. For the special case of Blockette 60, field 6 must be a Vector of Integers placed in valueVec. Be careful using this so that you get the intended result!

Throws:
SeedException

insertFieldGrp

public void insertFieldGrp(int fieldNum,
                           int fieldIndex,
                           java.util.Vector valueVec)
                    throws SeedException
Insert a repeat group before the indicated index. This is much like addFieldGrp, except that it serves as an insert function instead of an append function. Insert group at fieldIndex, with the first field of the group being fieldNum, consisting of the values in valueVec.

Throws:
SeedException

deleteFieldGrp

public void deleteFieldGrp(int fieldNum,
                           int fieldIndex)
                    throws SeedException
Remove a repeat group at the indicated index. Causes the number of repeat groups to decrease by 1. Delete the group at fieldIndex, where the first field of the group being fieldNum.

Throws:
SeedException

addChildBlockette

public int addChildBlockette(Blockette addBlockette)
Add a child blockette to this blockette. Append another already-created blockette to the Vector list of this blockette, indicating that the added blockette is heirarchically a 'child' of this blockette, whose data is a subcomponent of this blockette.

Parameters:
addBlockette - the blockette to be added as a child to this blockette
Returns:
the index where the addition was made.

removeChildBlockette

public void removeChildBlockette(int index)
Remove child blockette reference at the indicated index. Use getChildBlockette() to find which blockette is at which index value.


replaceChildBlockette

public void replaceChildBlockette(int index,
                                  Blockette newBlockette)
Replace child blockette at the indicated index with a new blockette.


attachParent

public void attachParent(Blockette parent)
Designate the provided Blockette as this Blockette's parent.


removeParent

public void removeParent()
Remove the parent reference in this Blockette.


attachWaveform

public void attachWaveform(Waveform data)
Attach waveform object to this blockette. Usually this applies only to FSDH blockette (999).


removeWaveform

public void removeWaveform()
Remove the attached waveform object from this blockette.


addDictionaryLookup

public int addDictionaryLookup(int abbrevLookupId)
Add lookupId value from an outside abbreviation dictionary blockette to the lookupMap Vector in this blockette. The number returned is the index value where the lookupId has been placed. It is recommended that this return value is written to the appropriate blockette field that is used to reference the dictionary blockette.


addDictionaryLookupIfNeeded

public int addDictionaryLookupIfNeeded(int abbrevLookupId)
Add lookupId value from an outside abbreviation dictionary blockette to the lookupMap Vector in this blockette if it is not already there. The number returned is the index value where the lookupId has been placed. It is recommended that this return value is written to the appropriate blockette field that is used to reference the dictionary blockette. Contributed by Sid Hellman, ISTI - 1/16/2004


setDictionaryLookup

public void setDictionaryLookup(int index,
                                int abbrevLookupId)
Set the lookupId value of an abbreviation dictionary blockette for a corresponding index value, replacing an existing entry at that index. Typically used for changing an index reference.


setLookupId

public void setLookupId(int idValue)
Set the lookupId value of this blockette. It can be used as a reference from other blockettes. Typically used by dictionary blockettes as their reference number.


getDefaultVersion

public static float getDefaultVersion()
Get the default SEED version for Blockettes. This is a static method!


setType

protected void setType(int i)
allow explicit setting of the type -- use with caution!

Throws:
SeedException

instanceInit

protected void instanceInit()
Initialize instance variables.



brought to you by Incorporated Research Institutions for Seismology
June 29 2006