18
18
import java .util .ArrayList ;
19
19
import java .util .Collections ;
20
20
import java .util .HashSet ;
21
+ import java .util .LinkedHashSet ;
22
+ import java .util .LinkedList ;
21
23
import java .util .List ;
22
24
import java .util .Set ;
23
25
import java .util .regex .Pattern ;
26
28
* A simple Trie, which accepts a trailing wildcard
27
29
*
28
30
* @author Markus Michael Geipel
31
+ * @author Pascal Christoph
29
32
*
30
33
* @param <P>
31
34
* type of value stored
@@ -77,7 +80,6 @@ private void simplyPut(final String key, final P value) {
77
80
78
81
public List <P > get (final String key ) {
79
82
80
-
81
83
nodes .add (root );
82
84
final int length = key .length ();
83
85
for (int i = 0 ; i < length ; ++i ) {
@@ -130,7 +132,7 @@ public List<P> get(final String key) {
130
132
*/
131
133
private final class Node <T > {
132
134
133
- private List <T > values = Collections . emptyList ();
135
+ private LinkedHashSet <T > values = new LinkedHashSet < T > ();
134
136
private final CharMap <Node <T >> links = new CharMap <Node <T >>();
135
137
136
138
protected Node () {
@@ -143,19 +145,18 @@ public Node<T> addNext(final char key) {
143
145
if (key == STAR_WILDCARD ) {
144
146
next .links .put (STAR_WILDCARD , next );
145
147
}
146
-
147
148
return next ;
148
149
}
149
150
150
151
public void addValue (final T value ) {
151
152
if (values == Collections .emptyList ()) {
152
- values = new ArrayList <T >();
153
+ values = new LinkedHashSet <T >();
153
154
}
154
155
this .values .add (value );
155
156
}
156
157
157
158
public List <T > getValues () {
158
- return values ;
159
+ return new LinkedList < T >( values ) ;
159
160
}
160
161
161
162
public Node <T > getNext (final char key ) {
0 commit comments