aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorArne Juul <arnej@yahoo-inc.com>2017-11-09 21:16:51 +0000
committerArne Juul <arnej@yahoo-inc.com>2017-11-09 21:16:51 +0000
commit5bc7413e1af6272b172d1ccd293235a2202f368a (patch)
tree6c34a440e614c5548173b3b5c40b0ae6477bdb5c
parent310675a44a01e9f671b06d63a2043cdad2cfc58a (diff)
add the pattern to BindingMatch
-rw-r--r--jdisc_core/src/main/java/com/yahoo/jdisc/application/BindingMatch.java24
-rw-r--r--jdisc_core/src/main/java/com/yahoo/jdisc/application/BindingSet.java5
-rw-r--r--jdisc_core/src/test/java/com/yahoo/jdisc/RequestTestCase.java7
-rw-r--r--jdisc_core/src/test/java/com/yahoo/jdisc/application/BindingMatchTestCase.java14
4 files changed, 40 insertions, 10 deletions
diff --git a/jdisc_core/src/main/java/com/yahoo/jdisc/application/BindingMatch.java b/jdisc_core/src/main/java/com/yahoo/jdisc/application/BindingMatch.java
index 5d4974f2dc4..5d5f40a825a 100644
--- a/jdisc_core/src/main/java/com/yahoo/jdisc/application/BindingMatch.java
+++ b/jdisc_core/src/main/java/com/yahoo/jdisc/application/BindingMatch.java
@@ -15,6 +15,7 @@ public class BindingMatch<T> {
private final UriPattern.Match match;
private final T target;
+ private final UriPattern matched;
/**
* <p>Constructs a new instance of this class.</p>
@@ -24,10 +25,23 @@ public class BindingMatch<T> {
* @throws NullPointerException If any argument is null.
*/
public BindingMatch(UriPattern.Match match, T target) {
+ this(match, target, null);
+ }
+
+ /**
+ * <p>Constructs a new instance of this class.</p>
+ *
+ * @param match The match information for this instance.
+ * @param target The target of this match.
+ * @param matched The matched URI pattern
+ * @throws NullPointerException If any argument is null.
+ */
+ public BindingMatch(UriPattern.Match match, T target, UriPattern matched) {
Objects.requireNonNull(match, "match");
Objects.requireNonNull(target, "target");
this.match = match;
this.target = target;
+ this.matched = matched;
}
/**
@@ -61,4 +75,14 @@ public class BindingMatch<T> {
public T target() {
return target;
}
+
+ /**
+ * <p>Returns the URI pattern that was matched.</p>
+ *
+ * @return The matched pattern.
+ */
+ public UriPattern matched() {
+ return matched;
+ }
+
}
diff --git a/jdisc_core/src/main/java/com/yahoo/jdisc/application/BindingSet.java b/jdisc_core/src/main/java/com/yahoo/jdisc/application/BindingSet.java
index 7a21e204dd3..1e25846f63c 100644
--- a/jdisc_core/src/main/java/com/yahoo/jdisc/application/BindingSet.java
+++ b/jdisc_core/src/main/java/com/yahoo/jdisc/application/BindingSet.java
@@ -38,9 +38,10 @@ public class BindingSet<T> implements Iterable<Map.Entry<UriPattern, T>> {
*/
public BindingMatch<T> match(URI uri) {
for (Map.Entry<UriPattern, T> entry : bindings) {
- UriPattern.Match match = entry.getKey().match(uri);
+ UriPattern pattern = entry.getKey();
+ UriPattern.Match match = pattern.match(uri);
if (match != null) {
- return new BindingMatch<>(match, entry.getValue());
+ return new BindingMatch<>(match, entry.getValue(), pattern);
}
}
return null;
diff --git a/jdisc_core/src/test/java/com/yahoo/jdisc/RequestTestCase.java b/jdisc_core/src/test/java/com/yahoo/jdisc/RequestTestCase.java
index e00bdae153d..cd5e07f1224 100644
--- a/jdisc_core/src/test/java/com/yahoo/jdisc/RequestTestCase.java
+++ b/jdisc_core/src/test/java/com/yahoo/jdisc/RequestTestCase.java
@@ -297,9 +297,10 @@ public class RequestTestCase {
public RequestHandler resolveHandler(Request request) {
this.asServer = request.isServerRequest();
RequestHandler requestHandler = new MyRequestHandler();
- request.setBindingMatch(new BindingMatch<>(
- new UriPattern("http://*/*").match(request.getUri()),
- requestHandler));
+ UriPattern pattern = new UriPattern("http://*/*");
+ request.setBindingMatch(new BindingMatch<>(pattern.match(request.getUri()),
+ requestHandler,
+ pattern));
return requestHandler;
}
diff --git a/jdisc_core/src/test/java/com/yahoo/jdisc/application/BindingMatchTestCase.java b/jdisc_core/src/test/java/com/yahoo/jdisc/application/BindingMatchTestCase.java
index 582a1c6685e..21a3ae08c49 100644
--- a/jdisc_core/src/test/java/com/yahoo/jdisc/application/BindingMatchTestCase.java
+++ b/jdisc_core/src/test/java/com/yahoo/jdisc/application/BindingMatchTestCase.java
@@ -18,32 +18,36 @@ public class BindingMatchTestCase {
@Test
public void requireThatAccessorsWork() {
Object obj = new Object();
+ UriPattern pattern = new UriPattern("http://*/*");
BindingMatch<Object> match = new BindingMatch<>(
- new UriPattern("http://*/*").match(URI.create("http://localhost:69/status.html")),
- obj);
+ pattern.match(URI.create("http://localhost:69/status.html")),
+ obj, pattern);
assertSame(obj, match.target());
assertEquals(3, match.groupCount());
assertEquals("localhost", match.group(0));
assertEquals("69", match.group(1));
assertEquals("status.html", match.group(2));
+ assertEquals(pattern, match.matched());
}
@Test
public void requireThatConstructorArgumentsCanNotBeNull() {
try {
- new BindingMatch<>(null, null);
+ new BindingMatch<>(null, null, null);
fail();
} catch (NullPointerException e) {
}
try {
- new BindingMatch<>(new UriPattern("http://*/*").match(URI.create("http://localhost/")), null);
+ UriPattern pattern = new UriPattern("http://*/*");
+ new BindingMatch<>(pattern.match(URI.create("http://localhost/")), null, pattern);
fail();
} catch (NullPointerException e) {
}
try {
- new BindingMatch<>(null, new Object());
+ UriPattern pattern = new UriPattern("http://*/*");
+ new BindingMatch<>(null, new Object(), pattern);
fail();
} catch (NullPointerException e) {