com.boylesoftware.cb2.util
Class BTreeMap

java.lang.Object
  extended bycom.boylesoftware.cb2.util.BTreeMap
All Implemented Interfaces:
java.io.Serializable

public class BTreeMap
extends java.lang.Object
implements java.io.Serializable

This class allows to associate values with string prefixes. You add elements as to a map, where keys are strings and values are some objects, later you can do lookups by the longest prefix. Here is an example:

You have the folowing elements in your map:

 ab     => 1
 abcd   => 2
 zyx    => 3
 zyxabc => 4
 

Below are results of lookups by various input strings:

 abcdefgh => 2
 abc      => 1
 a        => null
 orange   => null
 zyx      => 3
 zyx_111  => 3
 

This implementation is not thread-safe. In multithread environments access an object of this class has to be synchronized externally.

Version:
$Id: BTreeMap.java,v 1.2 2003/09/17 19:16:05 levahim Exp $
Author:
Lev Himmelfarb
See Also:
Serialized Form

Nested Class Summary
protected  class BTreeMap.Entry
          An entry.
 
Field Summary
protected  java.util.HashMap top
          The top level.
 
Constructor Summary
BTreeMap()
          Constructs a new empty map.
 
Method Summary
 void clear()
          Clears the map.
protected  void clear(java.util.HashMap level)
          Clears one level.
 java.lang.Object get(java.lang.String key)
          Looks up the best value for the specified key.
 void put(java.lang.String prefix, java.lang.Object value)
          Adds a new value to the map.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

top

protected final java.util.HashMap top
The top level. Keys are objects of Character, values are objects of BTreeMap.Entry.

Constructor Detail

BTreeMap

public BTreeMap()
Constructs a new empty map.

Method Detail

put

public void put(java.lang.String prefix,
                java.lang.Object value)
Adds a new value to the map.

Parameters:
prefix - the key.
value - the value.

get

public java.lang.Object get(java.lang.String key)
Looks up the best value for the specified key.

Parameters:
key - the input key to look up a value for.
Returns:
value associated with the longest prefix in the map matching the beginning of the specified key. May return null.

clear

public void clear()
Clears the map.


clear

protected void clear(java.util.HashMap level)
Clears one level.

Parameters:
level - the level.


Copyright © 2002,2003,2004 - Boyle Software, Inc.