mirror of
https://github.com/metosin/reitit.git
synced 2026-02-18 16:55:55 +00:00
Simplied Java, based on review
This commit is contained in:
parent
75065b56e3
commit
ffc6ba8053
1 changed files with 5 additions and 10 deletions
|
|
@ -52,7 +52,7 @@ public class SegmentTrie {
|
||||||
|
|
||||||
private Map<String, SegmentTrie> childs = new HashMap<>();
|
private Map<String, SegmentTrie> childs = new HashMap<>();
|
||||||
private Map<Keyword, SegmentTrie> wilds = new HashMap<>();
|
private Map<Keyword, SegmentTrie> wilds = new HashMap<>();
|
||||||
private Map<Keyword, SegmentTrie> catchAll = new HashMap<>();
|
private Keyword catchAll = null;
|
||||||
private Object data;
|
private Object data;
|
||||||
|
|
||||||
public SegmentTrie add(String path, Object data) {
|
public SegmentTrie add(String path, Object data) {
|
||||||
|
|
@ -69,12 +69,7 @@ public class SegmentTrie {
|
||||||
pointer = s;
|
pointer = s;
|
||||||
} else if (p.startsWith("*")) {
|
} else if (p.startsWith("*")) {
|
||||||
Keyword k = Keyword.intern(p.substring(1));
|
Keyword k = Keyword.intern(p.substring(1));
|
||||||
SegmentTrie s = pointer.catchAll.get(k);
|
pointer.catchAll = k;
|
||||||
if (s == null) {
|
|
||||||
s = new SegmentTrie();
|
|
||||||
s.data = data;
|
|
||||||
pointer.catchAll.put(k, s);
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
} else {
|
} else {
|
||||||
SegmentTrie s = pointer.childs.get(p);
|
SegmentTrie s = pointer.childs.get(p);
|
||||||
|
|
@ -103,10 +98,10 @@ public class SegmentTrie {
|
||||||
|
|
||||||
public Matcher matcher() {
|
public Matcher matcher() {
|
||||||
Matcher m;
|
Matcher m;
|
||||||
if (!catchAll.isEmpty()) {
|
if (catchAll != null) {
|
||||||
m = new CatchAllMatcher(catchAll.keySet().iterator().next(), data);
|
m = new CatchAllMatcher(catchAll, data);
|
||||||
} else if (!wilds.isEmpty()) {
|
} else if (!wilds.isEmpty()) {
|
||||||
if(wilds.size() == 1 && data == null && childs.isEmpty()) {
|
if (wilds.size() == 1 && data == null && childs.isEmpty()) {
|
||||||
m = new WildMatcher(wilds.keySet().iterator().next(), wilds.values().iterator().next().matcher());
|
m = new WildMatcher(wilds.keySet().iterator().next(), wilds.values().iterator().next().matcher());
|
||||||
} else {
|
} else {
|
||||||
List<Matcher> matchers = new ArrayList<>();
|
List<Matcher> matchers = new ArrayList<>();
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue