java.lang.Object
java.lang.Record
io.github.grumpystuff.grumpyrest.request.path.Path
Record Components:
segments - the segments of this path (pattern). The segments of the actual path from a request are lined up one-by-one with these segments and matched using PathSegment.matches(String).

public record Path(List<PathSegment> segments) extends Record
A path -- actually a path pattern -- that determines whether the actual path provided by a request matches a route. An instance of this class may define path parameters using VariablePathSegment.

It is currently not possible to create an instance that allows an incoming request path to have arbitrary extra segments.

  • Constructor Details

    • Path

      public Path(List<PathSegment> segments)
      Compact constructor.
      Parameters:
      segments - the segments of this path (pattern). The segments of the actual path from a request are lined up one-by-one with these segments and matched using PathSegment.matches(String).
  • Method Details

    • parse

      public static Path parse(String pathSpec)
      Creates an instance from a string-based specification, using :name for path parameters.
      Parameters:
      pathSpec - the path specification
      Returns:
      the instance
    • match

      public List<PathArgument> match(List<String> requestSegments, ParseFromStringService parseFromStringService)
      Matches a request path (i.e. a list of strings) against this path. This can either succeed and return a list of bound path arguments, or fail because the paths are different. "Different" here means that a literal segment of this path has a different text than the corresponding segment of the request.
      Parameters:
      requestSegments - the path segments from the request
      parseFromStringService - this service is needed because it is baked into returned path argument objects to allow the application code to convert the arguments into high-level types
      Returns:
      if matched successfully, the bound path arguments. This list only contains an element for each path parameter in this path. That is, it does not contain any entries for literal segments.
    • 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.
    • segments

      public List<PathSegment> segments()
      Returns the value of the segments record component.
      Returns:
      the value of the segments record component