blob: 2fec5f0773686f18c804017e257c28904c0191ed (
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
|
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.container.handler;
/**
* Wrapper to maintain indirections between prefixes and Handler instances.
*
* @author Steinar Knutsen
*/
public final class Prefix implements Comparable<Prefix> {
public final String prefix;
public final String[] elements;
public final String handler;
public Prefix(String prefix, String handler) {
super();
this.prefix = prefix;
this.elements = prefix.split("/");
this.handler = handler;
}
public Prefix(String prefix) {
this(prefix, null);
}
public boolean hasAnyCommonPrefix(String router) {
return router.codePointAt(0) == prefix.codePointAt(0);
}
@Override
public int compareTo(Prefix other) {
return prefix.compareTo(other.prefix);
}
public boolean matches(String path) {
String[] pathElements = path.split("/");
if (pathElements.length < elements.length) {
return false;
}
for (int i = 0; i < elements.length; ++i) {
if (!(elements[i].equals(pathElements[i]))) {
return false;
}
}
return true;
}
@Override
public String toString() {
return prefix + ": " + handler;
}
}
|