jopt.csp.util
Class SortableLongList

java.lang.Object
  extended byorg.apache.commons.collections.primitives.AbstractLongCollection
      extended byorg.apache.commons.collections.primitives.RandomAccessLongList
          extended byorg.apache.commons.collections.primitives.ArrayLongList
              extended byjopt.csp.util.SortableLongList
All Implemented Interfaces:
org.apache.commons.collections.primitives.LongCollection, org.apache.commons.collections.primitives.LongList, java.io.Serializable

public class SortableLongList
extends org.apache.commons.collections.primitives.ArrayLongList

A flexible, sortable list of long primitives. Borrows much of its functionality from the ArrayLongList implementation given in the Commons Primitives project (http://jakarta.apache.org/commons/primitives/index.html)

Author:
Chris Johnson
See Also:
Serialized Form

Constructor Summary
SortableLongList()
          Construct an empty list with the default initial capacity.
SortableLongList(int initialCapacity)
          Construct an empty list with the given initial capacity.
SortableLongList(org.apache.commons.collections.primitives.LongCollection that)
          Constructs a list containing the elements of the given collection, in the order they are returned by that collection's iterator.
 
Method Summary
 void add(int index, long element)
          Inserts the specified element at the specified position (optional operation).
 int binarySearch(long key)
          Searches the list for the specified key via Arrays.binarySearch(long[], long)
 void ensureCapacity(int mincap)
          Increases my capacity, if necessary, to ensure that I can hold at least the number of elements specified by the minimum capacity argument without growing.
 long get(int index)
           
 long removeElementAt(int index)
          Removes the element at the specified position in (optional operation).
 void reverse()
          Reverses the order of the elements
 long set(int index, long element)
          Replaces the element at the specified position in me with the specified element (optional operation).
 int size()
           
 void sort()
          Sorts the list into ascending numerical order via Arrays.sort(long[])
 void sort(int fromIndex, int toIndex)
          Sorts the specified range of the list into ascending numerical order via Arrays.sort(long[], int, int)
 void swap(int i, int j)
          Swaps the two specified elements.
 void trimToSize()
          Reduce my capacity, if necessary, to match my current size.
 
Methods inherited from class org.apache.commons.collections.primitives.RandomAccessLongList
add, addAll, equals, hashCode, indexOf, iterator, lastIndexOf, listIterator, listIterator, subList, toString
 
Methods inherited from class org.apache.commons.collections.primitives.AbstractLongCollection
addAll, clear, contains, containsAll, isEmpty, removeAll, removeElement, retainAll, toArray, toArray
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.apache.commons.collections.primitives.LongList
add, addAll, equals, hashCode, indexOf, iterator, lastIndexOf, listIterator, listIterator, subList
 
Methods inherited from interface org.apache.commons.collections.primitives.LongCollection
addAll, clear, contains, containsAll, isEmpty, removeAll, removeElement, retainAll, toArray, toArray
 

Constructor Detail

SortableLongList

public SortableLongList()
Construct an empty list with the default initial capacity.


SortableLongList

public SortableLongList(int initialCapacity)
Construct an empty list with the given initial capacity.

Throws:
java.lang.IllegalArgumentException - when initialCapacity is negative

SortableLongList

public SortableLongList(org.apache.commons.collections.primitives.LongCollection that)
Constructs a list containing the elements of the given collection, in the order they are returned by that collection's iterator.

Parameters:
that - the non-null collection of longs to add
Throws:
java.lang.NullPointerException - if that is null
See Also:
AbstractLongCollection.addAll(org.apache.commons.collections.primitives.LongCollection)
Method Detail

get

public long get(int index)

size

public int size()

removeElementAt

public long removeElementAt(int index)
Removes the element at the specified position in (optional operation). Any subsequent elements are shifted to the left, subtracting one from their indices. Returns the element that was removed.

Parameters:
index - the index of the element to remove
Returns:
the value of the element that was removed
Throws:
java.lang.UnsupportedOperationException - when this operation is not supported
java.lang.IndexOutOfBoundsException - if the specified index is out of range

set

public long set(int index,
                long element)
Replaces the element at the specified position in me with the specified element (optional operation). If specified index is beyond the current size, the list grows to accommodate it. No IndexOutOfBoundsException will occur during the set operation.

Parameters:
index - the index of the element to change
element - the value to be stored at the specified position
Returns:
the value previously stored at the specified position
Throws:
java.lang.UnsupportedOperationException - when this operation is not supported

add

public void add(int index,
                long element)
Inserts the specified element at the specified position (optional operation). Shifts the element currently at that position (if any) and any subsequent elements to the right, increasing their indices. If the specified index is beyond the current size, this method behaves like a call to set(int, long).

Parameters:
index - the index at which to insert the element
element - the value to insert
Throws:
java.lang.UnsupportedOperationException - when this operation is not supported
java.lang.IllegalArgumentException - if some aspect of the specified element prevents it from being added to me

ensureCapacity

public void ensureCapacity(int mincap)
Increases my capacity, if necessary, to ensure that I can hold at least the number of elements specified by the minimum capacity argument without growing.


trimToSize

public void trimToSize()
Reduce my capacity, if necessary, to match my current size.


sort

public void sort()
Sorts the list into ascending numerical order via Arrays.sort(long[])


reverse

public void reverse()
Reverses the order of the elements


swap

public void swap(int i,
                 int j)
Swaps the two specified elements. (If the specified positions are equal, invoking this method leaves the list unchanged.)


binarySearch

public int binarySearch(long key)
Searches the list for the specified key via Arrays.binarySearch(long[], long)

The array must be sorted (as by the sort method, above) prior to making this call. If it is not sorted, the results are undefined. If the list contains multiple elements with the specified value, there is no guarantee which one will be found.

Parameters:
key - the value to be searched for
Returns:
index of the search key, if it is contained in the list; otherwise, (-(insertion point) - 1)

sort

public void sort(int fromIndex,
                 int toIndex)
Sorts the specified range of the list into ascending numerical order via Arrays.sort(long[], int, int)

Parameters:
fromIndex - the index of the first element (inclusive) to be sorted
toIndex - the index of the last element (exclusive) to be sorted