public class StringMap
extends java.util.Dictionary
StringMap
class is a substitute for the Hashtable.
The StringMap has the following properties: null
.
Constructor and Description |
---|
StringMap()
Creates an empty StringMap.
|
Modifier and Type | Method and Description |
---|---|
void |
add(java.lang.String key,
java.lang.String value)
Maps the given case-insensitive key to the specified value in this
StringMap.
|
void |
append(StringMap other,
boolean noReplace)
Append another Stringmap onto this one.
|
void |
clear()
Removes all the keys and values from this StringMap.
|
java.util.Enumeration |
elements()
Returns an enumeration of the values in this StringMap.
|
java.lang.String |
get(int index)
Returns the value at the specified index.
|
java.lang.Object |
get(java.lang.Object key)
Performs the same job as
get(String) . |
java.lang.String |
get(java.lang.String key)
Returns the value that the specified case-insensitive key maps to
in this StringMap.
|
java.lang.String |
get(java.lang.String key,
java.lang.String dflt)
Returns the value that the specified case-insensitive key maps to
in this StringMap.
|
java.lang.String |
getKey(int index)
Returns the key at the specified index.
|
boolean |
isEmpty()
Tests if there are any elements in this StringMap.
|
java.util.Enumeration |
keys()
Returns an enumeration of the keys in this StringMap.
|
void |
put(int index,
java.lang.String value)
Maps the key at the given index to the specified value in this
StringMap.
|
java.lang.Object |
put(java.lang.Object key,
java.lang.Object value)
Performs the same job as
put(String, String) . |
void |
put(java.lang.String key,
java.lang.String value)
Maps the given case-insensitive key to the specified value in this
StringMap.
|
void |
remove(int i) |
java.lang.Object |
remove(java.lang.Object key)
Performs the same job as
remove(String) . |
void |
remove(java.lang.String key)
Removes the given case-insensitive key and its corresponding value
from this StringMap.
|
int |
size()
Returns the number of elements in this StringMap.
|
java.lang.String |
toString()
Returns a string representation of this
StringMap in the
form of a set of entries, enclosed in braces and separated by the
characters ", ". |
public int size()
size
in class java.util.Dictionary
keys
public boolean isEmpty()
isEmpty
in class java.util.Dictionary
true
if there are no elements,
false
otherwise.public java.util.Enumeration keys()
The same key may appear multiple times in the enumeration, not
necessarily consecutively. Since get
always returns
the value associated with the first occurrence of a given key, a
StringMap cannot be enumerated in the same fashion as a Hashtable.
Instead, the caller should use:
Enumeration keys = map.keys(); Enumeration values = map.elements(); while (keys.hasMoreElements()) { String key = (String) keys.nextElement(); String value = (String) values.nextElement(); }or:
for (int i = 0; i < map.size(); i++) { String key = map.getKey(i); String value = map.get(i); }
keys
in class java.util.Dictionary
elements()
,
size()
,
getKey(int)
,
get(int)
public java.util.Enumeration elements()
elements
in class java.util.Dictionary
keys
public java.lang.String getKey(int index) throws java.lang.IndexOutOfBoundsException
0
to size() - 1
.
This method can be used to iterate over all the keys in this StringMap in the order in which they were inserted, subject to any intervening deletions.
index
- The index of the key.java.lang.IndexOutOfBoundsException
- if the index is out of the allowed range.public java.lang.String get(int index) throws java.lang.IndexOutOfBoundsException
0
to size() - 1
.
This method can be used to iterate over all the values in this StringMap in the order in which they were inserted, subject to any intervening deletions.
index
- The index of the key.java.lang.IndexOutOfBoundsException
- if the index is out of the allowed range.public java.lang.String get(java.lang.String key)
The same key may appear multiple times in the enumeration; this method always returns the value associated with the first occurrence of the specified key. In order to get all the values, it is necessary to iterate over the entire StringMap to retrieve all the values associated with a given key.
key
- A key in this StringMap. May not be null
.null
if the key is not in the StringMap.keys
public java.lang.String get(java.lang.String key, java.lang.String dflt)
key
- A key in this StringMap. May not be null
.dflt
- A default value if the entry for key
is not found.dflt
if the key is not in the StringMap.public java.lang.Object get(java.lang.Object key)
get(String)
. It exists so
this class can extend the Dictionary
class.get
in class java.util.Dictionary
key
- Must be a String.java.lang.ClassCastException
- if the key
is not a String.get(String)
public void put(int index, java.lang.String value)
0
to
size() - 1
.index
- The index of the key.java.lang.IndexOutOfBoundsException
- if the index is out of the allowed range.public void put(java.lang.String key, java.lang.String value)
The value can be retrieved by calling get
with a
key that is case-insensitive equal to the given key.
If this StringMap already contained a mapping for the given key, the old value is forgotten and the new specified value is used. The case of the prior key is retained in that case. Otherwise the case of the new key is used.
key
- The new key. May not be null
.value
- The new value. May be null
.public java.lang.Object put(java.lang.Object key, java.lang.Object value)
put(String, String)
. It exists
so this class can extend the Dictionary
class.put
in class java.util.Dictionary
key
- Must be a String.value
- Must be a String.key
was mapped,
or null
if the the key did not map to any
value.java.lang.ClassCastException
- if the key
or value
is not a
String.put(String, String)
public void add(java.lang.String key, java.lang.String value)
The new mapping is added to this StringMap even if the given key already has a mapping. In this way it is possible to create a key that maps to two or more values.
Since the same key may appear multiple times in this StringMap, it is necessary to iterate over the entire StringMap to retrieve all values associated with a given key.
key
- The new key. May not be null
.value
- The new value. May be null
.put(String, String)
,
keys
public void remove(java.lang.String key)
The same key may appear in multiple times in this StringMap; this method only removes the first occurrence of the key.
key
- The key that needs to be removed. Must not be
null
.public void remove(int i)
public java.lang.Object remove(java.lang.Object key)
remove(String)
. It exists so
this class can extend the Dictionary
class.remove
in class java.util.Dictionary
key
- Must be a String.null
if the key did not have a mapping.java.lang.ClassCastException
- if the key
is not a String.public void clear()
public void append(StringMap other, boolean noReplace)
other
- the map to append to this onenoReplace
- should existing values be replaced?public java.lang.String toString()
StringMap
in the
form of a set of entries, enclosed in braces and separated by the
characters ", ". Each entry is rendered as the key, an equals sign
"=", and the associated value.toString
in class java.lang.Object
StringMap
.