@@ -90,7 +90,7 @@ public MathSymbol parseInfixPrecedenceLevel(int level) throws ExprParseException
9090 Collectors .toUnmodifiableMap (
9191 si -> Objects .requireNonNull (si .infix , "null infix not allowed for parseInfixPrecedenceLevel" ),
9292 Function .identity ()));
93- String [] infixesToFind = sortByLength (infixToSymbolInfo .keySet ().toArray (String []::new ));
93+ String [] infixesToFind = sortedByLength (infixToSymbolInfo .keySet ().toArray (String []::new ));
9494 MathSymbol left = parseInfixPrecedenceLevel (level - 1 );
9595 String op ;
9696
@@ -181,21 +181,26 @@ protected boolean matchesNext(@NotNull String expected) {
181181 return src .startsWith (expected , /*start*/ idx );
182182 }
183183
184- private @ NotNull String @ NotNull [] sortByLength (@ NotNull String @ NotNull [] arr ) {
184+ private @ NotNull String @ NotNull [] sortedByLength (@ NotNull String @ NotNull [] arr ) {
185185 return Arrays .stream (arr ).sorted (Comparator .comparingInt (String ::length ).reversed ()).toArray (String []::new );
186186 }
187187 private @ Nullable String matchesNextAny_optionsSorted (@ NotNull String ... expected ) {
188188 return Arrays .stream (expected ).filter (this ::matchesNext ).findFirst ().orElse (null );
189189 }
190190 private @ Nullable String discardMatchesNextAny_optionsSorted (@ NotNull String ... expected ) {
191- String s = Arrays . stream (expected ). filter ( this :: matchesNext ). findFirst (). orElse ( null );
191+ String s = matchesNextAny_optionsSorted (expected );
192192 if (s != null ) discardN (s .length ());
193193 return s ;
194194 }
195+ @ SuppressWarnings ("unused" )
195196 protected @ Nullable String matchesNextAny (@ NotNull String ... expected ) {
196197 // Try to longer ones first, then shorter ones.
197- return matchesNextAny_optionsSorted (
198- Arrays .stream (expected ).sorted (Comparator .comparingInt (String ::length ).reversed ()).toArray (String []::new ));
198+ return matchesNextAny_optionsSorted (sortedByLength (expected ));
199+ }
200+ @ SuppressWarnings ("unused" )
201+ protected @ Nullable String discardMatchesNextAny (@ NotNull String ... expected ) {
202+ // Try to longer ones first, then shorter ones.
203+ return discardMatchesNextAny_optionsSorted (sortedByLength (expected ));
199204 }
200205 // endregion
201206}
0 commit comments