jef.dna.fieldsTable.impl.def
Class FTable

java.lang.Object
  extended by jef.dna.fieldsTable.impl.def.FTable
All Implemented Interfaces:
java.lang.Cloneable, FieldsTable

public class FTable
extends java.lang.Object
implements FieldsTable

Default implementation class of the FieldsTable interface.

Author:
Francesco Russo

Field Summary
protected static Logger logger
           
 
Constructor Summary
FTable()
          Creates a new instance of FTable
 
Method Summary
 void addAll(FieldsTable ft)
          Appends the given FieldsTable to the current one.
 void addElement(FieldInfoStructure entry)
          Adds the specified FieldInfoStructure at the end of the table.
 void addElementAt(FieldInfoStructure entry, int index, boolean overwrite)
          Adds the specified FieldInfoStructure at the provided position, shifting of one index any subsequente entry (if exists) iff the overwrite parameter is set to false, otherwise the current entry at index index will be overwritten.
 java.lang.Object clone()
          Clone the current FieldsTable instance.
 void fromStream(java.io.DataInputStream dis, Dna dna, int fieldsCount)
          Reads the table from the given stream.
 FieldInfoStructure get(int index)
          Get a reference to the entry stored at the provided index.
 Dna getDna()
          Get the Dna container
 int getIndexOf(FieldInfoStructure entry)
          Return the index of the provided entry, if exists.
 int remove(FieldInfoStructure entry, boolean compact)
          Removes the specified entry, if exists, resizing the table if compact is true, otherwise the removed entry has to be replaced by null
 FieldInfoStructure remove(int index, boolean compact)
          Removes the entry at the specified index, if exists, resizing the table if compact is true, otherwise the removed entry has to be replaced by null
 void setDna(Dna dna)
          Set the Dna container
 int size()
          Returns the number of entries stored by the table
 void toStream(java.io.DataOutputStream dos)
          Writes the table to the given output stream.
 void validate()
          This method performs the validation over all the FieldsTable entries.
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

logger

protected static Logger logger
Constructor Detail

FTable

public FTable()
Creates a new instance of FTable

Method Detail

addElement

public void addElement(FieldInfoStructure entry)
Adds the specified FieldInfoStructure at the end of the table.

Specified by:
addElement in interface FieldsTable
Parameters:
entry - The entry to be added

addElementAt

public void addElementAt(FieldInfoStructure entry,
                         int index,
                         boolean overwrite)
                  throws java.lang.IndexOutOfBoundsException,
                         java.lang.UnsupportedOperationException
Adds the specified FieldInfoStructure at the provided position, shifting of one index any subsequente entry (if exists) iff the overwrite parameter is set to false, otherwise the current entry at index index will be overwritten.

Specified by:
addElementAt in interface FieldsTable
Parameters:
entry - The entry to be added
index - The position at which the entry should be placed
overwrite - Should any existing entry be overwritten?
Throws:
java.lang.IndexOutOfBoundsException - Trying to access to an invalid index
java.lang.UnsupportedOperationException - The method is not supported by the current implementation

get

public FieldInfoStructure get(int index)
                       throws java.lang.IndexOutOfBoundsException
Get a reference to the entry stored at the provided index.

Specified by:
get in interface FieldsTable
Parameters:
index - The index to access to
Returns:
FieldInfoStructure The entry located at the provided index, if any
Throws:
java.lang.IndexOutOfBoundsException - Tying to acces to an invalid index

getIndexOf

public int getIndexOf(FieldInfoStructure entry)
               throws FieldInfoStructureNotFoundException,
                      java.lang.UnsupportedOperationException
Return the index of the provided entry, if exists.

Specified by:
getIndexOf in interface FieldsTable
Parameters:
entry - The entry whose index has to be returned
Returns:
int The index of the provided entry
Throws:
FieldInfoStructureNotFoundException - The provided entry is not stored within the current table
java.lang.UnsupportedOperationException - The method is not supported by the current implementation

remove

public FieldInfoStructure remove(int index,
                                 boolean compact)
                          throws java.lang.IndexOutOfBoundsException,
                                 java.lang.UnsupportedOperationException
Removes the entry at the specified index, if exists, resizing the table if compact is true, otherwise the removed entry has to be replaced by null

Specified by:
remove in interface FieldsTable
Parameters:
index - The index of the entry we want to remove
compact - Has the table to be resized?
Returns:
FieldInfoStructure The removed entry
Throws:
java.lang.IndexOutOfBoundsException - Tying to acces to an invalid index
java.lang.UnsupportedOperationException - The method is not supported by the current implementation

remove

public int remove(FieldInfoStructure entry,
                  boolean compact)
           throws FieldInfoStructureNotFoundException,
                  java.lang.UnsupportedOperationException
Removes the specified entry, if exists, resizing the table if compact is true, otherwise the removed entry has to be replaced by null

Specified by:
remove in interface FieldsTable
Parameters:
entry - The entry we want to remove
compact - Has the constant pool table to be resized?
Returns:
int The index of the removed entry
Throws:
FieldInfoStructureNotFoundException - The provided entry is not stored within the current table
java.lang.UnsupportedOperationException - The method is not supported by the current implementation

size

public int size()
Returns the number of entries stored by the table

Specified by:
size in interface FieldsTable
Returns:
int The number of entries

addAll

public void addAll(FieldsTable ft)
Appends the given FieldsTable to the current one.

Specified by:
addAll in interface FieldsTable
Parameters:
ft - The FieldsTable to be appended

fromStream

public void fromStream(java.io.DataInputStream dis,
                       Dna dna,
                       int fieldsCount)
                throws MissingDnaContainerException,
                       DnaDeserializationException
Reads the table from the given stream.

Specified by:
fromStream in interface FieldsTable
Parameters:
dis - The stream for reading the table from
dna - The Dna container instance
fieldsCount - The number of expected fields
Throws:
MissingDnaContainerException - This exception is thrown iff no valid Dna instance has been set
DnaDeserializationException

toStream

public void toStream(java.io.DataOutputStream dos)
              throws DnaSerializationException
Writes the table to the given output stream.

Specified by:
toStream in interface FieldsTable
Parameters:
dos - The stream for writing the FiledsTable instance to
Throws:
DnaSerializationException

setDna

public void setDna(Dna dna)
Set the Dna container

Specified by:
setDna in interface FieldsTable
Parameters:
dna - The Dna container

getDna

public Dna getDna()
Get the Dna container

Specified by:
getDna in interface FieldsTable
Returns:
Dna The Dna container

validate

public void validate()
              throws FieldInfoValidationException,
                     InfoStructureAttributeOutOfRangeException,
                     MissingDnaContainerException,
                     MissingCPTableException
Description copied from interface: FieldsTable
This method performs the validation over all the FieldsTable entries.

Specified by:
validate in interface FieldsTable
Throws:
FieldInfoValidationException
InfoStructureAttributeOutOfRangeException
MissingDnaContainerException
MissingCPTableException

clone

public java.lang.Object clone()
                       throws java.lang.CloneNotSupportedException
Clone the current FieldsTable instance.

Specified by:
clone in interface FieldsTable
Overrides:
clone in class java.lang.Object
Returns:
Object The clone
Throws:
java.lang.CloneNotSupportedException