argo.jdom
Class JsonNodeSelector<T,U>

java.lang.Object
  extended by argo.jdom.JsonNodeSelector<T,U>
Type Parameters:
T - The type of Object worked on.
U - The type of Object returned.

public final class JsonNodeSelector<T,U>
extends java.lang.Object

Instances of JsonNodeSelector extract values from Objects of a specified type.

For example, given a JsonNode representing {"Fee":{"fi":"fo"}},

 anObjectNodeWithField("Fee")
 .withChild(anObjectNodeWithField("fi"))
 .withChild(aStringNode())
 .getValue(jsonNode)
 
will return the String "fo".


Method Summary
 U getValue(T argument)
          Extracts a value from the give JsonNode.
 boolean matches(T jsonNode)
          Determines whether this JsonNodeSelector can extract a value from the given JsonNode.
 java.lang.String toString()
           
<V> JsonNodeSelector<T,V>
with(JsonNodeSelector<U,V> childJsonNodeSelector)
          Constructs a JsonNodeSelector consisting of this chained with the given JsonNodeSelector.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Method Detail

matches

public boolean matches(T jsonNode)
Determines whether this JsonNodeSelector can extract a value from the given JsonNode.

Parameters:
jsonNode - the JsonNode to test.
Returns:
true if a value can be extracted from the given JsonNode, false otherwise.

getValue

public U getValue(T argument)
Extracts a value from the give JsonNode.

Parameters:
argument - the JsonNode to extract a value from.
Returns:
the extracted value.
Throws:
java.lang.IllegalArgumentException - if calling matches{@code with the given {@code JsonNode} would return false, indicating no value can be extracted from it.

with

public <V> JsonNodeSelector<T,V> with(JsonNodeSelector<U,V> childJsonNodeSelector)

Constructs a JsonNodeSelector consisting of this chained with the given JsonNodeSelector.

For example, if we have JsonNodeSelectors for the first element of an array, and another that selects the second element of an array, and we chain them together in that order, we will get a selector that works on nested arrays, selecting the second element from an array stored in the first element of a parent array.

Type Parameters:
V - the type the chained JsonNodeSelector will return.
Parameters:
childJsonNodeSelector - the JsonNodeSelector to chain onto this.
Returns:
a new JsonNodeSelector representing this, and the given selector applied in sequence.

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object