org.mortbay.util

Class StringMap

public class StringMap extends AbstractMap implements Externalizable

Map like class of Strings to Objects. 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.

Version: $Id: StringMap.java,v 1.13 2004/10/23 09:03:22 gregwilkins Exp $

Author: Greg Wilkins (gregw)

Field Summary
protected HashSet_entrySet
protected boolean_ignoreCase
protected StringMap.NullEntry_nullEntry
protected Object_nullValue
protected StringMap.Node_root
protected Set_umEntrySet
protected int_width
Constructor Summary
StringMap()
Constructor.
StringMap(boolean ignoreCase)
Constructor.
StringMap(boolean ignoreCase, int width)
Constructor.
Method Summary
voidclear()
booleancontainsKey(Object key)
SetentrySet()
Objectget(Object key)
Objectget(String key)
EntrygetEntry(String key, int offset, int length)
Get a map entry by substring key.
EntrygetEntry(char[] key, int offset, int length)
Get a map entry by char array key.
EntrygetEntry(byte[] key, int offset, int length)
Get a map entry by byte array key.
intgetWidth()
booleanisEmpty()
booleanisIgnoreCase()
Objectput(Object key, Object value)
Objectput(String key, Object value)
voidreadExternal(ObjectInput in)
Objectremove(Object key)
Objectremove(String key)
voidsetIgnoreCase(boolean ic)
Set the ignoreCase attribute.
voidsetWidth(int width)
Set the hash width.
intsize()
voidwriteExternal(ObjectOutput out)

Field Detail

_entrySet

protected HashSet _entrySet

_ignoreCase

protected boolean _ignoreCase

_nullEntry

protected StringMap.NullEntry _nullEntry

_nullValue

protected Object _nullValue

_root

protected StringMap.Node _root

_umEntrySet

protected Set _umEntrySet

_width

protected int _width

Constructor Detail

StringMap

public StringMap()
Constructor.

StringMap

public StringMap(boolean ignoreCase)
Constructor.

Parameters: ignoreCase

StringMap

public StringMap(boolean ignoreCase, int width)
Constructor.

Parameters: ignoreCase width Width of hash tables, larger values are faster but use more memory.

Method Detail

clear

public void clear()

containsKey

public boolean containsKey(Object key)

entrySet

public Set entrySet()

get

public Object get(Object key)

get

public Object get(String key)

getEntry

public Entry getEntry(String key, int offset, int length)
Get a map entry by substring key.

Parameters: key String containing the key offset Offset of the key within the String. length The length of the key

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

getEntry

public Entry getEntry(char[] key, int offset, int length)
Get a map entry by char array key.

Parameters: key char array containing the key offset Offset of the key within the array. length The length of the key

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

getEntry

public Entry getEntry(byte[] key, int offset, int length)
Get a map entry by byte array key.

Parameters: key byte array containing the key. A simple ASCII byte to char mapping is used. offset Offset of the key within the array. length The length of the key

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

getWidth

public int getWidth()

isEmpty

public boolean isEmpty()

isIgnoreCase

public boolean isIgnoreCase()

put

public Object put(Object key, Object value)

put

public Object put(String key, Object value)

readExternal

public void readExternal(ObjectInput in)

remove

public Object remove(Object key)

remove

public Object remove(String key)

setIgnoreCase

public void setIgnoreCase(boolean ic)
Set the ignoreCase attribute.

Parameters: ic If true, the map is case insensitive for keys.

setWidth

public void setWidth(int width)
Set the hash width.

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

size

public int size()

writeExternal

public void writeExternal(ObjectOutput out)
Copyright © 2004 Mortbay Consulting Pty. Ltd. All Rights Reserved.