|
Sharkysoft home | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--lava.util.NumberedStrings
An instance of NumberedStrings
is a mapping between integers and strings. After construction, the mapping is initially empty. Pairs are registered into the mapping by repeated calls to register
.
After all pairs have been registered, the mapping can be queried by calls to toInt(String)
and toString(int)
.
If register is called using integer and string values that have already been used in previous calls to register, then the last association takes priority. For example, if you register (3, "strikes") and (3, "wishes"), in that order, then 3 will map to "wishes" and not "strikes". However, both "strikes" and "wishes" will still map to 3.
Field Summary | |
protected java.lang.Integer |
failure_value
The default Integer object to return when a String lookup fails. |
protected java.util.Hashtable |
table
Storage for number-string pairs. |
Constructor Summary | |
NumberedStrings()
Creates an empty assocation. |
Method Summary | |
void |
register(int i,
java.lang.String s)
Registers an integer-string pair into this instance. |
int |
toInt(java.lang.String s)
Returns the integer that has been registered in association with the given string. |
java.lang.String |
toString(int i)
Returns the string that has been registered in association with the given integer. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
protected java.lang.Integer failure_value
Details: Normally, when a call to toInt fails to find an int associated with the supplied string, a NoSuchElementException is thrown. However, if this member is set (to non-null), the int value of this Integer object will be returned instead, and no exception will be thrown. This makes it possible to supply a default value for failed lookups.
protected java.util.Hashtable table
Constructor Detail |
public NumberedStrings()
register
.Method Detail |
public void register(int i, java.lang.String s)
i
- the integers
- the stringpublic int toInt(java.lang.String s) throws java.util.NoSuchElementException
s
- the stringjava.util.NoSuchElementException
- if the string has not been registered with an integerpublic java.lang.String toString(int i) throws java.util.NoSuchElementException
i
- the integerjava.util.NoSuchElementException
- if the integer has not been registered with a string
|
Sharkysoft home | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |