applicationLogic.utility
Class KeyValuePair

java.lang.Object
  extended by applicationLogic.utility.KeyValuePair

public class KeyValuePair
extends java.lang.Object

KeyValuePair stores keys and 1 or more sets of values.

Author:
gerald

Constructor Summary
KeyValuePair(java.lang.String[] keys, java.sql.ResultSet rs)
          Takes each row of a ResultSet and initializes 'keys', 'dataTypes' and 'data' so that each row in 'data' contains the values such that the jth element of the ith row is the value of the ith row corresponding to the jth key.
KeyValuePair(java.lang.String[] keys, java.lang.String[] dataTypes, java.util.List<java.lang.String[]> data, byte[] binaryData)
          Initializes variables in KeyValuePair.
 
Method Summary
 byte[] getBinaryData()
          Get the binary data stored in this KeyValuePair object.
 java.lang.String[] getDataTypes()
          Get the data types of the keys of this KeyValuePair object.
 java.lang.String[] getKeys()
          Get the keys of this KeyValuePair object.
 int getRowCount()
          Get the number of rows in the 'data' List.
 java.util.List getValues()
          Get the values of this KeyValuePair object.
 java.lang.String[] getValuesByKeyIndex(int index)
          Get the values of the 'index' column of each row in 'data'.
 java.lang.String[] getValuesByKeyName(java.lang.String keyName)
          Get the values from 'data' corresponding to the key 'keyName' in 'keys'.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

KeyValuePair

public KeyValuePair(java.lang.String[] keys,
                    java.sql.ResultSet rs)
             throws java.sql.SQLException
Takes each row of a ResultSet and initializes 'keys', 'dataTypes' and 'data' so that each row in 'data' contains the values such that the jth element of the ith row is the value of the ith row corresponding to the jth key. If 'rs' is null, this object variables are left as null. eg) 'value11' is the value corresponding to key 'key1', and there are n sets of values. Key 'key1' is a string. keys = ['key1', 'key2', ...], dataTypes = ['String', 'int', ...], data = [ ['value11', 'value12', ...], ['value21', 'value22', ...], ... ['valuen1', 'valuen2', ...] ]

Parameters:
keys - The names of the key value pairs.
rs - The ResultSet containing the values.
Throws:
java.sql.SQLException

KeyValuePair

public KeyValuePair(java.lang.String[] keys,
                    java.lang.String[] dataTypes,
                    java.util.List<java.lang.String[]> data,
                    byte[] binaryData)
Initializes variables in KeyValuePair. Does not query the database. This method is useful for debugging.

Parameters:
keys - The names of the key value pairs.
dataTypes - An array of String containing the data type of each element in 'keys'. Possible values include "string", "int", "float", "date", "binary", "time".
data - A list containing one or more rows of values corresponding to the keys. Each row is an array of strings.
binaryData - Binary data associated with 'keys', where 'keys' contains exactly one key.
Method Detail

getKeys

public java.lang.String[] getKeys()
Get the keys of this KeyValuePair object.

Returns:
An array of strings representing the keys of this KeyValuePair object.

getDataTypes

public java.lang.String[] getDataTypes()
Get the data types of the keys of this KeyValuePair object.

Returns:
An array of strings containing the data types of the keys of this KeyValuePair object.

getBinaryData

public byte[] getBinaryData()
Get the binary data stored in this KeyValuePair object.

Returns:
a BufferedReader for the binary data stored in this object.

getValues

public java.util.List getValues()
Get the values of this KeyValuePair object.

Returns:
A List containing arrays, where each array contains the values of this KeyValuePair object.

getValuesByKeyName

public java.lang.String[] getValuesByKeyName(java.lang.String keyName)
Get the values from 'data' corresponding to the key 'keyName' in 'keys'.

Parameters:
keyName - Name of key in 'keys'.
Returns:
A String array containing the values from 'data' corresponding to the key 'keyName' in 'keys'. Null if keyName is not found in 'keys' or if 'data' is null.

getValuesByKeyIndex

public java.lang.String[] getValuesByKeyIndex(int index)
Get the values of the 'index' column of each row in 'data'.

Parameters:
index -
Returns:
A String array where each element is the value of the 'index' column of 'data'. Null, if index is out of bounds.

getRowCount

public int getRowCount()
Get the number of rows in the 'data' List.

Returns:
The number of rows, as an int, in the 'data' List.