java.lang.Object
io.jstach.jstachio.context.ObjectContext
- All Implemented Interfaces:
ContextNode,io.jstach.jstachio.context.Internal.ObjectContextNode,Formatter.Formattable,Iterable<@Nullable ContextNode>
public abstract non-sealed class ObjectContext
extends Object
implements io.jstach.jstachio.context.Internal.ObjectContextNode
Extend this class to make
JStache model act like JSON object or a
java.util.Map.- Author:
- agentgt
- See Also:
-
Field Summary
Fields inherited from interface io.jstach.jstachio.context.ContextNode
CONTEXT_BINDING_NAME -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionfinal @Nullable ContextNodeWill search up the tree for a field starting at this nodes children first.final @Nullable ContextNodeGets a field from a ContextNode.abstract @Nullable ObjectGet a value by key.final booleanisFalsey()Determines if the node is falsey.final Iterator<@Nullable ContextNode>iterator()If the node is a Map or a non iterable/array a singleton iterator will be returned.final Objectobject()The object being wrapped.default @Nullable ContextNodeCreates an indexed child node off of this node where the return child nodes parent will be this node.default @Nullable ContextNodeCreates a named child node off of this node where the return child nodes parent will be this node.final @Nullable ContextNodeparent()The parent node.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface io.jstach.jstachio.context.ContextNode
renderStringMethods inherited from interface io.jstach.jstachio.context.Internal.ObjectContextNode
formatMethods inherited from interface java.lang.Iterable
forEach, spliterator
-
Constructor Details
-
ObjectContext
protected ObjectContext()Do nothing constructor
-
-
Method Details
-
getValue
Get a value by key. This is analagous toMap.get(Object).- Specified by:
getValuein interfaceio.jstach.jstachio.context.Internal.ObjectContextNode- Parameters:
key- not null- Returns:
- value mapped to key.
-
object
Description copied from interface:ContextNodeThe object being wrapped.- Specified by:
objectin interfaceContextNode- Returns:
- the Map, Iterable or object that was wrapped. Never
null.
-
get
Description copied from interface:ContextNodeGets a field from a ContextNode. This is direct access (end of a dotted path) and does not check the parents. The default implementation will check if the wrapping object is aMapand use it to return a child context node. Just likeMapnullwill be returned if no field is found.- Specified by:
getin interfaceContextNode- Specified by:
getin interfaceio.jstach.jstachio.context.Internal.ObjectContextNode- Parameters:
field- the name of the field- Returns:
- a new child node. Maybe
null.
-
find
Description copied from interface:ContextNodeWill search up the tree for a field starting at this nodes children first.- Specified by:
findin interfaceContextNode- Parameters:
field- context name (e.g. section name)- Returns:
nullif not found otherwise creates a new node from the map or object containing the field.
-
parent
Description copied from interface:ContextNodeThe parent node.- Specified by:
parentin interfaceContextNode- Returns:
- the parent node or
nullif this is the root.
-
iterator
Description copied from interface:ContextNodeIf the node is a Map or a non iterable/array a singleton iterator will be returned. Otherwise if it is an iterable/array new child context nodes will be created lazily.- Specified by:
iteratorin interfaceContextNode- Specified by:
iteratorin interfaceio.jstach.jstachio.context.Internal.ObjectContextNode- Specified by:
iteratorin interfaceIterable<@Nullable ContextNode>- Returns:
- lazy iterator of context nodes.
-
isFalsey
Description copied from interface:ContextNodeDetermines if the node is falsey. If falsey (return of true) inverted section blocks will be executed. The default checks ifContextNode.iterator()has any next elements and if it does not it is falsey.- Specified by:
isFalseyin interfaceContextNode- Specified by:
isFalseyin interfaceio.jstach.jstachio.context.Internal.ObjectContextNode- Returns:
- true if falsey.
-
ofChild
default @Nullable ContextNode ofChild(String name, @Nullable Object o) throws IllegalArgumentException Creates a named child node off of this node where the return child nodes parent will be this node.- Parameters:
name- the context name.o- the object to be wrapped.- Returns:
nullif the child object is null otherwise a new child node.- Throws:
IllegalArgumentException- if the input object is aContextNode
-
ofChild
Creates an indexed child node off of this node where the return child nodes parent will be this node.- Parameters:
index- a numeric indexo- the object to be wrapped. Maybenull.- Returns:
nullif the child object is null otherwise a new child node.- Throws:
IllegalArgumentException- if the input object is aContextNode- API Note
- there is no checking to see if the same index is reused as the parent knows nothing of the child.
-