org.apache.activemq.apollo.util.path
Class PathMap<Value>

java.lang.Object
  extended by org.apache.activemq.apollo.util.path.PathMap<Value>

public class PathMap<Value>
extends java.lang.Object

A Map-like data structure allowing values to be indexed by AsciiBuffer and retrieved by path - supporting both * and > style of wildcard as well as composite paths.
This class assumes that the index changes rarely but that fast lookup into the index is required. So this class maintains a pre-calculated index for path steps. So looking up the values for "TEST.*" or "*.TEST" will be pretty fast.
Looking up of a value could return a single value or a List of matching values if a wildcard or composite path is used.

Version:
$Revision: 1.3 $

Constructor Summary
PathMap()
           
 
Method Summary
 Value chooseValue(Path path)
          Returns the value which matches the given path or null if there is no matching value.
protected  java.util.Set<Value> findWildcardMatches(Path path)
           
 java.util.Set<Value> get(Path key)
          Looks up the value(s) matching the given AsciiBuffer key.
 PathMapNode<Value> getRootNode()
           
 void put(Path key, Value value)
           
 boolean remove(Path path, Value value)
          Removes the value from the associated path
 java.util.Set<Value> removeAll(Path key)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PathMap

public PathMap()
Method Detail

get

public java.util.Set<Value> get(Path key)
Looks up the value(s) matching the given AsciiBuffer key. For simple paths this is typically a List of one single value, for wild cards or composite paths this will typically be a List of matching values.

Parameters:
key - the path to lookup
Returns:
a List of matching values or an empty list if there are no matching values.

put

public void put(Path key,
                Value value)

remove

public boolean remove(Path path,
                      Value value)
Removes the value from the associated path


getRootNode

public PathMapNode<Value> getRootNode()

findWildcardMatches

protected java.util.Set<Value> findWildcardMatches(Path path)

removeAll

public java.util.Set<Value> removeAll(Path key)
Parameters:
key -
Returns:

chooseValue

public Value chooseValue(Path path)
Returns the value which matches the given path or null if there is no matching value. If there are multiple values, the results are sorted and the last item (the biggest) is returned.

Parameters:
path - the path to find the value for
Returns:
the largest matching value or null if no value matches


Copyright © 2005-2011 The Apache Software Foundation. All Rights Reserved.