OpMath

com.opmath.util.datastruct
Class ComparableResultSet

java.lang.Object
  |
  +--com.opmath.util.datastruct.ComparableResultSet
All Implemented Interfaces:
ComparableList

public class ComparableResultSet
extends Object
implements ComparableList

An object which can serve as a ComparableTable column, implemented using a java.sql.ResultSet.

ComparableResultSet 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.

This class uses a java.sql.ResultSet as its storage object. The reasons for this are twofold:

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

Constructor Summary
ComparableResultSet(ResultSet rs, String columnName)
          Constructs a new ComparableResultSet.
ComparableResultSet(ResultSet rs, String columnName, int startRowIndex, int endRowIndex)
          Constructs a new ComparableResultSet with limiting row bounds.
 
Method Summary
 boolean add(Comparable element)
          Always thows an UnsupportedOperationException.
 void clear()
          Does nothing.
 Enumeration elements()
          Returns an enumeration of the components of this ComparableResultSet.
 Object get(int index)
          Returns the element at the specified position in this ComparableResultSet.
 int indexOf(Object element)
          Returns the position of the first occurance of element.
 Comparable set(int index, Comparable element)
          Always thows an UnsupportedOperationException.
 int size()
          Returns the number of elements in this ComparableResultSet.
 String toString()
          Returns a string representation of the ComparableResultSet, containing a String representation of each element.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ComparableResultSet

public ComparableResultSet(ResultSet rs,
                           String columnName,
                           int startRowIndex,
                           int endRowIndex)
Constructs a new ComparableResultSet with limiting row bounds. This ComparableResultSet will make reference to the column columnName in the java.sql.ResultSet identified by rs, and will allow access to the rows startRowIndex to endRowIndex inclusive.

When accessing elements in this ComparableResultSet, the index 0 refers to the first accessible row in the result set, 1 to the second, and so on.

NOTE 1: The constructor clips startRowIndex and endRowIndex to fit the result set (and does not report this action); startRowIndex must be less than or equal to endRowIndex.

NOTE 2: This new ComparableResultSet always treats the java.sql.ResultSet as being read-only.

NOTE 3: No check is made as to whether columnName identifies a column in the java.sql.ResultSet - this check should be made elsewhere. If columnName is not valid, all access attempts will return null.

Parameters:
rs - the java.sql.ResultSet.
columnName - the String identifying the column.
startRowIndex - the int identifying the first relevant row in the java.sql.ResultSet (first position is 1).
endRowIndex - the int identifying the last relevant row in the java.sql.ResultSet.
Since:
J2SE 1.3

ComparableResultSet

public ComparableResultSet(ResultSet rs,
                           String columnName)
Constructs a new ComparableResultSet. This ComparableResultSet will make reference to the column columnName in the java.sql.ResultSet identified by rs. All rows can be accessed.

When accessing elements in this ComparableResultSet, the index 0 refers to the first accessible row in the result set, 1 to the second, and so on.

NOTE 1: This new ComparableResultSet always treats the java.sql.ResultSet as being read-only.

NOTE 2: No check is made as to whether columnName identifies a column in the java.sql.ResultSet - this check should be made elsewhere. If columnName is not valid, all access attempts will return null.

Parameters:
rs - the java.sql.ResultSet.
columnName - the String identifying the column.
Since:
J2SE 1.3
Method Detail

elements

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

Specified by:
elements in interface ComparableList
Returns:
an enumeration of the components of this ComparableResultSet.
Since:
J2SE 1.3
See Also:
Enumeration

clear

public void clear()
Does nothing.

Note that when the containing ComparableTable receives a clear(), all ComparableResultSet columns are removed.

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 index,
                      Comparable element)
               throws UnsupportedOperationException
Always thows an UnsupportedOperationException.

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

Specified by:
set in interface ComparableList
Parameters:
index - the int index of element to replace.
element - the Comparable element to be stored at the specified position.
Throws:
UnsupportedOperationException - always.
Since:
J2SE 1.3

get

public Object get(int index)
           throws ArrayIndexOutOfBoundsException
Returns the element at the specified position in this ComparableResultSet.

Specified by:
get in interface ComparableList
Parameters:
index - 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()).
Since:
J2SE 1.3

indexOf

public int indexOf(Object element)
Returns the position of the first occurance of element.

Specified by:
indexOf in interface ComparableList
Parameters:
element - the Comparable search criterion.
Returns:
the int index of the first occurance of element or -1.
Since:
J2SE 1.3

size

public int size()
Returns the number of elements in this ComparableResultSet. If there were any problems in initialising this instance, size() returns 0.

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

toString

public String toString()
Returns a string representation of the ComparableResultSet, containing a String representation of each element.

Specified by:
toString in interface ComparableList
Overrides:
toString in class Object
Returns:
a string representation of this list.
Since:
J2SE 1.3

OpMath

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