io.github.endreman0.javajson.nodes.Node Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of java-json Show documentation
Show all versions of java-json Show documentation
A JSON parser and mutable object-model implememntation
package io.github.endreman0.javajson.nodes;
/**
* All JSON nodes have a few properties in common.
*
* - They all have a parent node, and
* - Given another node with the same values and/or children, the two nodes will be considered equal.
*
* @author endreman0
*/
public abstract class Node{
protected ParentNode parent;
protected Node(){}
/**
* Remove this node from its parent.
*/
public void remove(){if(parent != null) parent.remove(this);}
/**
* Get the parent of this node.
* @return the node's parent
*/
public ParentNode parent(){return parent;}
/**
* Get a textual representation of the JSON for this node.
* @return the JSON text for this node
*/
public abstract String json();
/**
* Get a textual representation of the contents of this node.
* For objects and arrays, this will be just their children without being wrapped in curly brackets and square brackets.
* For strings, this will be the contained string.
* For booleans, numbers, and null, this will be the same as {@link #json()}.
* @return The JSON text for the contents of this node
*/
public abstract String innerJSON();
@Override public String toString(){return json();}
@Override public abstract boolean equals(Object obj);
@Override public abstract int hashCode();
}