2020import org .metafacture .commons .tries .WildcardTrie ;
2121
2222import java .util .ArrayList ;
23- import java .util .Arrays ;
2423import java .util .Collection ;
2524import java .util .ConcurrentModificationException ;
25+ import java .util .EnumSet ;
2626import java .util .HashMap ;
2727import java .util .HashSet ;
2828import java .util .LinkedHashMap ;
@@ -306,10 +306,9 @@ enum Type {
306306
307307 public static class TypeMatcher {
308308
309+ private final Set <Type > expected = EnumSet .noneOf (Type .class );
309310 private final Value value ;
310311
311- private byte expected ; // NOTE: Covers at most 7 `Type`s.
312-
313312 private TypeMatcher (final Value value ) {
314313 this .value = value ;
315314 }
@@ -327,26 +326,20 @@ public TypeMatcher ifString(final Consumer<String> consumer) {
327326 }
328327
329328 public void orElse (final Consumer <Value > consumer ) {
330- if (!expecting (value .type )) {
329+ if (!expected . contains (value .type )) {
331330 consumer .accept (value );
332331 }
333332 }
334333
335334 public void orElseThrow () {
336335 orElse (v -> {
337- final String types = Arrays .stream (Type .values ()).filter (this ::expecting )
338- .map (Type ::name ).collect (Collectors .joining (" or " ));
339-
336+ final String types = expected .stream ().map (Type ::name ).collect (Collectors .joining (" or " ));
340337 throw new IllegalStateException ("Expected " + types + ", got " + value .type );
341338 });
342339 }
343340
344341 private <T > TypeMatcher match (final Type type , final Consumer <T > consumer , final T rawValue ) {
345- final byte newExpected = (byte ) (expected | bit (type ));
346-
347- if (expected != newExpected ) {
348- expected = newExpected ;
349-
342+ if (expected .add (type )) {
350343 if (value .isType (type )) {
351344 consumer .accept (rawValue );
352345 }
@@ -358,14 +351,6 @@ private <T> TypeMatcher match(final Type type, final Consumer<T> consumer, final
358351 }
359352 }
360353
361- private boolean expecting (final Type type ) {
362- return (expected & bit (type )) != 0 ;
363- }
364-
365- private byte bit (final Type type ) {
366- return (byte ) (1 << type .ordinal ());
367- }
368-
369354 }
370355
371356 private abstract static class AbstractValueType {
0 commit comments