Top Description Fields Constructors Methods
joptsimple.internal

public Class AbbreviationMap<V>

extends Object
implements OptionNameMap<V>
Class Inheritance
All Implemented Interfaces
joptsimple.internal.OptionNameMap
Type Parameters
<V>
a constraint on the types of the values in the map
Imports
java.util.Map, .TreeMap

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 using 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" using 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".

Author
Paul Holser
See Also
Perl's Text::Abbrev module, Radix tree

Field Summary

Modifier and TypeField and Description
private final Map<Character, AbbreviationMap<V>>
private String
private int
private V

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
private boolean
add(char[] chars, V newValue, int offset, int length)

private void
addToMappings(Map<String, V> mappings)

private static char[]
public boolean

Returns:

true if key is present in the map
contains
(String
key to look up
key
)

Implements joptsimple.internal.OptionNameMap.contains.

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.

public V

Returns:

the value associated with aKey; or null if there is no such value or aKey is not a unique abbreviation of a key in the map
get
(String
key to look up
key
)

Implements joptsimple.internal.OptionNameMap.get.

Answers the value associated with the given key.

public void
put(String
key to create in the map
key
,
V
value to associate with the key
newValue
)

Implements joptsimple.internal.OptionNameMap.put.

Associates a given value with a given key.

public void
putAll(Iterable<String>
keys to create in the map
keys
,
V
value to associate with the key
newValue
)

Implements joptsimple.internal.OptionNameMap.putAll.

Associates a given value with a given set of keys.

public void
remove(String
key to remove
key
)

Implements joptsimple.internal.OptionNameMap.remove.

If the map contains the given key, dissociates the key from its value.

private boolean
remove(char[] aKey, int offset, int length)

private boolean
private void
public Map<String, V>

Returns:

a Java map corresponding to this abbreviation map
toJavaUtilMap
()

Implements joptsimple.internal.OptionNameMap.toJavaUtilMap.

Gives a Java map representation of this abbreviation map.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

childrenback to summary
private final Map<Character, AbbreviationMap<V>> children
keyback to summary
private String key
keysBeyondback to summary
private int keysBeyond
valueback to summary
private V value

Constructor Detail

AbbreviationMapback to summary
public AbbreviationMap()

Method Detail

addback to summary
private boolean add(char[] chars, V newValue, int offset, int length)
addToMappingsback to summary
private void addToMappings(Map<String, V> mappings)
charsOfback to summary
private static char[] charsOf(String aKey)
containsback to summary
public boolean contains(String key)

Implements joptsimple.internal.OptionNameMap.contains.

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.

Parameters
key:String

key to look up

Returns:boolean

true if key is present in the map

Annotations
@Override
Exceptions
NullPointerException:
if key is null
getback to summary
public V get(String key)

Implements joptsimple.internal.OptionNameMap.get.

Answers the value associated with the given key. The key can be a unique abbreviation of a key that is in the map.

Parameters
key:String

key to look up

Returns:V

the value associated with aKey; or null if there is no such value or aKey is not a unique abbreviation of a key in the map

Annotations
@Override
Exceptions
NullPointerException:
if aKey is null
putback to summary
public void put(String key, V newValue)

Implements joptsimple.internal.OptionNameMap.put.

Associates a given value with a given key. If there was a previous association, the old value is replaced with the new one.

Parameters
key:String

key to create in the map

newValue:V

value to associate with the key

Annotations
@Override
Exceptions
NullPointerException:
if aKey or newValue is null
IllegalArgumentException:
if aKey is a zero-length string
putAllback to summary
public void putAll(Iterable<String> keys, V newValue)

Implements joptsimple.internal.OptionNameMap.putAll.

Associates a given value with a given set of keys. If there was a previous association, the old value is replaced with the new one.

Parameters
keys:Iterable<String>

keys to create in the map

newValue:V

value to associate with the key

Annotations
@Override
Exceptions
NullPointerException:
if keys or newValue is null
IllegalArgumentException:
if any of keys is a zero-length string
removeback to summary
public void remove(String key)

Implements joptsimple.internal.OptionNameMap.remove.

If the map contains the given key, dissociates the key from its value.

Parameters
key:String

key to remove

Annotations
@Override
Exceptions
NullPointerException:
if aKey is null
IllegalArgumentException:
if aKey is a zero-length string
removeback to summary
private boolean remove(char[] aKey, int offset, int length)
removeAtEndOfKeyback to summary
private boolean removeAtEndOfKey()
setValueToThatOfOnlyChildback to summary
private void setValueToThatOfOnlyChild()
toJavaUtilMapback to summary
public Map<String, V> toJavaUtilMap()

Implements joptsimple.internal.OptionNameMap.toJavaUtilMap.

Gives a Java map representation of this abbreviation map.

Returns:Map<String, V>

a Java map corresponding to this abbreviation map

Annotations
@Override