Package com.networknt.schema
Class JsonNodePath
- java.lang.Object
-
- com.networknt.schema.JsonNodePath
-
- All Implemented Interfaces:
java.lang.Comparable<JsonNodePath>
public class JsonNodePath extends java.lang.Object implements java.lang.Comparable<JsonNodePath>
Represents a path to a JSON node.
-
-
Field Summary
Fields Modifier and Type Field Description private int
hash
private JsonNodePath
parent
private java.lang.String
pathSegment
private int
pathSegmentIndex
private PathType
type
private java.lang.String
value
-
Constructor Summary
Constructors Modifier Constructor Description private
JsonNodePath(JsonNodePath parent, int pathSegmentIndex)
private
JsonNodePath(JsonNodePath parent, java.lang.String pathSegment)
JsonNodePath(PathType type)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description JsonNodePath
append(int index)
Append the index to the path.JsonNodePath
append(java.lang.String token)
Append the child token to the path.int
compareTo(JsonNodePath other)
boolean
contains(java.lang.String segment)
Tests if this path contains a string segment that is an exact match.boolean
equals(java.lang.Object obj)
java.lang.Object
getElement(int index)
Gets the element given an index.java.lang.String
getName(int index)
Gets the name element given an index.int
getNameCount()
Gets the number of name elements in the path.JsonNodePath
getParent()
Returns the parent path, or null if this path does not have a parent.PathType
getPathType()
Gets thePathType
.int
hashCode()
boolean
startsWith(JsonNodePath other)
Tests if this path starts with the other path.java.lang.String
toString()
-
-
-
Field Detail
-
type
private final PathType type
-
parent
private final JsonNodePath parent
-
pathSegment
private final java.lang.String pathSegment
-
pathSegmentIndex
private final int pathSegmentIndex
-
value
private volatile java.lang.String value
-
hash
private int hash
-
-
Constructor Detail
-
JsonNodePath
public JsonNodePath(PathType type)
-
JsonNodePath
private JsonNodePath(JsonNodePath parent, java.lang.String pathSegment)
-
JsonNodePath
private JsonNodePath(JsonNodePath parent, int pathSegmentIndex)
-
-
Method Detail
-
getParent
public JsonNodePath getParent()
Returns the parent path, or null if this path does not have a parent.- Returns:
- the parent
-
append
public JsonNodePath append(java.lang.String token)
Append the child token to the path.- Parameters:
token
- the child token- Returns:
- the path
-
append
public JsonNodePath append(int index)
Append the index to the path.- Parameters:
index
- the index- Returns:
- the path
-
getName
public java.lang.String getName(int index)
Gets the name element given an index.The index parameter is the index of the name element to return. The element that is closest to the root has index 0. The element that is farthest from the root has index count -1.
- Parameters:
index
- to return- Returns:
- the name element
-
getElement
public java.lang.Object getElement(int index)
Gets the element given an index.The index parameter is the index of the element to return. The element that is closest to the root has index 0. The element that is farthest from the root has index count -1.
- Parameters:
index
- to return- Returns:
- the element either a String or Integer
-
getNameCount
public int getNameCount()
Gets the number of name elements in the path.- Returns:
- the number of elements in the path or 0 if this is the root element
-
startsWith
public boolean startsWith(JsonNodePath other)
Tests if this path starts with the other path.- Parameters:
other
- the other path- Returns:
- true if the path starts with the other path
-
contains
public boolean contains(java.lang.String segment)
Tests if this path contains a string segment that is an exact match.This will not match if the segment is a number.
- Parameters:
segment
- the segment to test- Returns:
- true if the string segment is found
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classjava.lang.Object
-
equals
public boolean equals(java.lang.Object obj)
- Overrides:
equals
in classjava.lang.Object
-
compareTo
public int compareTo(JsonNodePath other)
- Specified by:
compareTo
in interfacejava.lang.Comparable<JsonNodePath>
-
-