blob: 679fb52f0e76407e605948671592c2aad8c4bc18 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
|
// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.jdisc.application;
import java.net.URI;
import java.util.Objects;
/**
* <p>This class holds the result of a {@link BindingSet#match(URI)} operation. It contains methods to inspect the
* groups captured during matching, where a <em>group</em> is defined as a sequence of characters matches by a wildcard
* in the {@link UriPattern}, and to retrieve the matched target.</p>
*
* @param <T> The class of the target.
*/
public class BindingMatch<T> {
private final UriPattern.Match match;
private final T target;
/**
* <p>Constructs a new instance of this class.</p>
*
* @param match The match information for this instance.
* @param target The target of this match.
* @throws NullPointerException If any argument is null.
*/
public BindingMatch(UriPattern.Match match, T target) {
Objects.requireNonNull(match, "match");
Objects.requireNonNull(target, "target");
this.match = match;
this.target = target;
}
/**
* <p>Returns the number of captured groups of this match. Any non-negative integer smaller than the value returned
* by this method is a valid group index for this match.</p>
*
* @return The number of captured groups.
*/
public int groupCount() {
return match.groupCount();
}
/**
* <p>Returns the input subsequence captured by the given group by this match. Groups are indexed from left to
* right, starting at zero. Note that some groups may match an empty string, in which case this method returns the
* empty string. This method never returns null.</p>
*
* @param idx The index of the group to return.
* @return The (possibly empty) substring captured by the group during matching, never <tt>null</tt>.
* @throws IndexOutOfBoundsException If there is no group in the match with the given index.
*/
public String group(int idx) {
return match.group(idx);
}
/**
* <p>Returns the matched target.</p>
*
* @return The matched target.
*/
public T target() {
return target;
}
}
|