jopt.csp.util
Class SortableDoubleList

java.lang.Object
  extended byorg.apache.commons.collections.primitives.AbstractDoubleCollection
      extended byorg.apache.commons.collections.primitives.RandomAccessDoubleList
          extended byorg.apache.commons.collections.primitives.ArrayDoubleList
              extended byjopt.csp.util.SortableDoubleList
All Implemented Interfaces:
org.apache.commons.collections.primitives.DoubleCollection, org.apache.commons.collections.primitives.DoubleList, java.io.Serializable

public class SortableDoubleList
extends org.apache.commons.collections.primitives.ArrayDoubleList

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

Author:
Chris Johnson
See Also:
Serialized Form

Constructor Summary
SortableDoubleList()
          Construct an empty list with the default initial capacity.
SortableDoubleList(org.apache.commons.collections.primitives.DoubleCollection that)
          Constructs a list containing the elements of the given collection, in the order they are returned by that collection's iterator.
SortableDoubleList(int initialCapacity)
          Construct an empty list with the given initial capacity.
 
Method Summary
 void add(int index, double element)
          Inserts the specified element at the specified position (optional operation).
 int binarySearch(double key)
          Searches the list for the specified key via Arrays.binarySearch(double[], double)
 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.
 double get(int index)
           
 double removeElementAt(int index)
          Removes the element at the specified position in (optional operation).
 void reverse()
          Reverses the order of the elements
 double set(int index, double 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(double[])
 void sort(int fromIndex, int toIndex)
          Sorts the specified range of the list into ascending numerical order via Arrays.sort(double[], 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.RandomAccessDoubleList
add, addAll, equals, hashCode, indexOf, iterator, lastIndexOf, listIterator, listIterator, subList, toString
 
Methods inherited from class org.apache.commons.collections.primitives.AbstractDoubleCollection
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.DoubleList
add, addAll, equals, hashCode, indexOf, iterator, lastIndexOf, listIterator, listIterator, subList
 
Methods inherited from interface org.apache.commons.collections.primitives.DoubleCollection
addAll, clear, contains, containsAll, isEmpty, removeAll, removeElement, retainAll, toArray, toArray
 

Constructor Detail

SortableDoubleList

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


SortableDoubleList

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

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

SortableDoubleList

public SortableDoubleList(org.apache.commons.collections.primitives.DoubleCollection 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 doubles to add
Throws:
java.lang.NullPointerException - if that is null
See Also:
AbstractDoubleCollection.addAll(org.apache.commons.collections.primitives.DoubleCollection)
Method Detail

get

public double get(int index)

size

public int size()

removeElementAt

public double 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 double set(int index,
                  double 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,
                double 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, double).

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(double[])


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(double key)
Searches the list for the specified key via Arrays.binarySearch(double[], double)

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(double[], 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