The Octet Molecular Representation Framework v0.8.2

net.sf.octet.util
Class ArraySequence

java.lang.Object
  extended bynet.sf.octet.util.ArraySequence
All Implemented Interfaces:
Sequence

public class ArraySequence
extends java.lang.Object
implements Sequence

A default implementation of the Sequence interface backed by an array.

Author:
Richard Apodaca

Constructor Summary
ArraySequence()
          Constructs an empty ArraySequence that will return null for getObjectClass().
ArraySequence(java.util.Collection collection, java.lang.Class objectClass)
          Constructs an ArraySequence from the elements of collection by enforcing the constraint that all of its members are of type objectClass.
ArraySequence(java.lang.Object[] array, java.lang.Class objectClass)
          Constructs an ArraySequence from the elements of array by enforcing the constraint that all of its members are of type objectClass.
 
Method Summary
 boolean contains(java.lang.Object o)
          Returns true if the Object can be found in this Sequence.
 java.lang.Object get(int index)
          Returns the Object at the specified position in this Sequence.
 java.lang.Class getElementClass()
          Returns the Class of the Objects contained in this Sequence.
 int indexOf(java.lang.Object o)
          Returns the index of the specified Object, or -1 if it could not be found.
 java.util.Iterator iterator()
          Returns an Iterator over the objects in this Sequence.
 boolean objectsImplement(java.lang.Class classInterface)
          Returns true if the Objects in this Sequence implement classInterface, or false otherwise.
 int size()
          Returns the number of objects in this Sequence.
 java.lang.Object[] toArray()
          Returns the Objects of this sequence as an array.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ArraySequence

public ArraySequence()
Constructs an empty ArraySequence that will return null for getObjectClass().


ArraySequence

public ArraySequence(java.util.Collection collection,
                     java.lang.Class objectClass)
Constructs an ArraySequence from the elements of collection by enforcing the constraint that all of its members are of type objectClass.

Parameters:
collection - the collection
objectClass - the type of all Objects in collection
Throws:
java.lang.NullPointerException - if collection contains null, or if objectClass is null
java.lang.IllegalArgumentException - if collection contains elements of mixed class, or if Objects of type other than objectClass are found in collection

ArraySequence

public ArraySequence(java.lang.Object[] array,
                     java.lang.Class objectClass)
Constructs an ArraySequence from the elements of array by enforcing the constraint that all of its members are of type objectClass.

Parameters:
array - the array
objectClass - the type of all Objects in array
Throws:
java.lang.NullPointerException - if array contains null, or if objectClass is null
java.lang.IllegalArgumentException - if array contains elements of mixed class, or if Objects of type other than objectClass are found in collection
Method Detail

contains

public boolean contains(java.lang.Object o)
Description copied from interface: Sequence
Returns true if the Object can be found in this Sequence.

Specified by:
contains in interface Sequence
Parameters:
o - the Object to find
Returns:
true if o can be found, or false otherwise

size

public int size()
Description copied from interface: Sequence
Returns the number of objects in this Sequence.

Specified by:
size in interface Sequence
Returns:
the number of objects in this Sequence

indexOf

public int indexOf(java.lang.Object o)
Description copied from interface: Sequence
Returns the index of the specified Object, or -1 if it could not be found.

Specified by:
indexOf in interface Sequence
Parameters:
o - the Object to find
Returns:
true if o could be found, or false otherwise

get

public java.lang.Object get(int index)
Description copied from interface: Sequence
Returns the Object at the specified position in this Sequence.

Specified by:
get in interface Sequence
Parameters:
index - the index to query
Returns:
the Object at index

iterator

public java.util.Iterator iterator()
Description copied from interface: Sequence
Returns an Iterator over the objects in this Sequence.

Specified by:
iterator in interface Sequence
Returns:
an Iterator over the objects in this Sequence

toArray

public java.lang.Object[] toArray()
Description copied from interface: Sequence
Returns the Objects of this sequence as an array. This array can be modified without changing the state of this Sequence. The ordering in the returned array is identical to the ordering in iterator().

Specified by:
toArray in interface Sequence
Returns:
the Objects of this sequence as an array

getElementClass

public java.lang.Class getElementClass()
Description copied from interface: Sequence
Returns the Class of the Objects contained in this Sequence.

Specified by:
getElementClass in interface Sequence
Returns:
the Class of the Objects contained in this Sequence

objectsImplement

public boolean objectsImplement(java.lang.Class classInterface)
Description copied from interface: Sequence
Returns true if the Objects in this Sequence implement classInterface, or false otherwise.

Specified by:
objectsImplement in interface Sequence
Parameters:
classInterface - the interface to query Objects against
Returns:
true if the Objects in this Sequence implement classInterface, or false otherwise

The Octet Molecular Representation Framework v0.8.2