messif.objects.util
Class AbstractObjectList<E extends AbstractObject>

java.lang.Object
  extended by java.util.AbstractCollection<E>
      extended by java.util.AbstractList<E>
          extended by java.util.ArrayList<E>
              extended by messif.objects.util.AbstractObjectList<E>
Type Parameters:
E - the type of abstract objects stored in this list
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable, java.lang.Iterable<E>, java.util.Collection<E>, java.util.List<E>, java.util.RandomAccess, ObjectProvider<E>

public class AbstractObjectList<E extends AbstractObject>
extends java.util.ArrayList<E>
implements java.io.Serializable, ObjectProvider<E>

Resizable-array for storing AbstractObjects or their descendants. All list operations are implemented and additional support for building randomly selected AbstracObject lists is provided. Additionally, the list returns GenericObjectIterator through iterator method.

See Also:
Serialized Form

Field Summary
 
Fields inherited from class java.util.AbstractList
modCount
 
Constructor Summary
AbstractObjectList()
          Constructs an empty AbstractObject list with an initial capacity of ten.
AbstractObjectList(java.util.Collection<? extends E> source)
          Constructs an AbstractObject list containing the elements of the specified collection, in the order they are returned by the collection's iterator.
AbstractObjectList(int capacity)
          Constructs an empty AbstractObject list with the specified initial capacity.
AbstractObjectList(java.util.Iterator<? extends E> iterator)
          Constructs an AbstractObject list containing all elements returned by the specified iterator (in that order).
AbstractObjectList(java.util.Iterator<? extends E> iterator, int count)
          Constructs an AbstractObject list containing maximally count elements returned by the specified iterator (in that order).
 
Method Summary
 int addAll(java.util.Iterator<? extends E> iterator)
          Appends all of the elements that can be retrieved from the specified iterator to the end of this list.
 boolean dataEquals(java.lang.Object obj)
          Indicates whether some other object has the same data as this one.
 int dataHashCode()
          Returns a hash code value for the data of this list.
 UniqueID getObjectID(int index)
          Returns the ID of object at specified position.
 AbstractObjectIterator<E> iterator()
          Returns an iterator over the elements in this list in proper sequence.
 AbstractObjectIterator<E> provideObjects()
          The iterator for provided objects for ObjectProvider interface.
static
<F extends AbstractObject>
AbstractObjectList<F>
randomList(int count, boolean unique, java.util.Iterator<F> iterSource)
          Returns a list containing randomly choosen objects from the passed iterator.
<T extends java.util.List<E>>
T
randomList(int count, boolean unique, T list)
          Returns a list containing randomly choosen objects from this list.
static
<F extends AbstractObject,T extends java.util.List<F>>
T
randomList(int count, boolean unique, T list, java.util.Iterator<F> iterSource)
          Returns a list containing randomly choosen objects from the passed iterator.
 E randomObject()
          Returns one object selected from the list at random.
 java.lang.String toString()
          Returns a string representation of this collection of objects.
 
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, 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, listIterator, listIterator, removeAll, retainAll, subList
 

Constructor Detail

AbstractObjectList

public AbstractObjectList(int capacity)
                   throws java.lang.IllegalArgumentException
Constructs an empty AbstractObject list with the specified initial capacity.

Parameters:
capacity - the initial capacity of the list
Throws:
java.lang.IllegalArgumentException - if the specified initial capacity is negative

AbstractObjectList

public AbstractObjectList()
Constructs an empty AbstractObject list with an initial capacity of ten.


AbstractObjectList

public AbstractObjectList(java.util.Collection<? extends E> source)
                   throws java.lang.NullPointerException
Constructs an AbstractObject list containing the elements of the specified collection, in the order they are returned by the collection's iterator.

Parameters:
source - the collection whose elements are to be placed into this list
Throws:
java.lang.NullPointerException - if the specified collection is null

AbstractObjectList

public AbstractObjectList(java.util.Iterator<? extends E> iterator,
                          int count)
                   throws java.lang.NullPointerException
Constructs an AbstractObject list containing maximally count elements returned by the specified iterator (in that order).

Parameters:
iterator - the iterator returing elements that are to be placed into this list
count - maximal number of objects that are placed from iterator (negative number means unlimited)
Throws:
java.lang.NullPointerException - if the specified iterator is null

AbstractObjectList

public AbstractObjectList(java.util.Iterator<? extends E> iterator)
                   throws java.lang.NullPointerException
Constructs an AbstractObject list containing all elements returned by the specified iterator (in that order).

Parameters:
iterator - the iterator returing elements that are to be placed into this list
Throws:
java.lang.NullPointerException - if the specified iterator is null
Method Detail

getObjectID

public UniqueID getObjectID(int index)
Returns the ID of object at specified position.

Parameters:
index - position of object in the list
Returns:
the ID of object at position index

iterator

public AbstractObjectIterator<E> iterator()
Returns an iterator over the elements in this list in proper sequence.

Specified by:
iterator in interface java.lang.Iterable<E extends AbstractObject>
Specified by:
iterator in interface java.util.Collection<E extends AbstractObject>
Specified by:
iterator in interface java.util.List<E extends AbstractObject>
Overrides:
iterator in class java.util.AbstractList<E extends AbstractObject>
Returns:
an iterator over the elements in this list in proper sequence

provideObjects

public AbstractObjectIterator<E> provideObjects()
The iterator for provided objects for ObjectProvider interface.

Specified by:
provideObjects in interface ObjectProvider<E extends AbstractObject>
Returns:
iterator for provided objects

addAll

public int addAll(java.util.Iterator<? extends E> iterator)
Appends all of the elements that can be retrieved from the specified iterator to the end of this list.

Parameters:
iterator - iterator over elements to be added to this list
Returns:
the number of objects added

dataEquals

public boolean dataEquals(java.lang.Object obj)
Indicates whether some other object has the same data as this one.

Parameters:
obj - the reference object with which to compare.
Returns:
true if this object has the same data as the obj argument; false otherwise.

dataHashCode

public int dataHashCode()
Returns a hash code value for the data of this list.

Returns:
a hash code value for the data of this list

toString

public java.lang.String toString()
Returns a string representation of this collection of objects.

Overrides:
toString in class java.util.AbstractCollection<E extends AbstractObject>
Returns:
a string representation of this collection of objects

randomObject

public E randomObject()
Returns one object selected from the list at random.

Returns:
An object selected at random or null if the list is empty.

randomList

public <T extends java.util.List<E>> T randomList(int count,
                                                  boolean unique,
                                                  T list)
Returns a list containing randomly choosen objects from this list. If the uniqueness of objects in the retrieved list is not required, the number of objects in the response is equal to 'count'. If unique list is requested the number of objects can vary from 0 to 'count' and depends on the number of objects in this list. When this list consists of fewer objects than 'count' the whole list is returned at any case. The returned instance is exactly the same as passed in the parameter list. Chosen objects are only added to this list. If the passed list contains some objects they are left untouched.

Type Parameters:
T - the list class that receives random objects
Parameters:
count - Number of object to return.
unique - Flag if returned list contains each object only once.
list - An instance of a class extending ObjectList used to carry selected objects.
Returns:
the instance passed in list which contains randomly selected objects as requested

randomList

public static <F extends AbstractObject,T extends java.util.List<F>> T randomList(int count,
                                                                                  boolean unique,
                                                                                  T list,
                                                                                  java.util.Iterator<F> iterSource)
Returns a list containing randomly choosen objects from the passed iterator. If the uniqueness of objects in the retrieved list is not required, the number of objects in the response is equal to 'count'. If a unique list is requested, the number of objects can vary from zero to 'count' and depends on the number of objects in the passed iterator. When the iterator consists of fewer objects than 'count', all objects are returned at any case. The returned instance is exactly the same as passed in the parameter 'list'. Chosen objects are only added to this list. If the passed list contains some objects they are left untouched.

Type Parameters:
F - the class of objects that are stored in the list
T - the list class that receives random objects
Parameters:
count - Number of object to return.
unique - Flag if returned list contains each object only once.
list - An instance of a class extending ObjectList used to carry selected objects.
iterSource - Iterator from which objects are randomly picked.
Returns:
the instance passed in list which contains the randomly selected objects as requested

randomList

public static <F extends AbstractObject> AbstractObjectList<F> randomList(int count,
                                                                          boolean unique,
                                                                          java.util.Iterator<F> iterSource)
Returns a list containing randomly choosen objects from the passed iterator. If the uniqueness of objects in the retrieved list is not required, the number of objects in the response is equal to 'count'. If a unique list is requested, the number of objects can vary from zero to 'count' and depends on the number of objects in the passed iterator. When the iterator consists of fewer objects than 'count', all objects are returned at any case. The returned instance is a new AbstractObjectList with the iterator's type of objects.

Type Parameters:
F - the class of objects that are stored in the list
Parameters:
count - Number of object to return.
unique - Flag if returned list contains each object only once.
iterSource - Iterator from which objects are randomly picked.
Returns:
the instance passed in list which contains the randomly selected objects as requested