Record Class PermissionNode

java.lang.Object
java.lang.Record
fr.fidorial.permission.PermissionNode
All Implemented Interfaces:
Comparable<PermissionNode>

public record PermissionNode(String path) extends Record implements Comparable<PermissionNode>
  • Field Details

  • Constructor Details

    • PermissionNode

      public PermissionNode(String path)
      Creates an instance of a PermissionNode record class.
      Parameters:
      path - the value for the path record component
  • Method Details

    • of

      public static PermissionNode of(String path)
      Creates a node from its textual path.
      Parameters:
      path - dot-separated path
      Returns:
      the node
      Throws:
      IllegalArgumentException - if the path is malformed
    • segments

      public List<String> segments()
      Returns:
      the individual segments of this node
    • isWildcard

      public boolean isWildcard()
      Returns:
      true when the last segment is a wildcard
    • lookupChain

      public List<PermissionNode> lookupChain()
      Builds the lookup chain for this node, ordered from most specific to least specific.

      a.b.c yields a.b.c, a.b.*, a.* and finally *. The resolver walks this list and stops on the first decided state, which is what gives more specific rules priority over broader ones.

      Returns:
      the ordered lookup chain, always at least one element long
    • covers

      public boolean covers(PermissionNode other)
      Tests whether this node covers other, taking wildcards into account.
      Parameters:
      other - node being tested
      Returns:
      true if a rule on this node applies to other
    • child

      public PermissionNode child(String segment)
      Appends a child segment.
      Parameters:
      segment - segment to append
      Returns:
      the child node
    • compareTo

      public int compareTo(PermissionNode other)
      Specified by:
      compareTo in interface Comparable<PermissionNode>
    • toString

      public String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. All components in this record class are compared with Objects::equals(Object,Object).
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • path

      public String path()
      Returns the value of the path record component.
      Returns:
      the value of the path record component