voji.utils
Class VChoice

java.lang.Object
  |
  +--voji.utils.VChoice

public class VChoice
extends java.lang.Object

This class facilates implementing a choice for the user. There are methods for mapping between names, values and indices.


Field Summary
protected  java.util.Vector data
          A Vector of (name,value) pairs containing the data
protected  int defIndex
          The default index.
 
Constructor Summary
VChoice()
          Creates a new VChoice instance without data
VChoice(java.lang.Object[] data)
          Creates a new VChoice instance with initial data
 
Method Summary
 void add(java.lang.Object name, java.lang.Object value)
          Adds an entry
 void clear()
          Removes all entries
 java.lang.Object[] elements()
          Returns an Array for Lists and ComboBoxes
 java.lang.Object i2v(int index)
          Returns the value of an index
 void setData(java.util.Iterator data)
          Sets the data of this instance
 void setData(java.sql.ResultSet data)
          Sets the data of this instance
 int v2i(java.lang.Object value)
          Returns the index of a value
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

data

protected java.util.Vector data
A Vector of (name,value) pairs containing the data


defIndex

protected int defIndex
The default index. Usually, it's -1, but it can be overwritten by using a null value.

Constructor Detail

VChoice

public VChoice(java.lang.Object[] data)
Creates a new VChoice instance with initial data

Parameters:
data - an array of name-value-name-value-...

VChoice

public VChoice()
Creates a new VChoice instance without data

Method Detail

clear

public void clear()
Removes all entries


add

public void add(java.lang.Object name,
                java.lang.Object value)
Adds an entry

Parameters:
name - key of the entry (for elements())
value - value of the entry (for i2v and v2i)

setData

public void setData(java.util.Iterator data)
Sets the data of this instance

Parameters:
data - an Iterator of name-value-name-value-...

setData

public void setData(java.sql.ResultSet data)
             throws java.sql.SQLException
Sets the data of this instance

Parameters:
data - an ResultSet of (name;value)
Throws:
java.sql.SQLException - if there is an SQLException while working with the ResultSet

v2i

public int v2i(java.lang.Object value)
Returns the index of a value

Parameters:
value - the value that has to be looked for
Returns:
the corresponding index or the default index if the value wasn't found

i2v

public java.lang.Object i2v(int index)
Returns the value of an index

Parameters:
index - the index where to look at
Returns:
the corresponding value

elements

public java.lang.Object[] elements()
Returns an Array for Lists and ComboBoxes

Returns:
an Array containing all names