jef.dna.attributesTable.impl.def
Class ATable

java.lang.Object
  extended by jef.dna.attributesTable.impl.def.ATable
All Implemented Interfaces:
java.lang.Cloneable, AttributesTable

public class ATable
extends java.lang.Object
implements AttributesTable

Default implementation of the AttributesTable interface.

Author:
Francesco Russo

Field Summary
protected static Logger logger
           
 
Constructor Summary
ATable()
          Creates a new instance of ATable
 
Method Summary
 void addAll(AttributesTable at)
          Appends the given AttributesTable to the current one.
 void addElement(Attribute entry)
          Adds the specified Attribute at the end of the table.
 void addElementAt(Attribute entry, int index, boolean overwrite)
          Adds the specified Attribute 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 AttributesTable instance.
 void fromStream(java.io.DataInputStream dis, Dna dna, int dim)
          Reads the table from the given stream.
 Attribute get(int index)
          Get a reference to the entry stored at the provided index.
 Dna getDna()
          Get the Dna container
 int getIndexOf(Attribute entry)
          Return the index of the provided entry, if exists.
 int remove(Attribute 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
 Attribute 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()
          Validates all the AttributesTable 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

ATable

public ATable()
Creates a new instance of ATable

Method Detail

addAll

public void addAll(AttributesTable at)
Appends the given AttributesTable to the current one.

Specified by:
addAll in interface AttributesTable
Parameters:
at - The AttributesTable to be appended

addElement

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

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

addElementAt

public void addElementAt(Attribute entry,
                         int index,
                         boolean overwrite)
                  throws java.lang.IndexOutOfBoundsException,
                         java.lang.UnsupportedOperationException
Adds the specified Attribute 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 AttributesTable
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

fromStream

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

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

get

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

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

getDna

public Dna getDna()
Get the Dna container

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

getIndexOf

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

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

remove

public Attribute 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 AttributesTable
Parameters:
index - The index of the entry we want to remove
compact - Has the table to be resized?
Returns:
Attribute 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(Attribute entry,
                  boolean compact)
           throws AttributeNotFoundException,
                  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 AttributesTable
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:
AttributeNotFoundException - The provided entry is not stored within the current table
java.lang.UnsupportedOperationException - The method is not supported by the current implementation

setDna

public void setDna(Dna dna)
Set the Dna container

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

size

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

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

toStream

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

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

validate

public void validate()
              throws AttributeValidationException,
                     AttributeOutOfRangeException,
                     MissingDnaContainerException,
                     MissingCPTableException
Description copied from interface: AttributesTable
Validates all the AttributesTable entries.

Specified by:
validate in interface AttributesTable
Throws:
AttributeValidationException
AttributeOutOfRangeException
MissingDnaContainerException
MissingCPTableException

clone

public java.lang.Object clone()
                       throws java.lang.CloneNotSupportedException
Clone the current AttributesTable instance. This cloning does not modify the reference to the containing Dna instance.

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