AFLPcore
Class DataList

java.lang.Object
  |
  +--java.util.AbstractCollection
        |
        +--java.util.AbstractList
              |
              +--java.util.Vector
                    |
                    +--AFLPcore.DataList
All Implemented Interfaces:
java.lang.Cloneable, java.util.Collection, java.util.List, java.io.Serializable

public class DataList
extends java.util.Vector

This is an expandable list that can be used to store objects of type Data. The capacity will be increased automatically as needed. The whole list can be duplicated as well as matched to another list. Additionally, if all of the elements in the list are of type SortableData the list can be searched easily. However, since the searches are Binary Searches, the list must be kept ordered. To do this, simply add elemenets using the include method, which will keep the list ordered. Finally, even more options are available by calling methods in the super class, however, these should only be used if this class does not offer a similar feature.

See Also:
Serialized Form

Fields inherited from class java.util.Vector
capacityIncrement, elementCount, elementData
 
Fields inherited from class java.util.AbstractList
modCount
 
Constructor Summary
DataList()
          Constructs an empty DataList.
DataList(int capacity)
          Constructs an empty DataList with the specified initial capacity.
DataList(int capacity, int increment)
          Constructs an empty DataList with the specified initial capacity and capacity increment.
 
Method Summary
 void addData(Data dt)
          Adds the specified data to the list.
 DataList completeClone()
          Creates a new list that is identical to this one with a completely seperate copy of the data in the list.
 void copyList(DataList dest)
          Copies the data in this list to the specified destination.
 Data dataAt(int index)
          Retrieve the data at the specified index.
 SearchReturn find(double key)
          Finds the location of the specified key.
 SortableData findNearestUnder(double key)
          Gives the SortableData element which is less than or equal to the given value.
 void include(SortableData newData)
          Places the given data in the list so that the order of the list is maintained.
 
Methods inherited from class java.util.Vector
add, add, addAll, addAll, addElement, capacity, clear, clone, contains, containsAll, copyInto, elementAt, elements, ensureCapacity, equals, firstElement, get, hashCode, indexOf, indexOf, insertElementAt, isEmpty, lastElement, lastIndexOf, lastIndexOf, remove, remove, removeAll, removeAllElements, removeElement, removeElementAt, removeRange, retainAll, set, setElementAt, setSize, size, subList, toArray, toArray, toString, trimToSize
 
Methods inherited from class java.util.AbstractList
iterator, listIterator, listIterator
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.List
iterator, listIterator, listIterator
 

Constructor Detail

DataList

public DataList()
Constructs an empty DataList.

DataList

public DataList(int capacity)
Constructs an empty DataList with the specified initial capacity.
Parameters:
capacity - the initial capacity of the DataList.

DataList

public DataList(int capacity,
                int increment)
Constructs an empty DataList with the specified initial capacity and capacity increment.
Parameters:
capacity - the initial capacity of the DataList.
increment - the amount by which the capacity is increased when the DataList overflows.
Method Detail

addData

public void addData(Data dt)
Adds the specified data to the list.
Parameters:
dt - the data to add.

dataAt

public Data dataAt(int index)
Retrieve the data at the specified index.
Parameters:
index - the location of the desired data.
Throws:
ArrayIndexOutOfBoundsException - if the index is not valid.

include

public void include(SortableData newData)
Places the given data in the list so that the order of the list is maintained. This should be used if any searching of the list is to be done, since the serach algorithm assumes the list is sorted. Note that this works fine for the first element of a list.
Parameters:
newData - the data to be added to the list
Throws:
ListNotSearchableError - occurs when the list containes data that cannot be ordered.

findNearestUnder

public SortableData findNearestUnder(double key)
Gives the SortableData element which is less than or equal to the given value. All of the data in the list must be of type SortableData for this method to work. If unsortable data has been added to the list, an error will be thrown. Also, the search algorithm is a binary search, so the List, must be sorted. Therefore, data should be added with the includeData instead of the addData method.
Parameters:
key - the value to compare to
Returns:
the object which has a search value <= the key such that no other object in the list exists that is greater than the returned object, but still less than or equal to the key. null if no such peak exists.
Throws:
ListNotSearchableError - Given when some of the data is not ordered and therefor, the list cannot be searched.
See Also:
Data, SortableData, include(AFLPcore.SortableData)

find

public SearchReturn find(double key)
Finds the location of the specified key. All of the data in the list must be of type SortableData, which can be ordered, but simple Data cannot. If unsortable data has been added to the list, an error will be thrown. Also, the search algorithm is a binary search, so the List, must be sorted. Therefore, data should be added with the include instead of the addData method.
Parameters:
key - the value to search for
Returns:
an object with two values. The location variable will hold the index of the data with the key. It will be -1 if the data is not found. In that case, the insertIndex variable will hold the index where the data should be.
Throws:
ListNotSearchableError - Given when some of the data is not ordered and therefor, the list cannot be searched.
See Also:
Data, SortableData, include(AFLPcore.SortableData)

completeClone

public DataList completeClone()
Creates a new list that is identical to this one with a completely seperate copy of the data in the list. That is to say that not only the list itself is cloned, but all of the data in the list as well.
Returns:
a list that is seperate but otherwise identical to this one.

copyList

public void copyList(DataList dest)
Copies the data in this list to the specified destination. This means that the data in the destination will be discarded. Note that it simply causes the destination list to point to the same data. It does not copy the data itself, only the references to the data.
Parameters:
dest - the destination list