Package com.duncpro.jroute.util
Class ParameterizedRoute
- java.lang.Object
-
- com.duncpro.jroute.route.Route
-
- com.duncpro.jroute.util.ParameterizedRoute
-
public class ParameterizedRoute extends Route
This class is an ergonomic wrapper aroundRoutewhich associates a label with eachWildcardRouteElementin aRoute. This class does not represent a unique type ofRoute, instead it is simply a utility to make accessing the variable elements in a path more ergonomic. SinceParameterizedRouteis simply aRoute, two instances can be equal even if their parameter labels differ, so long as each route contains the sameRouteElements in the same order. Moreover, aParameterizedRoutecan be equal to aRoute, as long as the aforementioned condition is true.
-
-
Constructor Summary
Constructors Constructor Description ParameterizedRoute(java.util.List<java.lang.String> parameterLabels, java.util.List<RouteElement> elements)Creates aParameterizedRoutewhere the ith string in the labels list corresponds to the ithWildcardRouteElementin the elements list.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description java.util.Map<java.lang.String,java.lang.String>extractVariablesMap(Path path)Returns a mapping of parameters to arguments given somePathwhose structure matches theRouterepresented by thisParameterizedRoute.java.util.List<java.lang.String>getParameterLabels()static ParameterizedRouteparse(java.lang.String routeString)Constructs aParameterizedRoutegiven a parameterized route string.-
Methods inherited from class com.duncpro.jroute.route.Route
concat, equals, extractVariables, extractVariables, getElements, hashCode, isRoot, resolve, toString, withLeadingElement, withoutLeadingElement, withTrailingElement
-
-
-
-
Constructor Detail
-
ParameterizedRoute
public ParameterizedRoute(java.util.List<java.lang.String> parameterLabels, java.util.List<RouteElement> elements)Creates aParameterizedRoutewhere the ith string in the labels list corresponds to the ithWildcardRouteElementin the elements list. See alsoparse(String), which constructs aParameterizedRoutefrom a human-readable parameterized route string.
-
-
Method Detail
-
getParameterLabels
public java.util.List<java.lang.String> getParameterLabels()
-
extractVariablesMap
public java.util.Map<java.lang.String,java.lang.String> extractVariablesMap(Path path)
Returns a mapping of parameters to arguments given somePathwhose structure matches theRouterepresented by thisParameterizedRoute. For example a parameterized route string of '/customers/{customerId}/orders/{orderId}', and path of "/customers/duncan/orders/abc123" would result in a return value of [(customerId, duncan), (orderId, abc123)].
-
parse
public static ParameterizedRoute parse(java.lang.String routeString)
Constructs aParameterizedRoutegiven a parameterized route string. For example: "/customers/{customerId}/orders/{orderId}".- Throws:
java.lang.IllegalArgumentException- if the route string is malformed.
-
-