Data Request Broker
2-3-release

fr.gael.drb
Class DrbDefaultSequence

java.lang.Object
  extended by java.util.AbstractCollection<E>
      extended by java.util.AbstractList<E>
          extended by java.util.ArrayList<DrbItem>
              extended by fr.gael.drb.DrbDefaultSequence
All Implemented Interfaces:
DrbSequence, Serializable, Cloneable, Iterable<DrbItem>, Collection<DrbItem>, List<DrbItem>, RandomAccess
Direct Known Subclasses:
DrbDefaultAttributeList, DrbDefaultNodeList

public class DrbDefaultSequence
extends ArrayList<DrbItem>
implements DrbSequence

Generic implementation of DrbSequence. This default implementation extends an ArrayList provided by Java API. It is a generic mean to create a list of items. If no specific operations are required to implement the DrbSequence (e.g. filtering, caching, hashing, etc.). This class is a simple way to handle a collection of items. Note : the add() or equivalent operations of the ArrayList class have not been overrided to insure they insert DrbItem intances. Some inconsistency may appear * if no care is taken while calling add() or equivalent operations.

See Also:
Serialized Form

Field Summary
 
Fields inherited from class java.util.AbstractList
modCount
 
Constructor Summary
  DrbDefaultSequence()
          Builds an empty sequence.
protected DrbDefaultSequence(DrbDefaultSequence sequence)
          Duplicate an existing sequence
  DrbDefaultSequence(DrbItem item)
          Build a singleton from a item.
  DrbDefaultSequence(DrbSequence sequence)
          Duplicate an existing sequence
 
Method Summary
 DrbSequence addItem(DrbItem item)
          Appends an item at the end of the item list.
 DrbSequence addItem(int index, DrbItem item)
          Inserts a item at a given position.
 ValueArray atomize()
          The atomic values of this sequence.
 DrbItem getItem(int index)
          Returns a specific item of the list.
 int getLength()
          The number of items in the list.
static void main(String[] args)
          Make this class runnable for testing.
 DrbSequence removeItem(int index)
          Removes an existing item.
 String toString()
          Returns the string representation of this sequence
 
Methods inherited from class java.util.ArrayList
add, add, addAll, addAll, clear, clone, contains, ensureCapacity, get, indexOf, isEmpty, lastIndexOf, remove, remove, removeRange, set, size, toArray, toArray, trimToSize
 
Methods inherited from class java.util.AbstractList
equals, hashCode, iterator, listIterator, listIterator, subList
 
Methods inherited from class java.util.AbstractCollection
containsAll, removeAll, retainAll
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.List
containsAll, equals, hashCode, iterator, listIterator, listIterator, removeAll, retainAll, subList
 

Constructor Detail

DrbDefaultSequence

public DrbDefaultSequence()
Builds an empty sequence.


DrbDefaultSequence

public DrbDefaultSequence(DrbItem item)
Build a singleton from a item.

Parameters:
item - A reference to the singleton item.

DrbDefaultSequence

public DrbDefaultSequence(DrbSequence sequence)
Duplicate an existing sequence

Parameters:
sequence - A reference to the sequence to be duplicated.

DrbDefaultSequence

protected DrbDefaultSequence(DrbDefaultSequence sequence)
Duplicate an existing sequence

Parameters:
sequence - A reference to the sequence to be duplicated.
Method Detail

atomize

public ValueArray atomize()
The atomic values of this sequence. The value of the node means its content. The value is expressed accoring to one of the types supported by the fr.gael.drb.value package. Generally these types correspond to primitive types (e.g. integer, floatting points etc.) or very low level types (e.g. string, date, etc.).

Specified by:
atomize in interface DrbSequence
Returns:
A reference to the values of the sequence.

getItem

public final DrbItem getItem(int index)
Returns a specific item of the list. This operation wraps the ArrayList.get() operation. The exception that ArrayList.get() can raise is however traped and not propagated. In such case a message is written to the error output and the operation returns null without throwing any exception.

Specified by:
getItem in interface DrbSequence
Parameters:
index - The position of the item starting from 0 and not greater or equal to the item count in the list.
Returns:
A reference to specified item or null if no such item.

getLength

public final int getLength()
The number of items in the list.

Specified by:
getLength in interface DrbSequence
Returns:
The number of items in the list.

addItem

public DrbSequence addItem(int index,
                           DrbItem item)
                    throws NullPointerException,
                           UnsupportedOperationException,
                           IndexOutOfBoundsException
Inserts a item at a given position. The passed item is inserted in the list of children at the given position The position is the expected index of the item after insertion. All the previous item from the aimed position to the end of the list are shift to the end of the new sequence (i.e. their indices are shifted up of 1). If the given index is out of the sequence bounds and therefore less than zero and greater or equal to the current number of items,the operation raises an exception. An index equal to the current number of item is allowed and the operation is therefore equivalent to an append.

Specified by:
addItem in interface DrbSequence
Parameters:
index - The expected index of the item after the insertion.
item - A reference to the item to be inserted.
Returns:
A reference to the a sequence containing the inserted node.
Throws:
NullPointerException - This exception is raised when the passed item a null reference. This exception may be overriden by an UnsupportedOperationException.
IndexOutOfBoundsException - This exception is raised when the passe index is less than zero or if it is greater or equal to the number of item in the sequence prior the call
UnsupportedOperationException - This exception is raised when the implementation does not support the requested insertion for any reason (e.g. impossible in this current specific case or in general).

addItem

public DrbSequence addItem(DrbItem item)
                    throws NullPointerException,
                           UnsupportedOperationException
Appends an item at the end of the item list.

Important note: The implementation of the node is not supposed to accept any kind of node For instance it may not be possible to append a node wrapping a file in an XML document. The documentation of the implementation shall describe its specific strategy.

Case of unordered or specifically ordered implementations: If the implementation does not support ordered children or has specific ordering rules, the node may not be appended but only inserted according to these rules. For instance it may not be possible to impose the file order in a directory:it generally depends on the lexicographical order of the node names or their creation date.

Parameters:
item - A reference to the item to be appended.
Returns:
A reference to the a sequence containing the appended node.
Throws:
NullPointerException - This exception is raised when the passed node a null reference.This exception may be overriden by an UnsupportedOperationException.
UnsupportedOperationException - This exception is raised when the implementation does not support the requested append for any reason (e.g. impossible in this current specific case or in general).

removeItem

public DrbSequence removeItem(int index)
                       throws IndexOutOfBoundsException,
                              UnsupportedOperationException
Removes an existing item. The item at the given index is removed from the sequence of the current item. The item is not modified by this operation. The index of the item to be removed has to correspond to an existing item index. If the index is less than zero or greater or equal to the current number of items, an exception is thrown.

Specified by:
removeItem in interface DrbSequence
Parameters:
index - Index of the item to be removed.
Returns:
A reference to the a sequence after the removal of the item.
Throws:
IndexOutOfBoundsException - This exception is raised when the passed index is less than zero or greater or equal to the current number of children.
UnsupportedOperationException - This exception is raised when the implementation does not support the requested removal for any reason.

toString

public String toString()
Returns the string representation of this sequence

Overrides:
toString in class AbstractCollection<DrbItem>
Returns:
the sequence as a string

main

public static void main(String[] args)
Make this class runnable for testing.

Parameters:
args - the arguments.

Data Request Broker - DRB API®
2-3-release

Copyright© 2001-2009 GAEL Consultant. All rights reserved. Use is subject to license terms .