4444
4545import com .google .common .base .Strings ;
4646import com .google .common .collect .ImmutableList ;
47- import com .google .common .collect .ImmutableMap ;
4847import com .google .common .collect .Lists ;
4948import com .google .common .primitives .Primitives ;
5049import com .google .inject .Key ;
@@ -1058,6 +1057,17 @@ public List<String> vars() {
10581057 return cpattern .vars ();
10591058 }
10601059
1060+ /**
1061+ * Indicates if the {@link #pattern()} contains a glob charecter, like <code>?</code>,
1062+ * <code>*</code> or <code>**</code>.
1063+ *
1064+ * @return Indicates if the {@link #pattern()} contains a glob charecter, like <code>?</code>,
1065+ * <code>*</code> or <code>**</code>.
1066+ */
1067+ public boolean glob () {
1068+ return cpattern .glob ();
1069+ }
1070+
10611071 /**
10621072 * Recreate a route path and apply the given variables.
10631073 *
@@ -1113,22 +1123,22 @@ public <T> T attr(final String name) {
11131123 * @return A read only view of attributes.
11141124 */
11151125 public Map <String , Object > attributes () {
1116- return ImmutableMap . copyOf (attributes );
1126+ return Collections . unmodifiableMap (attributes );
11171127 }
11181128
11191129 /**
11201130 * Test if the route matches the given verb, path, content type and accept header.
11211131 *
1122- * @param verb A HTTP verb.
1132+ * @param method A HTTP verb.
11231133 * @param path Current HTTP path.
11241134 * @param contentType The <code>Content-Type</code> header.
11251135 * @param accept The <code>Accept</code> header.
11261136 * @return A route or an empty optional.
11271137 */
1128- public Optional <Route > matches (final String verb ,
1138+ public Optional <Route > matches (final String method ,
11291139 final String path , final MediaType contentType ,
11301140 final List <MediaType > accept ) {
1131- String fpath = verb + path ;
1141+ String fpath = method + path ;
11321142 if (excludes .size () > 0 && excludes (fpath )) {
11331143 return Optional .empty ();
11341144 }
@@ -1139,7 +1149,7 @@ public Optional<Route> matches(final String verb,
11391149 // keep accept when */*
11401150 List <MediaType > produces = result .size () == 1 && result .get (0 ).name ().equals ("*/*" )
11411151 ? accept : this .produces ;
1142- return Optional .of (asRoute (verb , matcher , produces ));
1152+ return Optional .of (asRoute (method , matcher , produces ));
11431153 }
11441154 }
11451155 return Optional .empty ();
@@ -1286,14 +1296,14 @@ private boolean excludes(final String path) {
12861296 * @return All the types this route can consumes.
12871297 */
12881298 public List <MediaType > consumes () {
1289- return ImmutableList . copyOf (this .consumes );
1299+ return Collections . unmodifiableList (this .consumes );
12901300 }
12911301
12921302 /**
12931303 * @return All the types this route can produces.
12941304 */
12951305 public List <MediaType > produces () {
1296- return ImmutableList . copyOf (this .produces );
1306+ return Collections . unmodifiableList (this .produces );
12971307 }
12981308
12991309 @ Override
@@ -1327,8 +1337,7 @@ private Route asRoute(final String method, final RouteMatcher matcher,
13271337 if (filter instanceof AssetProxy ) {
13281338 filter = ((AssetProxy ) filter ).delegate ();
13291339 }
1330- return new RouteImpl (filter , method , matcher .path (), pattern , name , matcher .vars (), consumes ,
1331- produces , attributes , mapper );
1340+ return new RouteImpl (filter , this , method , matcher .path (), produces , matcher .vars (), mapper );
13321341 }
13331342
13341343 }
@@ -1400,6 +1409,21 @@ public <T> T attr(final String name) {
14001409 return route .attr (name );
14011410 }
14021411
1412+ @ Override
1413+ public boolean glob () {
1414+ return route .glob ();
1415+ }
1416+
1417+ @ Override
1418+ public String reverse (final Map <String , Object > vars ) {
1419+ return route .reverse (vars );
1420+ }
1421+
1422+ @ Override
1423+ public String reverse (final Object ... values ) {
1424+ return route .reverse (values );
1425+ }
1426+
14031427 @ Override
14041428 public String toString () {
14051429 return route .toString ();
@@ -2041,6 +2065,31 @@ default <T> T attr(final String name) {
20412065 return (T ) attributes ().get (name );
20422066 }
20432067
2068+ /**
2069+ * Indicates if the {@link #pattern()} contains a glob charecter, like <code>?</code>,
2070+ * <code>*</code> or <code>**</code>.
2071+ *
2072+ * @return Indicates if the {@link #pattern()} contains a glob charecter, like <code>?</code>,
2073+ * <code>*</code> or <code>**</code>.
2074+ */
2075+ boolean glob ();
2076+
2077+ /**
2078+ * Recreate a route path and apply the given variables.
2079+ *
2080+ * @param vars Path variables.
2081+ * @return A route pattern.
2082+ */
2083+ String reverse (final Map <String , Object > vars );
2084+
2085+ /**
2086+ * Recreate a route path and apply the given variables.
2087+ *
2088+ * @param values Path variable values.
2089+ * @return A route pattern.
2090+ */
2091+ String reverse (final Object ... values );
2092+
20442093 /**
20452094 * Normalize a path by removing double or trailing slashes.
20462095 *
0 commit comments