Package JsonFse
Class Node
- java.lang.Object
-
- JsonFse.Node
-
- Direct Known Subclasses:
NodeElements
,NodeMembers
,NodePair
,NodeValue
public abstract class Node extends java.lang.Object
Base class of all nodes a JSON tree consists of.- Author:
- Friedemann Seebass
-
-
Constructor Summary
Constructors Constructor Description Node()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Node
get(int idx)
If the node is of type NodeObj or NodeArray get() delivers the element with index idx.java.lang.String
getAsString()
java.lang.String
getAsString(int columnOffset, boolean hasLabel)
Delivers recursively a node and all of its children as a formatted string.java.lang.String
getAsStrippedString()
In JSON all strings are surrounded by quotation marks.Node
getNext()
If the node is of type NodeObj or NodeArray getNext() delivers the next element (of type NodePair or NodeValue).protected java.lang.String
indent(int num)
Delivers a string consisting out of num spaces.
-
-
-
Method Detail
-
getAsString
public java.lang.String getAsString()
-
getAsStrippedString
public java.lang.String getAsStrippedString()
In JSON all strings are surrounded by quotation marks. These are regularly superfluous for further processing. This method returns the string without these quotes if the Node is a NodeString.- Returns:
- The string without the leading and trailing quotes.
-
getAsString
public java.lang.String getAsString(int columnOffset, boolean hasLabel)
Delivers recursively a node and all of its children as a formatted string. Child nodes and their elements are indented according to the following rules:- Each pair (of label and value) is in its own line.
- Values containing sub elements (i. e. JSON objects and arrays) start in the same line as the label.
- If they contain no or only one element they are written in the same line, following directly after the label.
- If they contain more than one element the opening bracket is written into the same line as the label, but each element in its own line. The elements are indented further mTabWidth spaces. The closing bracket is written in its own line, but in the same column as the opening bracket.
- Parameters:
columnOffset
- Number of spaces an element is indented.hasLabel
- If true this node starts in a line with a label. The element must not be indented then but follows immediately after the label.- Returns:
- Formatted string of the node and its childs.
-
indent
protected java.lang.String indent(int num)
Delivers a string consisting out of num spaces.- Parameters:
num
- Number of spaces.- Returns:
- String consisting out of num spaces.
-
getNext
public Node getNext()
If the node is of type NodeObj or NodeArray getNext() delivers the next element (of type NodePair or NodeValue). The index the element is read from can be set with setIdx(). The index is incremented on each call automatically.- Returns:
- The next element in a list of NodePairs or NoveValues or null if no more elements are available.
-
get
public Node get(int idx)
If the node is of type NodeObj or NodeArray get() delivers the element with index idx.- Parameters:
idx
- Index of the wanted NodePair or NodeValue out of a list of these elements.- Returns:
- The element with index idx.
-
-