|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjoptsimple.AbbreviationMap
class AbbreviationMap
A map whose keys are strings; when a key/value pair is added to the map, the longest unique abbreviations of that key are added as well, and associated with the value. Thus:
abbreviations.put( "good", "bye" );
would make it such that you could retrieve the value "bye"
from the
map with the keys "good"
, "goo"
, "go"
, and
"g"
. A subsequent invocation of:
abbreviations.put( "go", "fish" );
would make it such that you could retrieve the value "bye"
using the
keys "good"
and "goo"
, and the value "fish"
with the key "go"
. The key "g"
would yield
null
, since it would no longer be a unique abbreviation.
The data structure is much like a "trie".
Field Summary | |
---|---|
private java.util.Map |
children
|
private java.lang.String |
key
|
private int |
keysBeyond
|
private java.lang.Object |
value
|
Constructor Summary | |
---|---|
AbbreviationMap()
|
Method Summary | |
---|---|
private boolean |
add(char[] chars,
java.lang.Object newValue,
int offset,
int length)
|
private void |
addToMappings(java.util.Map mappings)
|
private static char[] |
charsOf(java.lang.String aKey)
|
(package private) boolean |
contains(java.lang.String aKey)
Tells whether the given key is in the map, or whether the given key is a unique abbreviation of a key that is in the map. |
(package private) java.lang.Object |
get(java.lang.String aKey)
Answers the value associated with the given key. |
(package private) void |
put(java.lang.String aKey,
java.lang.Object newValue)
Associates a given value with a given key. |
(package private) void |
putAll(java.util.List keys,
java.lang.Object newValue)
|
private boolean |
remove(char[] aKey,
int offset,
int length)
|
(package private) void |
remove(java.lang.String aKey)
If the map contains the given key, dissociates the key from its value. |
private boolean |
removeAtEndOfKey()
|
(package private) java.util.Map |
toJavaUtilMap()
|
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
private java.lang.String key
private java.lang.Object value
private final java.util.Map children
private int keysBeyond
Constructor Detail |
---|
AbbreviationMap()
Method Detail |
---|
boolean contains(java.lang.String aKey)
Tells whether the given key is in the map, or whether the given key is a unique abbreviation of a key that is in the map.
aKey
- key to look up
true
if key
is present in the map
java.lang.NullPointerException
- if key
is null
java.lang.Object get(java.lang.String aKey)
Answers the value associated with the given key. The key can be a unique abbreviation of a key that is in the map.
aKey
- key to look up
null
if there
is no such value or aKey is not a unique abbreviation of a key in the
map
java.lang.NullPointerException
- if aKey is null
void put(java.lang.String aKey, java.lang.Object newValue)
Associates a given value with a given key. If there was a previous association, the old value is replaced with the new one.
aKey
- key to create in the mapnewValue
- value to associate with the key
java.lang.NullPointerException
- if aKey or newValue is
null
java.lang.IllegalArgumentException
- if aKey is a zero-length stringvoid putAll(java.util.List keys, java.lang.Object newValue)
private boolean add(char[] chars, java.lang.Object newValue, int offset, int length)
void remove(java.lang.String aKey)
If the map contains the given key, dissociates the key from its value.
aKey
- key to remove
java.lang.NullPointerException
- if aKey is null
java.lang.IllegalArgumentException
- if aKey is a zero-length stringprivate boolean remove(char[] aKey, int offset, int length)
private boolean removeAtEndOfKey()
java.util.Map toJavaUtilMap()
private void addToMappings(java.util.Map mappings)
private static char[] charsOf(java.lang.String aKey)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |