com.github.fge.jackson.jsonpointer
Class TreePointer<T extends com.fasterxml.jackson.core.TreeNode>

java.lang.Object
  extended by com.github.fge.jackson.jsonpointer.TreePointer<T>
Type Parameters:
T - the type of the tree
All Implemented Interfaces:
Iterable<TokenResolver<T>>
Direct Known Subclasses:
JsonPointer

@ThreadSafe
public abstract class TreePointer<T extends com.fasterxml.jackson.core.TreeNode>
extends Object
implements Iterable<TokenResolver<T>>

A pointer into a TreeNode

Note that all pointers are absolute: they start from the root of the tree. This is to mirror the behaviour of JSON Pointer proper.

The class does not decode a JSON Pointer representation itself; however it provides all the necessary methods for implementations to achieve this.

This class has two traversal methods: get(TreeNode) and path(TreeNode). The difference between both is that path() may return another node than null if the tree representation has such a node. This is the case, for instance, for JsonNode, which has a MissingNode.

At the core, this class is essentially a(n ordered!) List of TokenResolvers (which is iterable via the class itself).

Note that this class' hashCode(), equals(Object) and toString() are final.


Field Summary
protected static MessageBundle BUNDLE
           
protected  List<TokenResolver<T>> tokenResolvers
          The list of token resolvers
 
Constructor Summary
protected TreePointer(List<TokenResolver<T>> tokenResolvers)
          Alternate constructor
protected TreePointer(T missing, List<TokenResolver<T>> tokenResolvers)
          Main protected constructor
 
Method Summary
 boolean equals(Object obj)
           
 T get(T node)
          Traverse a node and return the result
 int hashCode()
           
 boolean isEmpty()
          Tell whether this pointer is empty
 Iterator<TokenResolver<T>> iterator()
           
 T path(T node)
          Traverse a node and return the result
protected static List<ReferenceToken> tokensFromInput(String input)
          Decode an input into a list of reference tokens
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

BUNDLE

protected static final MessageBundle BUNDLE

tokenResolvers

protected final List<TokenResolver<T extends com.fasterxml.jackson.core.TreeNode>> tokenResolvers
The list of token resolvers

Constructor Detail

TreePointer

protected TreePointer(T missing,
                      List<TokenResolver<T>> tokenResolvers)
Main protected constructor

This constructor makes an immutable copy of the list it receives as an argument.

Parameters:
missing - the representation of a missing node (may be null)
tokenResolvers - the list of reference token resolvers

TreePointer

protected TreePointer(List<TokenResolver<T>> tokenResolvers)
Alternate constructor

This is the same as calling TreePointer(TreeNode, List) with null as the missing node.

Parameters:
tokenResolvers - the list of token resolvers
Method Detail

get

public final T get(T node)
Traverse a node and return the result

Note that this method shortcuts: it stops at the first node it cannot traverse.

Parameters:
node - the node to traverse
Returns:
the resulting node, null if not found

path

public final T path(T node)
Traverse a node and return the result

This is like get(TreeNode), but it will return the missing node if traversal fails.

Parameters:
node - the node to traverse
Returns:
the result, or the missing node
See Also:
TreePointer(TreeNode, List)

isEmpty

public final boolean isEmpty()
Tell whether this pointer is empty

Returns:
true if the reference token list is empty

iterator

public final Iterator<TokenResolver<T>> iterator()
Specified by:
iterator in interface Iterable<TokenResolver<T extends com.fasterxml.jackson.core.TreeNode>>

hashCode

public final int hashCode()
Overrides:
hashCode in class Object

equals

public final boolean equals(Object obj)
Overrides:
equals in class Object

toString

public final String toString()
Overrides:
toString in class Object

tokensFromInput

protected static List<ReferenceToken> tokensFromInput(String input)
                                               throws JsonPointerException
Decode an input into a list of reference tokens

Parameters:
input - the input
Returns:
the list of reference tokens
Throws:
JsonPointerException - input is not a valid JSON Pointer
NullPointerException - input is null