org.itc.irst.tcc.ties.util
Class IndexList

java.lang.Object
  extended byorg.itc.irst.tcc.ties.util.IndexList
All Implemented Interfaces:
java.io.Serializable

public final class IndexList
extends java.lang.Object
implements java.io.Serializable

The IndexList class implements a growable sorted list of indexes. The list is sorted into increasing order; the order is assured by construction. A new index is added into the list if it is greater than the last index present into the list; othewise it is discarted. Like an array, components that can be accessed using an integer index.

Each IndexList tries to optimize storage management by maintaining a capacity and a capacityIncrement. The capacity is always at least as large as the IndexList size; it is usually larger because as components are added to the IndexList, the IndexList's storage increases in chunks the size of capacityIncrement. An application can increase the capacity of a IndexList before inserting a large number of components; this reduces the amount of incremental reallocation.

Since:
1.0
Version:
%I%, %G%
Author:
Claudio Giuliano
See Also:
Serialized Form

Field Summary
protected  int capacityIncrement
          The amount by which the capacity of the IndexList is automatically incremented when its size becomes greater than its capacity.
protected  int elementCount
          The number of valid components in the IndexList.
protected  int[] elementData
          The array buffer into which the components of the ints are stored.
(package private) static org.apache.log4j.Logger logger
          Define a static logger variable so that it references the Logger instance named IndexList.
 
Constructor Summary
IndexList()
          Constructs an empty IndexList.
IndexList(int initialCapacity)
          Constructs an empty IndexList with the specified initial capacity.
IndexList(int initialCapacity, int capacityIncrement)
          Constructs an empty IndexList with the specified initial capacity and capacity increment.
 
Method Summary
 void add(int index)
          Adds the specified index to the end of this IndexList, increasing its size by one.
 int capacity()
          Returns the current capacity of this IndexList.
 boolean contains(int elem)
          Tests if the specified object is a component in this IndexList.
 void copyInto(int[] anArray)
          Copies the components of this IndexList into the specified array.
 IndexList duplicate()
          Returns an IndexList with the components of this IndexList incremented by inc.
 void ensureCapacity(int minCapacity)
          Increases the capacity of this IndexList, if necessary, to ensure that it can hold at least the number of components specified by the minimum capacity argument.
private  void ensureCapacityHelper(int minCapacity)
          This implements the unsynchronized semantics of ensureCapacity.
 int firstIndex()
          Returns the first index (the item at index 0) of this list.
 int[] getArray()
          Copies the components of this IndexList into the specified array.
 IndexList getIntersection(IndexList indexList)
          Returns the intersection between this object and the specified index list.
 IndexList getIntersection(IndexList indexList, int inc1, int inc2)
          Returns the intersection between this object and the specified index list.
 IndexList getIntersection1(IndexList l2)
           
 IndexList getIntersection1(IndexList l2, int inc1, int inc2)
           
 IndexList getUnion(IndexList indexList)
          Returns the union between this object and the specified index list.
 IndexList incValue(int inc)
          Returns an IndexList with the components of this IndexList incremented by inc.
 IndexList incValue(int inc, int min, int max)
          Returns an IndexList with the components of this IndexList incremented by inc.
 int indexAt(int index)
          Returns the index at the specified position in this list.
 int indexOf(int elem)
          Searches for the first occurence of the given argument, testing for equality using the equals method.
 int indexOf(int elem, int index)
          Searches for the first occurence of the given argument, beginning the search at index, and testing for equality using the equals method.
 boolean isEmpty()
          Tests if this IndexList has no components.
 int lastIndex()
          Returns the last index of this list.
 int lastIndexOf(int elem)
          Returns the index of the last occurrence of the specified object in this IndexList.
 int lastIndexOf(int elem, int index)
          Searches backwards for the specified object, starting from the specified index, and returns an index to it.
 int search(int index)
           
 int search(int index, int inc)
           
 void setIndexAt(int obj, int index)
          Sets the component at the specified index of this vector to be the specified object.
 int size()
          Returns the number of components in this IndexList.
 java.lang.String toString()
          Returns a string representation of this IndexList.
 void trim()
          Trims the capacity of this IndexList to be the IndexList's current size.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

logger

static org.apache.log4j.Logger logger
Define a static logger variable so that it references the Logger instance named IndexList.


elementData

protected int[] elementData
The array buffer into which the components of the ints are stored. The capacity of the IndexList is the length of this array buffer.


elementCount

protected int elementCount
The number of valid components in the IndexList.


capacityIncrement

protected int capacityIncrement
The amount by which the capacity of the IndexList is automatically incremented when its size becomes greater than its capacity. If the capacity increment is 0, the capacity of the IndexList is doubled each time it needs to grow.

Constructor Detail

IndexList

public IndexList(int initialCapacity,
                 int capacityIncrement)
Constructs an empty IndexList with the specified initial capacity and capacity increment.

Parameters:
initialCapacity - the initial capacity of the IndexList.
capacityIncrement - the amount by which the capacity is increased when the IndexList overflows.

IndexList

public IndexList(int initialCapacity)
Constructs an empty IndexList with the specified initial capacity.

Parameters:
initialCapacity - the initial capacity of the IndexList.

IndexList

public IndexList()
Constructs an empty IndexList.

Method Detail

copyInto

public final void copyInto(int[] anArray)
Copies the components of this IndexList into the specified array. The array must be big enough to hold all the objects in this IndexList.

Parameters:
anArray - the array into which the components get copied.

getArray

public final int[] getArray()
Copies the components of this IndexList into the specified array. The array must be big enough to hold all the objects in this IndexList.


incValue

public final IndexList incValue(int inc,
                                int min,
                                int max)
Returns an IndexList with the components of this IndexList incremented by inc.

Parameters:
inc - the amount each component must be incremented.
min - the min value allowed, inclusive..
max - the max value allowed, exclusive.
Returns:
the components of this IndexList incremented by incinto the specified array.

duplicate

public final IndexList duplicate()
Returns an IndexList with the components of this IndexList incremented by inc.

Returns:
the components of this IndexList incremented by incinto the specified array.

incValue

public final IndexList incValue(int inc)
Returns an IndexList with the components of this IndexList incremented by inc.

Parameters:
inc - the amount each component must be incremented.
Returns:
the components of this IndexList incremented by incinto the specified array.

trim

public final void trim()
Trims the capacity of this IndexList to be the IndexList's current size. An application can use this operation to minimize the storage of a IndexList.


ensureCapacity

public final void ensureCapacity(int minCapacity)
Increases the capacity of this IndexList, if necessary, to ensure that it can hold at least the number of components specified by the minimum capacity argument.

Parameters:
minCapacity - the desired minimum capacity.

ensureCapacityHelper

private void ensureCapacityHelper(int minCapacity)
This implements the unsynchronized semantics of ensureCapacity. Synchronized methods in this class can internally call this method for ensuring capacity without incurring the cost of an extra synchronization.


capacity

public final int capacity()
Returns the current capacity of this IndexList.

Returns:
the current capacity of this IndexList.

size

public final int size()
Returns the number of components in this IndexList.

Returns:
the number of components in this IndexList.

isEmpty

public final boolean isEmpty()
Tests if this IndexList has no components.

Returns:
true if this IndexList has no components; false otherwise.

contains

public final boolean contains(int elem)
Tests if the specified object is a component in this IndexList.

Parameters:
elem - an object.
Returns:
true if the specified object is a component in this IndexList; false otherwise.

indexOf

public final int indexOf(int elem)
Searches for the first occurence of the given argument, testing for equality using the equals method.

Parameters:
elem - an object.
Returns:
the index of the first occurrence of the argument in this IndexList; returns -1 if the object is not found.

indexOf

public final int indexOf(int elem,
                         int index)
Searches for the first occurence of the given argument, beginning the search at index, and testing for equality using the equals method.

Parameters:
elem - an object.
index - the index to start searching from.
Returns:
the index of the first occurrence of the object argument in this IndexList at position index or later in the IndexList; returns -1 if the object is not found.

lastIndexOf

public final int lastIndexOf(int elem)
Returns the index of the last occurrence of the specified object in this IndexList.

Parameters:
elem - the desired component.
Returns:
the index of the last occurrence of the specified object in this IndexList; returns -1 if the object is not found.

lastIndexOf

public final int lastIndexOf(int elem,
                             int index)
Searches backwards for the specified object, starting from the specified index, and returns an index to it.

Parameters:
elem - the desired component.
index - the index to start searching from.
Returns:
the index of the last occurrence of the specified object in this IndexList at position less than index in the IndexList; -1 if the object is not found.

indexAt

public final int indexAt(int index)
Returns the index at the specified position in this list.

Returns:
the index at the specified position.

firstIndex

public final int firstIndex()
Returns the first index (the item at index 0) of this list.

Returns:
the first index of this list.
Throws:
java.util.NoSuchElementException - if this IndexList has no components.

lastIndex

public final int lastIndex()
Returns the last index of this list.

Throws:
java.util.NoSuchElementException - if this IndexList is empty.

setIndexAt

public final void setIndexAt(int obj,
                             int index)
Sets the component at the specified index of this vector to be the specified object. The previous component at that position is discarded.

The index must be a value greater than or equal to 0 and less than the current size of the vector.

Parameters:
obj - what the component is to be set to.
index - the specified index.
Throws:
java.lang.ArrayIndexOutOfBoundsException - if the index was invalid.

add

public final void add(int index)
Adds the specified index to the end of this IndexList, increasing its size by one. The capacity of this IndexList is increased if its size becomes greater than its capacity. if the new index is greater than the last index present into the list is added; othewise is discarted.

Parameters:
index - the component to be added.

getIntersection1

public IndexList getIntersection1(IndexList l2)

getIntersection1

public IndexList getIntersection1(IndexList l2,
                                  int inc1,
                                  int inc2)

getIntersection

public IndexList getIntersection(IndexList indexList)
Returns the intersection between this object and the specified index list.

Returns:
the intersection between this object and the specified index list.

getIntersection

public IndexList getIntersection(IndexList indexList,
                                 int inc1,
                                 int inc2)
Returns the intersection between this object and the specified index list.

Returns:
the intersection between this object and the specified index list.

getUnion

public IndexList getUnion(IndexList indexList)
Returns the union between this object and the specified index list.

Returns:
the union between this object and the specified index list.

toString

public final java.lang.String toString()
Returns a string representation of this IndexList.

Returns:
a string representation of this IndexList.

search

public int search(int index)

search

public int search(int index,
                  int inc)