Package com.jsgalactic.axiom.validation
Class FieldPath
java.lang.Object
com.jsgalactic.axiom.validation.FieldPath
Immutable builder for violation field paths such as
items[2].name.
Segments are developer-defined property names and element indexes, never client input. Paths
are bounded: once appending a segment would exceed MAX_LENGTH characters, or an index
exceeds the nine digits a violation field allows, the path stops at the last ancestor that fits
and is marked truncated; later appends are ignored so a violation is
never attributed to an unrelated field. The empty path is reported as the empty ROOT
field, for checks on the whole value; problem responses leave the field out for it.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intLongest field path, matching the limit ofViolation.field().static final StringField reported for violations of the whole value: the empty string. -
Method Summary
Modifier and TypeMethodDescriptionAppends a field reported by a nested validator; the emptyROOTmaps to this path.booleaninthashCode()index(int index) Appends an element index to the last property.static booleanisPropertyName(String name) Tells whether a name may be used as one property segment: an ASCII letter or_followed by ASCII letters, digits,_or-.booleanisRoot()Tells whether this is the empty root path.booleanTells whether a segment was dropped because of the length or index limit.Appends a property segment.static FieldPathroot()Returns the empty path of the validated value itself.toField()Returns the path as a violation field.toString()
-
Field Details
-
ROOT
Field reported for violations of the whole value: the empty string.- See Also:
-
MAX_LENGTH
public static final int MAX_LENGTHLongest field path, matching the limit ofViolation.field().- See Also:
-
-
Method Details
-
root
Returns the empty path of the validated value itself.- Returns:
- root path
-
isPropertyName
Tells whether a name may be used as one property segment: an ASCII letter or_followed by ASCII letters, digits,_or-.- Parameters:
name- candidate segment- Returns:
- whether
property(String)accepts it
-
property
Appends a property segment.- Parameters:
name- property name, seeisPropertyName(String)- Returns:
- extended path, or this path if it is truncated or would become too long
- Throws:
IllegalArgumentException- if the name is not a safe property segment
-
index
Appends an element index to the last property.- Parameters:
index- zero-based element index- Returns:
- extended path, or a truncated path when this is the root, the index has more than nine digits, or the path would become too long
- Throws:
IllegalArgumentException- if the index is negative
-
append
Appends a field reported by a nested validator; the emptyROOTmaps to this path.- Parameters:
field- a validViolation.field()value- Returns:
- extended path, or this path marked truncated if the result would be too long
- Throws:
IllegalArgumentException- if the field is not a valid violation field
-
isRoot
public boolean isRoot()Tells whether this is the empty root path.- Returns:
- true for the root
-
isTruncated
public boolean isTruncated()Tells whether a segment was dropped because of the length or index limit.- Returns:
- true when the path stopped early
-
toField
Returns the path as a violation field.- Returns:
- the path, or the empty
ROOTfor the root
-
equals
-
hashCode
public int hashCode() -
toString
-