Record Class Path
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 usingPathSegment.matches(String).
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 Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionfinal booleanIndicates whether some other object is "equal to" this one.final inthashCode()Returns a hash code value for this object.match(List<String> requestSegments, ParseFromStringService parseFromStringService) Matches a request path (i.e. a list of strings) against this path.static PathCreates an instance from a string-based specification, using:namefor path parameters.segments()Returns the value of thesegmentsrecord component.toString()Returns a string representation of this record class.
-
Constructor Details
-
Path
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 usingPathSegment.matches(String).
-
-
Method Details
-
parse
Creates an instance from a string-based specification, using:namefor 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 requestparseFromStringService- 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
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. -
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. -
equals
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 withObjects::equals(Object,Object). -
segments
Returns the value of thesegmentsrecord component.- Returns:
- the value of the
segmentsrecord component
-