RobotCore 1.0
WPILib port to raspberry Pi
Loading...
Searching...
No Matches
PrefixTrie.java
1/*
2 * Copyright (C) 2018-2021 Niels Basjes
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * https://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package org.wpilib.util.collections.prefixmap;
18
19import java.util.Iterator;
20import java.util.Objects;
21import java.util.PrimitiveIterator;
22
23interface PrefixTrie<V> {
31 default V add(String prefix, V value) {
32 Objects.requireNonNull(prefix, "The prefix may not be null");
33 Objects.requireNonNull(value, "The value may not be null");
34 return add(prefix.codePoints().iterator(), value);
35 }
36
44 V add(PrimitiveIterator.OfInt prefix, V value);
45
46 // ====================================================
47
54 default V remove(String prefix) {
55 Objects.requireNonNull(prefix, "The prefix may not be null");
56 return remove(prefix.codePoints().iterator());
57 }
58
65 default V remove(PrimitiveIterator.OfInt prefix) {
66 throw new UnsupportedOperationException(
67 "The 'remove(PrimitiveIterator.OfInt prefix)' method has not been implemented in "
68 + this.getClass().getCanonicalName());
69 }
70
71 // ====================================================
72
79 default boolean containsPrefix(String prefix) {
80 return get(prefix) != null;
81 }
82
90 default boolean containsPrefix(PrimitiveIterator.OfInt prefix) {
91 return get(prefix) != null;
92 }
93
94 // ====================================================
95
105 default V get(String input) {
106 Objects.requireNonNull(input, "The input may not be null");
107 return get(input.codePoints().iterator());
108 }
109
120 V get(PrimitiveIterator.OfInt input);
121
122 // ====================================================
123
133 default V getShortestMatch(String input) {
134 Objects.requireNonNull(input, "The input may not be null");
135 return getShortestMatch(input.codePoints().iterator());
136 }
137
147 V getShortestMatch(PrimitiveIterator.OfInt input);
148
149 // ====================================================
150
160 default V getLongestMatch(String input) {
161 Objects.requireNonNull(input, "The input may not be null");
162 return getLongestMatch(input.codePoints().iterator());
163 }
164
174 V getLongestMatch(PrimitiveIterator.OfInt input);
175
176 // ====================================================
177
187 default Iterator<V> getAllMatches(String input) {
188 Objects.requireNonNull(input, "The input may not be null");
189 return getAllMatches(input.codePoints().iterator());
190 }
191
201 Iterator<V> getAllMatches(PrimitiveIterator.OfInt input);
202
203 // ====================================================
204
206 void clear();
207}
V getShortestMatch(PrimitiveIterator.OfInt input)
default V add(String prefix, V value)
V getLongestMatch(PrimitiveIterator.OfInt input)
default boolean containsPrefix(String prefix)
default Iterator< V > getAllMatches(String input)
Iterator< V > getAllMatches(PrimitiveIterator.OfInt input)
V add(PrimitiveIterator.OfInt prefix, V value)
default boolean containsPrefix(PrimitiveIterator.OfInt prefix)