no.uio.edd.utils.datautils
Class ExtendableObjectList

java.lang.Object
  extended by no.uio.edd.utils.datautils.ExtendableObjectList
Direct Known Subclasses:
ExtendableNodeList, ExtendableStringList

public class ExtendableObjectList
extends java.lang.Object

Objects of this class is used to store list of objects. The list may be of variable length. The list is zero indexed. Elements cannot be removed; set to null instead. Implementation notes: Maximum length of the list is the maximum length of the datatype int. The actual storage is in arrays. Initially the length is 10, the array is expanded in chunks of 10. Will not scale for long lists. TODO: Demand that the user adds the object type for this. If null, mixed array.

Author:
oeide

Constructor Summary
ExtendableObjectList()
          Creates a new list object.
ExtendableObjectList(java.lang.Object firstElem)
          Creates a new list object.
ExtendableObjectList(java.lang.Object[] newList)
          Creates a new list object.
 
Method Summary
 int addElem(java.lang.Object newElem)
          Add a new element to the list.
 int addElemUnlessAlreadyThere(java.lang.Object newElem)
          Add a new element to the list unless it is already there.
 void addObjectArray(java.lang.Object[] newObjectArr)
          Adding a full array of objects to the list.
 boolean emptyList()
          Checks if my list is empty.
 int findObject(java.lang.Object objectToBeFound)
          Find first occurrences of one specific object from my list.
 java.lang.Object getElem(int num)
          Return one element from the list.
 int getLength()
          Find the length of the list.
 int getLengthNoNulls()
          Find the length of the list when all null objects are excluded.
 java.lang.Object[] getList()
          Get the full object list held by this object.
 java.lang.Object[] getListNoNulls()
          Get the full object list held by this object, from which all null elements are removed.
 int getNextFree()
          Find the place in the list in which the next element will be located.
 boolean nullFirstObjectInList(java.lang.Object toBeNulled)
          Set to null (that is, as close we get to removal) the first occurrence of one specific object from my list.
 int nullObjectsInList(java.lang.Object toBeNulled)
          Set to null (that is, as close we get to removal) all occurrences of one specific object from my list.
 java.lang.Object[] removeDuplicates()
          If there are duplicates in the list, returns a list where all but the first occurrence are set to null.
 java.lang.Object[] removeDuplicatesAndNulls()
          If there are duplicates in the list, returns a list where all but the first occurrence are removed.
 void setElem(int num, java.lang.Object newValue)
          Set an element in the list to a new value.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ExtendableObjectList

public ExtendableObjectList(java.lang.Object firstElem)
Creates a new list object.

Parameters:
firstElem - The first element of the list.

ExtendableObjectList

public ExtendableObjectList()
Creates a new list object.


ExtendableObjectList

public ExtendableObjectList(java.lang.Object[] newList)
Creates a new list object.

Parameters:
newList - An array of objects to be set as mine.
Method Detail

addElem

public int addElem(java.lang.Object newElem)
Add a new element to the list.

Parameters:
newElem - The new element.
Returns:
The index given to the new element.

addElemUnlessAlreadyThere

public int addElemUnlessAlreadyThere(java.lang.Object newElem)
Add a new element to the list unless it is already there.

Parameters:
newElem - The new element.
Returns:
The index given to the new element. If it is not added, -1 is returned.

getElem

public java.lang.Object getElem(int num)
Return one element from the list.

Parameters:
num - The index number of the element to be returned.
Returns:

setElem

public void setElem(int num,
                    java.lang.Object newValue)
Set an element in the list to a new value. The closest we get to removing elements in to use this to set to null. Mutable.

Parameters:
num - The index number of the element to be set.
newValue - The new object.

getList

public java.lang.Object[] getList()
Get the full object list held by this object. Will normally include trailing null elements that was never initialised.

Returns:

getListNoNulls

public java.lang.Object[] getListNoNulls()
Get the full object list held by this object, from which all null elements are removed.

Returns:

nullObjectsInList

public int nullObjectsInList(java.lang.Object toBeNulled)
Set to null (that is, as close we get to removal) all occurrences of one specific object from my list. Uses equals to compare. Mutable.

Parameters:
toBeNulled - The object to be nulled.
Returns:
The number of objects nulled.

nullFirstObjectInList

public boolean nullFirstObjectInList(java.lang.Object toBeNulled)
Set to null (that is, as close we get to removal) the first occurrence of one specific object from my list. Uses equals to compare. Mutable.

Parameters:
toBeNulled - The object to be nulled.
Returns:
True if found.

findObject

public int findObject(java.lang.Object objectToBeFound)
Find first occurrences of one specific object from my list. Uses equals to compare.

Parameters:
objectToBeFound - The object to be found.
Returns:
The index number of the occurrence of the object. -1 if not found.

emptyList

public boolean emptyList()
Checks if my list is empty. Empty hear means no items, or all items in the list are null.

Returns:
True if the list is empty.

getNextFree

public int getNextFree()
Find the place in the list in which the next element will be located. Because the list is not compressed, this is not necessarily connected to the number of elements actually in the list, but it will always be >= the number of elements in the list.

Returns:
The next available space in the list.

getLength

public int getLength()
Find the length of the list. This is longer than the actual filled list, as it is expanded in chunks of 10 elements.

Returns:
The length of the list.

getLengthNoNulls

public int getLengthNoNulls()
Find the length of the list when all null objects are excluded. Thus, this is the number of non-null elements in the list.

Returns:
The length of the list.

removeDuplicates

public java.lang.Object[] removeDuplicates()
If there are duplicates in the list, returns a list where all but the first occurrence are set to null. Uses equals to compare. If no duplicates, an identical list is returned.

Returns:
The list where duplicates are nulled.

removeDuplicatesAndNulls

public java.lang.Object[] removeDuplicatesAndNulls()
If there are duplicates in the list, returns a list where all but the first occurrence are removed. Uses equals to compare. If no duplicates or nulls, an identical list is returned.

Returns:
A version of my list without duplicates and nulls.

addObjectArray

public void addObjectArray(java.lang.Object[] newObjectArr)
Adding a full array of objects to the list.

Parameters:
newStringArr -