org.mortbay.util

Class StringMap

Implemented Interfaces:
Externalizable

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 org.mortbay.util.StringMap.NullEntry
_nullEntry
protected Object
_nullValue
protected org.mortbay.util.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

void
clear()
boolean
containsKey(Object key)
Set
entrySet()
Object
get(Object key)
Object
get(String key)
Map.Entry
getEntry(String key, int offset, int length)
Get a map entry by substring key.
Map.Entry
getEntry(byte[] key, int offset, int length)
Get a map entry by byte array key.
Map.Entry
getEntry(char[] key, int offset, int length)
Get a map entry by char array key.
int
getWidth()
boolean
isEmpty()
boolean
isIgnoreCase()
Object
put(Object key, Object value)
Object
put(String key, Object value)
void
readExternal(java.io.ObjectInput in)
Object
remove(Object key)
Object
remove(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)

Field Details

_entrySet

protected HashSet _entrySet

_ignoreCase

protected boolean _ignoreCase

_nullEntry

protected org.mortbay.util.StringMap.NullEntry _nullEntry

_nullValue

protected Object _nullValue

_root

protected org.mortbay.util.StringMap.Node _root

_umEntrySet

protected Set _umEntrySet

_width

protected int _width

Constructor Details

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 Details

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

getEntry

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

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(java.io.ObjectInput in)
            throws java.io.IOException,
                   ClassNotFoundException

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(java.io.ObjectOutput out)
            throws java.io.IOException

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