8181public class Rule {
8282
8383 public static final class Phoneme implements PhonemeExpr {
84- public static final Comparator <Phoneme > COMPARATOR = new Comparator <Phoneme >() {
85- @ Override
86- public int compare (final Phoneme o1 , final Phoneme o2 ) {
87- final int o1Length = o1 .phonemeText .length ();
88- final int o2Length = o2 .phonemeText .length ();
89- for (int i = 0 ; i < o1Length ; i ++) {
90- if (i >= o2Length ) {
91- return +1 ;
92- }
93- final int c = o1 .phonemeText .charAt (i ) - o2 .phonemeText .charAt (i );
94- if (c != 0 ) {
95- return c ;
96- }
84+ public static final Comparator <Phoneme > COMPARATOR = (o1 , o2 ) -> {
85+ final int o1Length = o1 .phonemeText .length ();
86+ final int o2Length = o2 .phonemeText .length ();
87+ for (int i = 0 ; i < o1Length ; i ++) {
88+ if (i >= o2Length ) {
89+ return +1 ;
9790 }
98-
99- if (o1Length < o2Length ) {
100- return - 1 ;
91+ final int c = o1 . phonemeText . charAt ( i ) - o2 . phonemeText . charAt ( i );
92+ if (c != 0 ) {
93+ return c ;
10194 }
95+ }
10296
103- return 0 ;
97+ if (o1Length < o2Length ) {
98+ return -1 ;
10499 }
100+
101+ return 0 ;
105102 };
106103
107104 private final StringBuilder phonemeText ;
@@ -194,12 +191,7 @@ public interface RPattern {
194191 boolean isMatch (CharSequence input );
195192 }
196193
197- public static final RPattern ALL_STRINGS_RMATCHER = new RPattern () {
198- @ Override
199- public boolean isMatch (final CharSequence input ) {
200- return true ;
201- }
202- };
194+ public static final RPattern ALL_STRINGS_RMATCHER = input -> true ;
203195
204196 public static final String ALL = "ALL" ;
205197
@@ -465,11 +457,7 @@ public String toString() {
465457 }
466458 };
467459 final String patternKey = r .pattern .substring (0 ,1 );
468- List <Rule > rules = lines .get (patternKey );
469- if (rules == null ) {
470- rules = new ArrayList <>();
471- lines .put (patternKey , rules );
472- }
460+ final List <Rule > rules = lines .computeIfAbsent (patternKey , k -> new ArrayList <>());
473461 rules .add (r );
474462 } catch (final IllegalArgumentException e ) {
475463 throw new IllegalStateException ("Problem parsing line '" + currentLine + "' in " +
@@ -500,41 +488,21 @@ private static RPattern pattern(final String regex) {
500488 // exact match
501489 if (content .isEmpty ()) {
502490 // empty
503- return new RPattern () {
504- @ Override
505- public boolean isMatch (final CharSequence input ) {
506- return input .length () == 0 ;
507- }
508- };
491+ return input -> input .length () == 0 ;
509492 }
510- return new RPattern () {
511- @ Override
512- public boolean isMatch (final CharSequence input ) {
513- return input .equals (content );
514- }
515- };
493+ return input -> input .equals (content );
516494 }
517495 if ((startsWith || endsWith ) && content .isEmpty ()) {
518496 // matches every string
519497 return ALL_STRINGS_RMATCHER ;
520498 }
521499 if (startsWith ) {
522500 // matches from start
523- return new RPattern () {
524- @ Override
525- public boolean isMatch (final CharSequence input ) {
526- return startsWith (input , content );
527- }
528- };
501+ return input -> startsWith (input , content );
529502 }
530503 if (endsWith ) {
531504 // matches from start
532- return new RPattern () {
533- @ Override
534- public boolean isMatch (final CharSequence input ) {
535- return endsWith (input , content );
536- }
537- };
505+ return input -> endsWith (input , content );
538506 }
539507 } else {
540508 final boolean startsWithBox = content .startsWith ("[" );
@@ -553,31 +521,16 @@ public boolean isMatch(final CharSequence input) {
553521
554522 if (startsWith && endsWith ) {
555523 // exact match
556- return new RPattern () {
557- @ Override
558- public boolean isMatch (final CharSequence input ) {
559- return input .length () == 1 && contains (bContent , input .charAt (0 )) == shouldMatch ;
560- }
561- };
524+ return input -> input .length () == 1 && contains (bContent , input .charAt (0 )) == shouldMatch ;
562525 }
563526 if (startsWith ) {
564527 // first char
565- return new RPattern () {
566- @ Override
567- public boolean isMatch (final CharSequence input ) {
568- return input .length () > 0 && contains (bContent , input .charAt (0 )) == shouldMatch ;
569- }
570- };
528+ return input -> input .length () > 0 && contains (bContent , input .charAt (0 )) == shouldMatch ;
571529 }
572530 if (endsWith ) {
573531 // last char
574- return new RPattern () {
575- @ Override
576- public boolean isMatch (final CharSequence input ) {
577- return input .length () > 0 &&
578- contains (bContent , input .charAt (input .length () - 1 )) == shouldMatch ;
579- }
580- };
532+ return input -> input .length () > 0 &&
533+ contains (bContent , input .charAt (input .length () - 1 )) == shouldMatch ;
581534 }
582535 }
583536 }
0 commit comments