1515import java .util .regex .Pattern ;
1616
1717public class Route {
18+
19+ private String name ;
1820 private final RouteParamTransformerProvider routeParamTransformerProvider ;
1921 private final HTTPMethod method ;
20- private final Pattern pattern ;
22+ private final String pattern ;
23+ private final Pattern compiledPattern ;
2124 private final Map <String , String > variables = new HashMap <>();
2225 private List <RequestHandler > handlers ;
2326 private List <AfterRequestHandler > afterHandlers ;
@@ -30,6 +33,7 @@ public Route(RouteParamTransformerProvider routeParamTransformerProvider, HTTPMe
3033 this .handlers = handlers ;
3134 this .method = method ;
3235 this .routeParamTransformerProvider = routeParamTransformerProvider ;
36+ this .pattern = pattern ;
3337 pattern = pattern .toLowerCase (Locale .ENGLISH );
3438 if (options .isIgnoreTrailingSlash ()) {
3539 if (pattern .endsWith ("/" ))
@@ -90,22 +94,39 @@ public Route(RouteParamTransformerProvider routeParamTransformerProvider, HTTPMe
9094 if (options .isIgnoreTrailingSlash ()) {
9195 sb .append ("/?" );
9296 }
93- this .pattern = Pattern .compile (sb .toString ());
97+ this .compiledPattern = Pattern .compile (sb .toString ());
98+ }
99+
100+ public Route setName (String name ) {
101+ this .name = name ;
102+ return this ;
103+ }
104+
105+ public String getName () {
106+ return name ;
94107 }
95108
96109 public Route setAfterHandlers (List <AfterRequestHandler > afterHandlers ) {
97110 this .afterHandlers = afterHandlers ;
98111 return this ;
99112 }
100113
114+ public String getPattern () {
115+ return pattern ;
116+ }
117+
118+ public Map <String , String > getVariables () {
119+ return variables ;
120+ }
121+
101122 public Map <String , Object > match (Exchange exchange ) {
102123 return match (exchange , exchange .getMethod (), exchange .getPath ());
103124 }
104125
105126 public Map <String , Object > match (Exchange exchange , HTTPMethod method , String path ) {
106127 if (this .method != method )
107128 return null ;
108- Matcher matcher = pattern .matcher (path );
129+ Matcher matcher = compiledPattern .matcher (path );
109130 if (matcher .matches ()) {
110131 Map <String , Object > params = new HashMap <>();
111132 for (String name : variables .keySet ()) {
0 commit comments