Class FieldPath

java.lang.Object
com.jsgalactic.axiom.validation.FieldPath

public final class FieldPath extends Object
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 Details

  • Method Details

    • root

      public static FieldPath root()
      Returns the empty path of the validated value itself.
      Returns:
      root path
    • isPropertyName

      public static boolean isPropertyName(String name)
      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

      public FieldPath property(String name)
      Appends a property segment.
      Parameters:
      name - property name, see isPropertyName(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

      public FieldPath index(int 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

      public FieldPath append(String field)
      Appends a field reported by a nested validator; the empty ROOT maps to this path.
      Parameters:
      field - a valid Violation.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

      public String toField()
      Returns the path as a violation field.
      Returns:
      the path, or the empty ROOT for the root
    • equals

      public boolean equals(Object other)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object