@@ -197,16 +197,6 @@ public List<ReplacerConfig> getReplacerConfigList() {
197197 return new ArrayList <>(replacerConfigList );
198198 }
199199
200- public int getReplacesCount () {
201- int count = 0 ;
202- for (ReplacerConfig replacerConfig : replacerConfigList ) {
203- if (replacerConfig .isEnabled ()) {
204- count = count + replacerConfig .getReplaces (ReplaceMode .COMMON ).size ();
205- }
206- }
207- return count ;
208- }
209-
210200 public void saveReplacerConfigs () {
211201 for (ReplacerConfig replacerConfig : replacerConfigList ) {
212202 if (replacerConfig .isEdited ()) {
@@ -475,42 +465,44 @@ private String getReplaced(@Nonnull String string, @Nonnull ReplacerConfig repla
475465 Validate .notNull (replacerConfig , "Replacer File cannot be null" );
476466 Validate .notNull (replaceMode , "Replaces Mode cannot be null" );
477467
478- if (replacerConfig .getMatchMode () == MatchMode .CONTAIN ) {
479- // Using Aho-Corasick algorithm.
480- int i = 0 ;
468+ switch (replacerConfig .getMatchMode ()) {
469+ case CONTAIN :
470+ // Using Aho-Corasick algorithm.
471+ int i = 0 ;
481472
482- StringBuilder resultBuilder = new StringBuilder ();
483- for (Emit <String > emit : replacerConfig .getReplacesStringSearcher (replaceMode ).parseText (string )) {
484- if (emit .getStart () > i ) {
485- resultBuilder .append (string , i , emit .getStart ());
473+ StringBuilder resultBuilder = new StringBuilder ();
474+ for (Emit <String > emit : replacerConfig .getReplacesStringSearcher (replaceMode ).parseText (string )) {
475+ if (emit .getStart () > i ) {
476+ resultBuilder .append (string , i , emit .getStart ());
477+ }
478+ resultBuilder .append (emit .getPayload ());
479+ i = emit .getEnd () + 1 ;
486480 }
487- resultBuilder .append (emit .getPayload ());
488- i = emit .getEnd () + 1 ;
489- }
490481
491- if (i < string .length ()) {
492- resultBuilder .append (string .substring (i ));
493- }
482+ if (i < string .length ()) {
483+ resultBuilder .append (string .substring (i ));
484+ }
494485
495- return resultBuilder .toString ();
486+ return resultBuilder .toString ();
496487
497- } else if ( replacerConfig . getMatchMode () == MatchMode . EQUAL ) {
498- Object get = replacerConfig .getReplaces (replaceMode ).get (string );
499- if (get != null ) {
500- return (String ) get ;
501- }
502- return string ;
503- } else if ( replacerConfig . getMatchMode () == MatchMode . REGEX ) {
504- String result = string ;
488+ case EQUAL :
489+ Object get = replacerConfig .getReplaces (replaceMode ).get (string );
490+ if (get != null ) {
491+ return (String ) get ;
492+ }
493+ return string ;
494+ case REGEX :
495+ String result = string ;
505496
506- @ SuppressWarnings ("unchecked" )
507- Set <Map .Entry <Pattern , String >> set = replacerConfig .getReplaces (replaceMode ).entrySet ();
508- for (Map .Entry <Pattern , String > entry : set ) {
509- result = entry .getKey ().matcher (result ).replaceAll (entry .getValue ());
510- }
511- return result ;
497+ @ SuppressWarnings ("unchecked" )
498+ Set <Map .Entry <Pattern , String >> set = replacerConfig .getReplaces (replaceMode ).entrySet ();
499+ for (Map .Entry <Pattern , String > entry : set ) {
500+ result = entry .getKey ().matcher (result ).replaceAll (entry .getValue ());
501+ }
502+ return result ;
503+ default :
504+ throw new AssertionError ();
512505 }
513- throw new AssertionError ();
514506 }
515507
516508 public boolean getBlocked (@ Nonnull String string , @ Nonnull ReplacerConfig replacerConfig , @ Nonnull ReplaceMode replaceMode ) {
@@ -531,11 +523,10 @@ public boolean getBlocked(@Nonnull String string, @Nonnull ReplacerConfig replac
531523 return true ;
532524 }
533525 }
534- break ;
526+ return false ;
535527 default :
536528 throw new AssertionError ();
537529 }
538- return false ;
539530 }
540531
541532}
0 commit comments