Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

org.mortbay.util
Class StringMap  view StringMap download StringMap.java

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

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.11 2003/09/18 13:29:27 gregwilkins Exp $

Nested Class Summary
private static class StringMap.Node
           
private  class StringMap.NullEntry
           
 
Nested classes inherited from class java.util.AbstractMap
 
Nested classes inherited from class java.util.Map
java.util.Map.Entry
 
Field Summary
private static int __HASH_WIDTH
           
protected  java.util.HashSet _entrySet
           
protected  boolean _ignoreCase
           
protected  StringMap.NullEntry _nullEntry
           
protected  java.lang.Object _nullValue
           
protected  StringMap.Node _root
           
protected  java.util.Set _umEntrySet
           
protected  int _width
           
 
Fields inherited from class java.util.AbstractMap
 
Constructor Summary
StringMap()
          Constructor.
StringMap(boolean ignoreCase)
          Constructor.
StringMap(boolean ignoreCase, int width)
          Constructor.
 
Method Summary
 void clear()
          Remove all entries from this Map (optional operation).
 boolean containsKey(java.lang.Object key)
          Returns true if this contains a mapping for the given key.
 java.util.Set entrySet()
          Returns a set view of the mappings in this Map.
 java.lang.Object get(java.lang.Object key)
          Returns the value mapped by the given 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()
          Returns true if the map contains no mappings.
 boolean isIgnoreCase()
           
 java.lang.Object put(java.lang.Object key, java.lang.Object value)
          Associates the given key to the given value (optional operation).
 java.lang.Object put(java.lang.String key, java.lang.Object value)
           
 void readExternal(java.io.ObjectInput in)
          This method restores an object's state by reading in the instance data for the object from the passed in stream.
 java.lang.Object remove(java.lang.Object key)
          Removes the mapping for this key if present (optional operation).
 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()
          Returns the number of key-value mappings in the map.
 void writeExternal(java.io.ObjectOutput out)
          This method is responsible for writing the instance data of an object to the passed in stream.
 
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

__HASH_WIDTH

private static final int __HASH_WIDTH
See Also:
Constant Field Values

_width

protected int _width

_root

protected StringMap.Node _root

_ignoreCase

protected boolean _ignoreCase

_nullEntry

protected 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.


StringMap

public StringMap(boolean ignoreCase,
                 int width)
Constructor.

Method Detail

setIgnoreCase

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


isIgnoreCase

public boolean isIgnoreCase()

setWidth

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


getWidth

public int getWidth()

put

public java.lang.Object put(java.lang.Object key,
                            java.lang.Object value)
Description copied from class: java.util.AbstractMap
Associates the given key to the given value (optional operation). If the map already contains the key, its value is replaced. This implementation simply throws an UnsupportedOperationException. Be aware that in a map that permits null values, a null return does not always imply that the mapping was created.

Specified by:
put in interface java.util.Map

put

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

get

public java.lang.Object get(java.lang.Object key)
Description copied from class: java.util.AbstractMap
Returns the value mapped by the given key. Returns null if there is no mapping. However, in Maps that accept null values, you must rely on containsKey to determine if a mapping exists. This iteration takes linear time, searching entrySet().iterator() of the key. Many implementations override this method.

Specified by:
get in interface java.util.Map

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.


getEntry

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


getEntry

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


remove

public java.lang.Object remove(java.lang.Object key)
Description copied from class: java.util.AbstractMap
Removes the mapping for this key if present (optional operation). This implementation iterates over the entrySet searching for a matching key, at which point it calls the iterator's remove method. It returns the result of getValue() on the entry, if found, or null if no entry is found. Note that maps which permit null values may also return null if the key was removed. If the entrySet does not support removal, this will also fail. This is O(n), so many implementations override it for efficiency.

Specified by:
remove in interface java.util.Map

remove

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

entrySet

public java.util.Set entrySet()
Description copied from class: java.util.AbstractMap
Returns a set view of the mappings in this Map. Each element in the set must be an implementation of Map.Entry. The set is backed by the map, so that changes in one show up in the other. Modifications made while an iterator is in progress cause undefined behavior. If the set supports removal, these methods must be valid: Iterator.remove, Set.remove, removeAll, retainAll, and clear. Element addition is not supported via this set.

Specified by:
entrySet in interface java.util.Map

size

public int size()
Description copied from class: java.util.AbstractMap
Returns the number of key-value mappings in the map. If there are more than Integer.MAX_VALUE mappings, return Integer.MAX_VALUE. This is implemented as entrySet().size().

Specified by:
size in interface java.util.Map

isEmpty

public boolean isEmpty()
Description copied from class: java.util.AbstractMap
Returns true if the map contains no mappings. This is implemented by size() == 0.

Specified by:
isEmpty in interface java.util.Map

containsKey

public boolean containsKey(java.lang.Object key)
Description copied from class: java.util.AbstractMap
Returns true if this contains a mapping for the given key. This implementation does a linear search, O(n), over the entrySet(), returning true if a match is found, false if the iteration ends. Many subclasses can implement this more efficiently.

Specified by:
containsKey in interface java.util.Map

clear

public void clear()
Description copied from class: java.util.AbstractMap
Remove all entries from this Map (optional operation). This default implementation calls entrySet().clear(). NOTE: If the entry set does not permit clearing, then this will fail, too. Subclasses often override this for efficiency. Your implementation of entrySet() should not call AbstractMap.clear unless you want an infinite loop.

Specified by:
clear in interface java.util.Map

writeExternal

public void writeExternal(java.io.ObjectOutput out)
                   throws java.io.IOException
Description copied from interface: java.io.Externalizable
This method is responsible for writing the instance data of an object to the passed in stream. Note that this stream is not a subclass of OutputStream, but rather is a class that implements the ObjectOutput interface. That interface provides a number of methods for writing Java data values to a stream.

Not that the implementation of this method must be coordinated with the implementation of readExternal.

Specified by:
writeExternal in interface java.io.Externalizable

readExternal

public void readExternal(java.io.ObjectInput in)
                  throws java.io.IOException,
                         java.lang.ClassNotFoundException
Description copied from interface: java.io.Externalizable
This method restores an object's state by reading in the instance data for the object from the passed in stream. Note that this stream is not a subclass of InputStream, but rather is a class that implements the ObjectInput interface. That interface provides a mechanism for reading in Java data types from a stream.

Note that this method must be compatible with writeExternal. It must read back the exact same types that were written by that method in the exact order they were written.

If this method needs to read back an object instance, then the class for that object must be found and loaded. If that operation fails, then this method throws a ClassNotFoundException

Specified by:
readExternal in interface java.io.Externalizable