com.vinculumtech.platform.util.context
Class ContextTree

java.lang.Object
  extended bycom.vinculumtech.platform.util.context.ContextTree

public class ContextTree
extends java.lang.Object

The ContextTree class takes a set of unique keys and returns a context sensitive value.
The ContextTree can be used in three ways. As a static "map", relating a set of unique keys to a single value. As a cummunlative map, relating a set of unique keys to a factory object which is passed a value returned by its parent, and a value associated with the context key, and returns a new value. Or as a combination of both.

Version:
$Id: //depot/carrierwave/src/shared/com/vinculumtech/platform/util/context/ContextTree.java#3 $

Constructor Summary
ContextTree()
           
ContextTree(java.lang.Object rootValue)
          Creates a ContextTree that
 
Method Summary
 ContextNode addChildNode(java.lang.String contextElement)
          Add new branch for key, returns same values as parent.
 ContextNode addChildNode(java.lang.String contextElement, Function valueFunction)
          Add new branch for key, result value is a result of the given Function.
This method accepts either a NullaryFunction, UnaryFunction, BinaryFunction, or a TernaryFunction.
 ContextNode addChildNode(java.lang.String contextElement, java.lang.Object value)
          Add new branch for key, always return given value.
 java.lang.Object getCummulativeValueFor(java.util.Map contextMap)
          Returns the factory created value for the given contextMap.
 java.lang.Object getValueFor(java.util.Collection context)
          Returns the static value for the given contextMap.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ContextTree

public ContextTree()

ContextTree

public ContextTree(java.lang.Object rootValue)
Creates a ContextTree that

Parameters:
rootValue -
Method Detail

addChildNode

public ContextNode addChildNode(java.lang.String contextElement,
                                java.lang.Object value)
Add new branch for key, always return given value.

Parameters:
contextElement -
value -
Returns:

addChildNode

public ContextNode addChildNode(java.lang.String contextElement,
                                Function valueFunction)
Add new branch for key, result value is a result of the given Function.
This method accepts either a NullaryFunction, UnaryFunction, BinaryFunction, or a TernaryFunction. The NullaryFunction is given no arguments, the UnaryFunction is given the corresponding value of the contextElement in the contextMap, the BinaryFunction is given the value of its parent, and the context value, and the TernaryFunction is given the contextMap, parent value, and context value.

Parameters:
contextElement -
valueFunction -
Returns:

addChildNode

public ContextNode addChildNode(java.lang.String contextElement)
Add new branch for key, returns same values as parent.

Parameters:
contextElement -
Returns:

getCummulativeValueFor

public java.lang.Object getCummulativeValueFor(java.util.Map contextMap)
Returns the factory created value for the given contextMap. If no contextElement tree has been defined, will result in a ContextTreeException. Note that this form of retrieval always consults the parent for the value one higher up the context tree.
If the valueFunction is null, and the static value is null, the parentValue will be returned.
If the static value is not null, it will be returned. Otherwise the valueFunction will be consulted.

Parameters:
contextMap -
Returns:

getValueFor

public java.lang.Object getValueFor(java.util.Collection context)
Returns the static value for the given contextMap. If no contextElement tree has been defined, will result in a ContextTreeException.

Parameters:
context -
Returns:


Copyright (C) 2002 Vinculum Technologies, Inc. All Rights Reserved.