Top Description Inners Fields Constructors Methods
org.mortbay.util

public Class StringMap

extends AbstractMap
implements Externalizable
Class Inheritance
All Implemented Interfaces
java.io.Externalizable, java.io.Serializable
Imports
java.io.Externalizable, java.util.AbstractMap, .Collections, .HashMap, .HashSet, .Map, .Set

Map implementation Optimized for Strings keys.. This String Map has been optimized for mapping small sets of Strings where the most frequently accessed Strings have been put to the map first. It also has the benefit that it can look up entries by substring or sections of char and byte arrays. This can prevent many String objects from being created just to look up in the map. This map is NOT synchronized.
Author
Greg Wilkins (gregw)

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
private class

Field Summary

Modifier and TypeField and Description
protected static final int
protected HashSet<E>
protected boolean
protected StringMap.NullEntry
protected Object
protected StringMap.Node
protected Set<E>
protected int
public static final boolean

Constructor Summary

AccessConstructor and Description
public
StringMap()

Constructor.

public
StringMap(boolean ignoreCase)

Constructor.

public
StringMap(boolean ignoreCase, int
Width of hash tables, larger values are faster but use more memory.
width
)

Constructor.

Method Summary

Modifier and TypeMethod and Description
public void
clear()

Overrides java.util.AbstractMap.clear.

Implements java.util.Map.clear.

Removes all of the mappings from this map (optional operation).
public boolean
containsKey(Object
key whose presence in this map is to be tested
key
)

Overrides java.util.AbstractMap.containsKey.

Implements java.util.Map.containsKey.

Returns true if this map contains a mapping for the specified key.
public Set<E>
entrySet()

Implements abstract java.util.AbstractMap.entrySet.

Implements java.util.Map.entrySet.

Returns a Set view of the mappings contained in this map.
public Object
get(Object
the key whose associated value is to be returned
key
)

Overrides java.util.AbstractMap.get.

Implements java.util.Map.get.

Returns the value to which the specified key is mapped, or null if this map contains no mapping for the key.
public Object
get(String key)

public Map.Entry<K, V>

Returns:

The Map.Entry for the key or null if the key is not in the map.
getBestEntry
(byte[]
char array containing the key
key
,
int
Offset of the key within the array.
offset
,
int
The length of the key
maxLength
)

Get a map entry by byte array key, using as much of the passed key as needed for a match.

public Map.Entry<K, V>

Returns:

The Map.Entry for the key or null if the key is not in the map.
getEntry
(String
String containing the key
key
,
int
Offset of the key within the String.
offset
,
int
The length of the key
length
)

Get a map entry by substring key.

public Map.Entry<K, V>

Returns:

The Map.Entry for the key or null if the key is not in the map.
getEntry
(char[]
char array containing the key
key
,
int
Offset of the key within the array.
offset
,
int
The length of the key
length
)

Get a map entry by char array key.

public int
public boolean
isEmpty()

Overrides java.util.AbstractMap.isEmpty.

Implements java.util.Map.isEmpty.

Returns true if this map contains no key-value mappings.
public boolean
public Object
put(Object
key with which the specified value is to be associated
key
,
Object
value to be associated with the specified key
value
)

Overrides java.util.AbstractMap.put.

Implements java.util.Map.put.

Associates the specified value with the specified key in this map (optional operation).
public Object
put(String
key with which the specified value is to be associated
key
,
Object
value to be associated with the specified key
value
)

Overrides java.util.AbstractMap.put.

Implements java.util.Map.put.

Associates the specified value with the specified key in this map (optional operation).
public void
readExternal(ObjectInput
the stream to read data from in order to restore the object
in
)

Implements java.io.Externalizable.readExternal.

The object implements the readExternal method to restore its contents by calling the methods of DataInput for primitive types and readObject for objects, strings and arrays.
public Object
remove(Object
key whose mapping is to be removed from the map
key
)

Overrides java.util.AbstractMap.remove.

Implements java.util.Map.remove.

Removes the mapping for a key from this map if it is present (optional operation).
public Object
public void
setIgnoreCase(boolean
If true, the map is case insensitive for keys.
ic
)

Set the ignoreCase attribute.

public void
setWidth(int
Width of hash tables, larger values are faster but use more memory.
width
)

Set the hash width.

public int
size()

Overrides java.util.AbstractMap.size.

Implements java.util.Map.size.

Returns the number of key-value mappings in this map.
public void
writeExternal(ObjectOutput
the stream to write the object to
out
)

Implements java.io.Externalizable.writeExternal.

The object implements the writeExternal method to save its contents by calling the methods of DataOutput for its primitive values or calling the writeObject method of ObjectOutput for objects, strings, and arrays.
Inherited from java.util.AbstractMap:
clonecontainsValueequalshashCodekeySetputAlltoStringvalues

Field Detail

__HASH_WIDTHback to summary
protected static final int __HASH_WIDTH
_entrySetback to summary
protected HashSet<E> _entrySet
_ignoreCaseback to summary
protected boolean _ignoreCase
_nullEntryback to summary
protected StringMap.NullEntry _nullEntry
_nullValueback to summary
protected Object _nullValue
_rootback to summary
protected StringMap.Node _root
_umEntrySetback to summary
protected Set<E> _umEntrySet
_widthback to summary
protected int _width
CASE_INSENSTIVEback to summary
public static final boolean CASE_INSENSTIVE

Constructor Detail

StringMapback to summary
public StringMap()

Constructor.

StringMapback to summary
public StringMap(boolean ignoreCase)

Constructor.

StringMapback to summary
public StringMap(boolean ignoreCase, int width)

Constructor.

Parameters
width:int

Width of hash tables, larger values are faster but use more memory.

Method Detail

clearback to summary
public void clear()

Overrides java.util.AbstractMap.clear.

Implements java.util.Map.clear.

Doc from java.util.AbstractMap.clear.

Removes all of the mappings from this map (optional operation). The map will be empty after this call returns.

containsKeyback to summary
public boolean containsKey(Object key)

Overrides java.util.AbstractMap.containsKey.

Implements java.util.Map.containsKey.

Doc from java.util.AbstractMap.containsKey.

Returns true if this map contains a mapping for the specified key. More formally, returns true if and only if this map contains a mapping for a key k such that Objects.equals(key, k). (There can be at most one such mapping.)

Parameters
key:Object

Doc from java.util.Map.containsKey.

key whose presence in this map is to be tested

Returns:boolean

Doc from java.util.Map.containsKey.

true if this map contains a mapping for the specified key

entrySetback to summary
public Set<E> entrySet()

Implements abstract java.util.AbstractMap.entrySet.

Implements java.util.Map.entrySet.

Doc from java.util.Map.entrySet.

Returns a Set view of the mappings contained in this map. The set is backed by the map, so changes to the map are reflected in the set, and vice-versa. If the map is modified while an iteration over the set is in progress (except through the iterator's own remove operation, or through the setValue operation on a map entry returned by the iterator) the results of the iteration are undefined. The set supports element removal, which removes the corresponding mapping from the map, via the Iterator.remove, Set.remove, removeAll, retainAll and clear operations. It does not support the add or addAll operations.

Returns:Set<E>

a set view of the mappings contained in this map

getback to summary
public Object get(Object key)

Overrides java.util.AbstractMap.get.

Implements java.util.Map.get.

Doc from java.util.AbstractMap.get.

Returns the value to which the specified key is mapped, or null if this map contains no mapping for the key.

More formally, if this map contains a mapping from a key k to a value v such that Objects.equals(key, k), then this method returns v; otherwise it returns null. (There can be at most one such mapping.)

If this map permits null values, then a return value of null does not necessarily indicate that the map contains no mapping for the key; it's also possible that the map explicitly maps the key to null. The containsKey operation may be used to distinguish these two cases.

Parameters
key:Object

Doc from java.util.Map.get.

the key whose associated value is to be returned

Returns:Object

Doc from java.util.Map.get.

the value to which the specified key is mapped, or null if this map contains no mapping for the key

getback to summary
public Object get(String key)
getBestEntryback to summary
public Map.Entry<K, V> getBestEntry(byte[] key, int offset, int maxLength)

Get a map entry by byte array key, using as much of the passed key as needed for a match. A simple 8859-1 byte to char mapping is assumed.

Parameters
key:byte[]

char array containing the key

offset:int

Offset of the key within the array.

maxLength:int

The length of the key

Returns:Map.Entry<K, V>

The Map.Entry for the key or null if the key is not in the map.

getEntryback to summary
public Map.Entry<K, V> getEntry(String key, int offset, int length)

Get a map entry by substring key.

Parameters
key:String

String containing the key

offset:int

Offset of the key within the String.

length:int

The length of the key

Returns:Map.Entry<K, V>

The Map.Entry for the key or null if the key is not in the map.

getEntryback to summary
public Map.Entry<K, V> getEntry(char[] key, int offset, int length)

Get a map entry by char array key.

Parameters
key:char[]

char array containing the key

offset:int

Offset of the key within the array.

length:int

The length of the key

Returns:Map.Entry<K, V>

The Map.Entry for the key or null if the key is not in the map.

getWidthback to summary
public int getWidth()
isEmptyback to summary
public boolean isEmpty()

Overrides java.util.AbstractMap.isEmpty.

Implements java.util.Map.isEmpty.

Doc from java.util.AbstractMap.isEmpty.

Returns true if this map contains no key-value mappings.

Returns:boolean

Doc from java.util.Map.isEmpty.

true if this map contains no key-value mappings

isIgnoreCaseback to summary
public boolean isIgnoreCase()
putback to summary
public Object put(Object key, Object value)

Overrides java.util.AbstractMap.put.

Implements java.util.Map.put.

Doc from java.util.AbstractMap.put.

Associates the specified value with the specified key in this map (optional operation). If the map previously contained a mapping for the key, the old value is replaced by the specified value. (A map m is said to contain a mapping for a key k if and only if m.containsKey(k) would return true.)

Parameters
key:Object

Doc from java.util.Map.put.

key with which the specified value is to be associated

value:Object

Doc from java.util.Map.put.

value to be associated with the specified key

Returns:Object

Doc from java.util.Map.put.

the previous value associated with key, or null if there was no mapping for key. (A null return can also indicate that the map previously associated null with key, if the implementation supports null values.)

putback to summary
public Object put(String key, Object value)

Overrides java.util.AbstractMap.put.

Implements java.util.Map.put.

Doc from java.util.AbstractMap.put.

Associates the specified value with the specified key in this map (optional operation). If the map previously contained a mapping for the key, the old value is replaced by the specified value. (A map m is said to contain a mapping for a key k if and only if m.containsKey(k) would return true.)

Parameters
key:String

Doc from java.util.Map.put.

key with which the specified value is to be associated

value:Object

Doc from java.util.Map.put.

value to be associated with the specified key

Returns:Object

Doc from java.util.Map.put.

the previous value associated with key, or null if there was no mapping for key. (A null return can also indicate that the map previously associated null with key, if the implementation supports null values.)

readExternalback to summary
public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException

Implements java.io.Externalizable.readExternal.

Doc from java.io.Externalizable.readExternal.

The object implements the readExternal method to restore its contents by calling the methods of DataInput for primitive types and readObject for objects, strings and arrays. The readExternal method must read the values in the same sequence and with the same types as were written by writeExternal.

Parameters
in:ObjectInput

the stream to read data from in order to restore the object

Exceptions
IOException:
if I/O errors occur
ClassNotFoundException:
If the class for an object being restored cannot be found.
removeback to summary
public Object remove(Object key)

Overrides java.util.AbstractMap.remove.

Implements java.util.Map.remove.

Doc from java.util.AbstractMap.remove.

Removes the mapping for a key from this map if it is present (optional operation). More formally, if this map contains a mapping from key k to value v such that Objects.equals(key, k), that mapping is removed. (The map can contain at most one such mapping.)

Returns the value to which this map previously associated the key, or null if the map contained no mapping for the key.

If this map permits null values, then a return value of null does not necessarily indicate that the map contained no mapping for the key; it's also possible that the map explicitly mapped the key to null.

The map will not contain a mapping for the specified key once the call returns.

Parameters
key:Object

Doc from java.util.Map.remove.

key whose mapping is to be removed from the map

Returns:Object

Doc from java.util.Map.remove.

the previous value associated with key, or null if there was no mapping for key.

removeback to summary
public Object remove(String key)
setIgnoreCaseback to summary
public void setIgnoreCase(boolean ic)

Set the ignoreCase attribute.

Parameters
ic:boolean

If true, the map is case insensitive for keys.

setWidthback to summary
public void setWidth(int width)

Set the hash width.

Parameters
width:int

Width of hash tables, larger values are faster but use more memory.

sizeback to summary
public int size()

Overrides java.util.AbstractMap.size.

Implements java.util.Map.size.

Doc from java.util.AbstractMap.size.

Returns the number of key-value mappings in this map. If the map contains more than Integer.MAX_VALUE elements, returns Integer.MAX_VALUE.

Returns:int

Doc from java.util.Map.size.

the number of key-value mappings in this map

writeExternalback to summary
public void writeExternal(ObjectOutput out) throws IOException

Implements java.io.Externalizable.writeExternal.

Doc from java.io.Externalizable.writeExternal.

The object implements the writeExternal method to save its contents by calling the methods of DataOutput for its primitive values or calling the writeObject method of ObjectOutput for objects, strings, and arrays.

Parameters
out:ObjectOutput

the stream to write the object to

Exceptions
IOException:
Includes any I/O exceptions that may occur
org.mortbay.util back to summary

private Class StringMap.Node

extends Object
implements Entry
Class Inheritance
All Implemented Interfaces
java.util.Map.Entry

Field Summary

Modifier and TypeField and Description
pack-priv char[]
pack-priv StringMap.Node[]
pack-priv String
pack-priv StringMap.Node
pack-priv char[]
pack-priv Object

Constructor Summary

AccessConstructor and Description
pack-priv
Node()

pack-priv
Node(boolean ignoreCase, String s, int offset)

Method Summary

Modifier and TypeMethod and Description
public Object
getKey()

Implements java.util.Map.Entry.getKey.

Returns the key corresponding to this entry.
public Object
getValue()

Implements java.util.Map.Entry.getValue.

Returns the value corresponding to this entry.
public Object
setValue(Object
new value to be stored in this entry
o
)

Implements java.util.Map.Entry.setValue.

Replaces the value corresponding to this entry with the specified value (optional operation).
pack-priv StringMap.Node
split(StringMap map, int offset)

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.
private void
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

_charback to summary
pack-priv char[] _char
_childrenback to summary
pack-priv StringMap.Node[] _children
_keyback to summary
pack-priv String _key
_nextback to summary
pack-priv StringMap.Node _next
_ocharback to summary
pack-priv char[] _ochar
_valueback to summary
pack-priv Object _value

Constructor Detail

Nodeback to summary
pack-priv Node()
Nodeback to summary
pack-priv Node(boolean ignoreCase, String s, int offset)

Method Detail

getKeyback to summary
public Object getKey()

Implements java.util.Map.Entry.getKey.

Doc from java.util.Map.Entry.getKey.

Returns the key corresponding to this entry.

Returns:Object

the key corresponding to this entry

getValueback to summary
public Object getValue()

Implements java.util.Map.Entry.getValue.

Doc from java.util.Map.Entry.getValue.

Returns the value corresponding to this entry. If the mapping has been removed from the backing map (by the iterator's remove operation), the results of this call are undefined.

Returns:Object

the value corresponding to this entry

setValueback to summary
public Object setValue(Object o)

Implements java.util.Map.Entry.setValue.

Doc from java.util.Map.Entry.setValue.

Replaces the value corresponding to this entry with the specified value (optional operation). (Writes through to the map.) The behavior of this call is undefined if the mapping has already been removed from the map (by the iterator's remove operation).

Parameters
o:Object

new value to be stored in this entry

Returns:Object

old value corresponding to the entry

splitback to summary
pack-priv StringMap.Node split(StringMap map, int offset)
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object.

Returns:String

a string representation of the object

toStringback to summary
private void toString(StringBuilder buf)
org.mortbay.util back to summary

private Class StringMap.NullEntry

extends Object
implements Entry
Class Inheritance
All Implemented Interfaces
java.util.Map.Entry

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public Object
getKey()

Implements java.util.Map.Entry.getKey.

Returns the key corresponding to this entry.
public Object
getValue()

Implements java.util.Map.Entry.getValue.

Returns the value corresponding to this entry.
public Object
setValue(Object
new value to be stored in this entry
o
)

Implements java.util.Map.Entry.setValue.

Replaces the value corresponding to this entry with the specified value (optional operation).
public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Constructor Detail

NullEntryback to summary
private NullEntry()

Method Detail

getKeyback to summary
public Object getKey()

Implements java.util.Map.Entry.getKey.

Doc from java.util.Map.Entry.getKey.

Returns the key corresponding to this entry.

Returns:Object

the key corresponding to this entry

getValueback to summary
public Object getValue()

Implements java.util.Map.Entry.getValue.

Doc from java.util.Map.Entry.getValue.

Returns the value corresponding to this entry. If the mapping has been removed from the backing map (by the iterator's remove operation), the results of this call are undefined.

Returns:Object

the value corresponding to this entry

setValueback to summary
public Object setValue(Object o)

Implements java.util.Map.Entry.setValue.

Doc from java.util.Map.Entry.setValue.

Replaces the value corresponding to this entry with the specified value (optional operation). (Writes through to the map.) The behavior of this call is undefined if the mapping has already been removed from the map (by the iterator's remove operation).

Parameters
o:Object

new value to be stored in this entry

Returns:Object

old value corresponding to the entry

toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object.

Returns:String

a string representation of the object