org.mortbay.util
Class StringMap

java.lang.Object
  extended by java.util.AbstractMap
      extended by org.mortbay.util.StringMap
All Implemented Interfaces:
java.io.Externalizable, java.io.Serializable, java.util.Map

public class StringMap
extends java.util.AbstractMap
implements java.io.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)
See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from interface java.util.Map
java.util.Map.Entry<K,V>
 
Field Summary
protected  java.util.HashSet _entrySet
           
protected  boolean _ignoreCase
           
protected  org.mortbay.util.StringMap.NullEntry _nullEntry
           
protected  java.lang.Object _nullValue
           
protected  org.mortbay.util.StringMap.Node _root
           
protected  java.util.Set _umEntrySet
           
protected  int _width
           
 
Constructor Summary
StringMap()
          Constructor.
StringMap(boolean ignoreCase)
          Constructor.
StringMap(boolean ignoreCase, int width)
          Constructor.
 
Method Summary
 void clear()
           
 boolean containsKey(java.lang.Object key)
           
 java.util.Set entrySet()
           
 java.lang.Object get(java.lang.Object key)
           
 java.lang.Object get(java.lang.String key)
           
 java.util.Map.Entry getEntry(byte[] key, int offset, int length)
          Get a map entry by byte array key.
 java.util.Map.Entry getEntry(char[] key, int offset, int length)
          Get a map entry by char array key.
 java.util.Map.Entry getEntry(java.lang.String key, int offset, int length)
          Get a map entry by substring key.
 int getWidth()
           
 boolean isEmpty()
           
 boolean isIgnoreCase()
           
 java.lang.Object put(java.lang.Object key, java.lang.Object value)
           
 java.lang.Object put(java.lang.String key, java.lang.Object value)
           
 void readExternal(java.io.ObjectInput in)
           
 java.lang.Object remove(java.lang.Object key)
           
 java.lang.Object remove(java.lang.String key)
           
 void setIgnoreCase(boolean ic)
          Set the ignoreCase attribute.
 void setWidth(int width)
          Set the hash width.
 int size()
           
 void writeExternal(java.io.ObjectOutput out)
           
 
Methods inherited from class java.util.AbstractMap
clone, containsValue, equals, hashCode, keySet, putAll, toString, values
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

_width

protected int _width

_root

protected org.mortbay.util.StringMap.Node _root

_ignoreCase

protected boolean _ignoreCase

_nullEntry

protected org.mortbay.util.StringMap.NullEntry _nullEntry

_nullValue

protected java.lang.Object _nullValue

_entrySet

protected java.util.HashSet _entrySet

_umEntrySet

protected java.util.Set _umEntrySet
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

setIgnoreCase

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

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

isIgnoreCase

public boolean isIgnoreCase()

setWidth

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

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

getWidth

public int getWidth()

put

public java.lang.Object put(java.lang.Object key,
                            java.lang.Object value)
Specified by:
put in interface java.util.Map
Overrides:
put in class java.util.AbstractMap

put

public java.lang.Object put(java.lang.String key,
                            java.lang.Object value)

get

public java.lang.Object get(java.lang.Object key)
Specified by:
get in interface java.util.Map
Overrides:
get in class java.util.AbstractMap

get

public java.lang.Object get(java.lang.String key)

getEntry

public java.util.Map.Entry getEntry(java.lang.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 java.util.Map.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 java.util.Map.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.

remove

public java.lang.Object remove(java.lang.Object key)
Specified by:
remove in interface java.util.Map
Overrides:
remove in class java.util.AbstractMap

remove

public java.lang.Object remove(java.lang.String key)

entrySet

public java.util.Set entrySet()
Specified by:
entrySet in interface java.util.Map
Specified by:
entrySet in class java.util.AbstractMap

size

public int size()
Specified by:
size in interface java.util.Map
Overrides:
size in class java.util.AbstractMap

isEmpty

public boolean isEmpty()
Specified by:
isEmpty in interface java.util.Map
Overrides:
isEmpty in class java.util.AbstractMap

containsKey

public boolean containsKey(java.lang.Object key)
Specified by:
containsKey in interface java.util.Map
Overrides:
containsKey in class java.util.AbstractMap

clear

public void clear()
Specified by:
clear in interface java.util.Map
Overrides:
clear in class java.util.AbstractMap

writeExternal

public void writeExternal(java.io.ObjectOutput out)
                   throws java.io.IOException
Specified by:
writeExternal in interface java.io.Externalizable
Throws:
java.io.IOException

readExternal

public void readExternal(java.io.ObjectInput in)
                  throws java.io.IOException,
                         java.lang.ClassNotFoundException
Specified by:
readExternal in interface java.io.Externalizable
Throws:
java.io.IOException
java.lang.ClassNotFoundException


Copyright © 2004 Mortbay Consulting Pty. Ltd. All Rights Reserved.