OpMath

com.opmath.util.datastruct
Class ComparableArray

java.lang.Object
  |
  +--com.opmath.util.datastruct.ComparableArray
All Implemented Interfaces:
ComparableList
Direct Known Subclasses:
ComparableArrayRO

public class ComparableArray
extends Object
implements ComparableList

An object which can serve as a ComparableTable column, implemented using a Comparable[].

ComparableArray implements the ComparableList interface, thus it provides a storage structure for columns of a ComparableTable with exactly the access methods required by the containing class.

ComparableArray is suitable for use where the size of the ComparableTable column is known in advance, but its contents may change. This particular specialisation has one useful behaviour: the clear() method nulls out the contents of the ComparableArray, but leaves the stucture intact.

Copyright: (c) 2002 The Open Math Company Limited

The Terms of Distribution of this software are stipulated in the javadoc Overview for this project.

Since:
J2SE 1.3
Version:
utilities-v011
Author:
Bruno Beloff bruno.beloff@opmath.com

Field Summary
protected  Comparable[] a
           
 
Constructor Summary
ComparableArray(Comparable[] src)
          Constructs a ComparableArray.
ComparableArray(int n)
          Constructs a ComparableArray of size n.
 
Method Summary
 boolean add(Comparable element)
          Always thows an UnsupportedOperationException.
 void clear()
          Sets all of the elements of this ComparableArray to null.
 Enumeration elements()
          Returns an enumeration of the components of this ComparableArray.
 Object get(int i)
          Returns the element at the specified position in this ComparableArray.
 int indexOf(Object element)
          Searches for the first occurence of the given argument, testing for equality using the equals(Object) method.
 Comparable set(int i, Comparable element)
          Replaces the element at the specified position in this ComparableVector with the specified element.
 int size()
          Returns the number of elements in this list.
 String toString()
          Returns a new String, detailing the contents of this ComparableArray instance.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

a

protected Comparable[] a
Constructor Detail

ComparableArray

public ComparableArray(Comparable[] src)
Constructs a ComparableArray. The data for the new instance is a System.arraycopy(..) of the given Compararble[].

Parameters:
src - a Compararble[] used to populate the ComparableArray.
Since:
J2SE 1.3

ComparableArray

public ComparableArray(int n)
Constructs a ComparableArray of size n. The initial value of all the elements will be null. The elements can be modified later with set(int, Comparable).

Parameters:
n - an int specifying the size.
Since:
J2SE 1.3
Method Detail

elements

public Enumeration elements()
Returns an enumeration of the components of this ComparableArray. The returned Enumeration object will generate all items in this list.

Specified by:
elements in interface ComparableList
Returns:
an enumeration of the components of this list.
Since:
J2SE 1.3

clear

public void clear()
Sets all of the elements of this ComparableArray to null.

Note that clear() does not alter the size of this ComparableArray instance.

Specified by:
clear in interface ComparableList
Since:
J2SE 1.3

add

public boolean add(Comparable element)
            throws UnsupportedOperationException
Always thows an UnsupportedOperationException.

NOTE: Although it is declared as returning a boolean, add(Comparable) never returns anything.

Specified by:
add in interface ComparableList
Parameters:
element - the Comparable to be added.
Returns:
true (as per the general contract of the Collection.add method).
Throws:
UnsupportedOperationException - always.
Since:
J2SE 1.3

set

public Comparable set(int i,
                      Comparable element)
               throws ArrayIndexOutOfBoundsException
Replaces the element at the specified position in this ComparableVector with the specified element.

Specified by:
set in interface ComparableList
Parameters:
element - the Comparable element to be stored at the specified position.
i - the int index of element to replace.
Returns:
the Comparable element previously stored at this location.
Throws:
ArrayIndexOutOfBoundsException - an exception thrown if the index is out of range (index < 0 || index >= size()).
Since:
J2SE 1.3

get

public Object get(int i)
           throws IndexOutOfBoundsException
Returns the element at the specified position in this ComparableArray.

Specified by:
get in interface ComparableList
Parameters:
i - the int index of element.
Returns:
the element at the specified position in this ComparableResultSet.
Throws:
ArrayIndexOutOfBoundsException - an exception thrown if the index is out of range (index < 0 || index >= size()).
IndexOutOfBoundsException - if the index is out of range (index < 0 || index >= size()).
Since:
J2SE 1.3

indexOf

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

Specified by:
indexOf in interface ComparableList
Returns:
the index of the first occurrence of the argument in this vector, that is, the smallest value k such that elem.equals(elementData[k]) is true; returns -1 if the object is not found.
Since:
J2SE 1.3

size

public int size()
Returns the number of elements in this list. If this list contains more than Integer.MAX_VALUE elements, returns Integer.MAX_VALUE.

Specified by:
size in interface ComparableList
Returns:
the number of elements in this list.
Since:
J2SE 1.3

toString

public String toString()
Returns a new String, detailing the contents of this ComparableArray instance.

Specified by:
toString in interface ComparableList
Overrides:
toString in class Object
Returns:
a String.
Since:
J2SE 1.3

OpMath

Submit a bug or feature to Open Math
Copyright © 2002 Open Math Company Limited, Brighton, UK