net.groboclown.util.datastruct.v1
Class PathRegistry

java.lang.Object
  |
  +--net.groboclown.util.datastruct.v1.PathRegistry

public class PathRegistry
extends Object

A path-tree registry for storing and retrieving objects. Objects can be registered at any point along the tree, but no more than one object may be at each node. A null entry at a point indicates a non-registered node.

Synchronization needs to be hauled-over to increase speed and minimize read interference with writes.

Version:
0.9.0 Alpha
Author:
Matt Albrecht

Inner Class Summary
(package private)  class PathRegistry.TreeNode
           
 
Field Summary
private  boolean m_ignoreDuplicateSeparators
           
private  PathRegistry.TreeNode m_root
           
private  char m_separator
           
 
Constructor Summary
PathRegistry(char separator, boolean ignoreDuplicateSeparators)
          Users must specify all variables without corresponding defaults.
 
Method Summary
protected  void addChildNode(PathRegistry.TreeNode parent, PathRegistry.TreeNode child)
          Child must already be initialized correctly.
protected  PathRegistry.TreeNode findNode(String name)
          Find the node with the given name.
protected  PathRegistry.TreeNode findSibling(PathRegistry.TreeNode parent, String namePart)
          Find the sibling with the given node name part.
 Object get(String path)
          Retrieve the object stored at the given path.
protected  Enumeration parsePath(String path)
          Parses the given path into node elements.
 void register(String path, Object value, boolean isRecursive, boolean isCaseSensitive)
          Register the given object at the given path.
 void remove(String path)
          Remove the object at the given path.
protected  void removeChild(PathRegistry.TreeNode parent, PathRegistry.TreeNode child)
          Find the sibling with the given node name part.
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait
 

Field Detail

m_separator

private char m_separator

m_ignoreDuplicateSeparators

private boolean m_ignoreDuplicateSeparators

m_root

private PathRegistry.TreeNode m_root
Constructor Detail

PathRegistry

public PathRegistry(char separator,
                    boolean ignoreDuplicateSeparators)
Users must specify all variables without corresponding defaults. This prevents the class from implementing defaults, which have a habit of randomly changing.
Method Detail

register

public void register(String path,
                     Object value,
                     boolean isRecursive,
                     boolean isCaseSensitive)
              throws PathAlreadyRegisteredException
Register the given object at the given path. If the nodes leading up to this end node do not exist, then they will be created.

For future use, we will need to re-do synchronization, so that we synch on the tree node parent being worked on.

Parameters:
path - the path under which the given value will be registered.
value - the object to store under the given path.
isRecursive - set to true to notify the tree that this particular node also covers any sub-paths. If this is false, then queries will only retrieve this node if the exact path is given.
isCaseSensitive - set to true if the given node is to be case sensitive in searches. If the nodes leading to this new node do not exist, then the newly created nodes will have the same case sensitivity as this end node.
Throws:
IllegalArgumentException - thrown if the value is null, or the given path is not well formed.
PathAlreadyRegisteredException - thrown if the given path has already been registered to another object.

remove

public void remove(String path)
            throws NoRegisteredComponentException
Remove the object at the given path. It only removes nodes if the node no longer has any children. The siblings are automatically compressed.

For future use, we will need to re-do synchronization, so that we synch on the tree node parent being worked on.

Parameters:
path - the tree path specifying which node to remove. If the given node does not exist, or has not been registered, then a NotRegisteredException is thrown.
Throws:
IllegalArgumentException - thrown if the value is null, or the given path is not well formed.
NoRegisteredComponentException - thrown if the given path node has not yet been registered.

get

public Object get(String path)
Retrieve the object stored at the given path.

Need to synchronize better so that reads don't collide with writes, but reads can be done asynchronously.

Parameters:
path - the path which specifies the object to retrieve.
Returns:
the object which was registered at the given path, or null if nothing is registered there.

parsePath

protected Enumeration parsePath(String path)
Parses the given path into node elements. The last item in the list is ignored, unless the path ends with the path separator character.

findSibling

protected PathRegistry.TreeNode findSibling(PathRegistry.TreeNode parent,
                                            String namePart)
Find the sibling with the given node name part.

findNode

protected PathRegistry.TreeNode findNode(String name)
Find the node with the given name.

removeChild

protected void removeChild(PathRegistry.TreeNode parent,
                           PathRegistry.TreeNode child)
Find the sibling with the given node name part.

addChildNode

protected void addChildNode(PathRegistry.TreeNode parent,
                            PathRegistry.TreeNode child)
                     throws PathAlreadyRegisteredException
Child must already be initialized correctly.


Written under the LGPL