RobotCore 1.0
WPILib port to raspberry Pi
Loading...
Searching...
No Matches
PrefixMap.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;
18
19import java.util.Collection;
20import java.util.Iterator;
21import java.util.Map;
22import java.util.PrimitiveIterator;
23import java.util.Set;
24import java.util.stream.IntStream;
25
43public interface PrefixMap<V> extends Map<String, V> {
49 @Override
50 int size();
51
57 @Override
58 default boolean isEmpty() {
59 return size() == 0;
60 }
61
69 @Override
70 default void putAll(Map<? extends String, ? extends V> prefixesAndValues) {
71 prefixesAndValues.forEach(this::put);
72 }
73
87 @Override
88 V put(String prefix, V value);
89
97 default V remove(String prefix) {
98 throw new UnsupportedOperationException(
99 "The 'remove(String prefix)' method has not been implemented in "
100 + this.getClass().getCanonicalName());
101 }
102
103 @Override
104 default V remove(Object o) {
105 if (o instanceof String) {
106 return remove((String) o);
107 }
108 return null;
109 }
110
111 @Override
112 default boolean containsKey(Object o) {
113 throw new UnsupportedOperationException(
114 "The 'containsKey(Object o)' method has not been implemented in "
115 + this.getClass().getCanonicalName());
116 }
117
118 @Override
119 default boolean containsValue(Object o) {
120 throw new UnsupportedOperationException(
121 "The 'containsValue(Object o)' method has not been implemented in "
122 + this.getClass().getCanonicalName());
123 }
124
134 V get(String prefix);
135
145 @Override
146 default V get(Object prefix) {
147 if (prefix instanceof String) {
148 return get((String) prefix);
149 }
150 return null;
151 }
152
153 @Override
154 default Set<String> keySet() {
155 throw new UnsupportedOperationException(
156 "The 'keySet()' method has not been implemented in " + this.getClass().getCanonicalName());
157 }
158
159 @Override
160 default Collection<V> values() {
161 throw new UnsupportedOperationException(
162 "The 'values()' method has not been implemented in " + this.getClass().getCanonicalName());
163 }
164
171 @Override
172 default void clear() {
173 throw new UnsupportedOperationException(
174 "The 'clear()' method has not been implemented in " + this.getClass().getCanonicalName());
175 }
176
183 default boolean containsPrefix(String prefix) {
184 return containsPrefix(prefix.codePoints().iterator());
185 }
186
193 default boolean containsPrefix(int[] prefix) {
194 return containsPrefix(IntStream.of(prefix).iterator());
195 }
196
203 boolean containsPrefix(PrimitiveIterator.OfInt prefix);
204
214 default V getShortestMatch(String input) {
215 return getShortestMatch(input.codePoints().iterator());
216 }
217
228 default V getShortestMatch(int[] input) {
229 return getShortestMatch(IntStream.of(input).iterator());
230 }
231
242 V getShortestMatch(PrimitiveIterator.OfInt input);
243
253 default V getLongestMatch(String input) {
254 return getLongestMatch(input.codePoints().iterator());
255 }
256
267 default V getLongestMatch(int[] input) {
268 return getLongestMatch(IntStream.of(input).iterator());
269 }
270
281 V getLongestMatch(PrimitiveIterator.OfInt input);
282
292 default Iterator<V> getAllMatches(String input) {
293 return getAllMatches(input.codePoints().iterator());
294 }
295
306 default Iterator<V> getAllMatches(int[] input) {
307 return getAllMatches(IntStream.of(input).iterator());
308 }
309
320 Iterator<V> getAllMatches(PrimitiveIterator.OfInt input);
321}
default boolean containsPrefix(String prefix)
default V getShortestMatch(int[] input)
V put(String prefix, V value)
default Iterator< V > getAllMatches(int[] input)
default V getLongestMatch(int[] input)
V getLongestMatch(PrimitiveIterator.OfInt input)
default void putAll(Map<? extends String, ? extends V > prefixesAndValues)
Iterator< V > getAllMatches(PrimitiveIterator.OfInt input)
V getShortestMatch(PrimitiveIterator.OfInt input)
default Iterator< V > getAllMatches(String input)
default V getLongestMatch(String input)
default V getShortestMatch(String input)
default boolean containsPrefix(int[] prefix)
boolean containsPrefix(PrimitiveIterator.OfInt prefix)