@@ -140,16 +140,7 @@ public Set<Rule.Phoneme> getPhonemes() {
140140 * @return the stringified phoneme set
141141 */
142142 public String makeString () {
143- final StringBuilder sb = new StringBuilder ();
144-
145- for (final Rule .Phoneme ph : this .phonemes ) {
146- if (sb .length () > 0 ) {
147- sb .append ("|" );
148- }
149- sb .append (ph .getPhonemeText ());
150- }
151-
152- return sb .toString ();
143+ return phonemes .stream ().map (Rule .Phoneme ::getPhonemeText ).collect (Collectors .joining ("|" ));
153144 }
154145 }
155146
@@ -314,22 +305,20 @@ public PhoneticEngine(final NameType nameType, final RuleType ruleType, final bo
314305 * @return the resulting phonemes
315306 */
316307 private PhonemeBuilder applyFinalRules (final PhonemeBuilder phonemeBuilder ,
317- final Map <String , List <Rule >> finalRules ) {
308+ final Map <String , List <Rule >> finalRules ) {
318309 Objects .requireNonNull (finalRules , "finalRules" );
319310 if (finalRules .isEmpty ()) {
320311 return phonemeBuilder ;
321312 }
322313
323- final Map <Rule .Phoneme , Rule .Phoneme > phonemes =
324- new TreeMap <>(Rule .Phoneme .COMPARATOR );
314+ final Map <Rule .Phoneme , Rule .Phoneme > phonemes = new TreeMap <>(Rule .Phoneme .COMPARATOR );
325315
326- for ( final Rule . Phoneme phoneme : phonemeBuilder .getPhonemes ()) {
316+ phonemeBuilder .getPhonemes (). forEach ( phoneme -> {
327317 PhonemeBuilder subBuilder = PhonemeBuilder .empty (phoneme .getLanguages ());
328318 final String phonemeText = phoneme .getPhonemeText ().toString ();
329319
330320 for (int i = 0 ; i < phonemeText .length ();) {
331- final RulesApplication rulesApplication =
332- new RulesApplication (finalRules , phonemeText , subBuilder , i , maxPhonemes ).invoke ();
321+ final RulesApplication rulesApplication = new RulesApplication (finalRules , phonemeText , subBuilder , i , maxPhonemes ).invoke ();
333322 final boolean found = rulesApplication .isFound ();
334323 subBuilder = rulesApplication .getPhonemeBuilder ();
335324
@@ -344,16 +333,16 @@ private PhonemeBuilder applyFinalRules(final PhonemeBuilder phonemeBuilder,
344333 // the phonemes map orders the phonemes only based on their text, but ignores the language set
345334 // when adding new phonemes, check for equal phonemes and merge their language set, otherwise
346335 // phonemes with the same text but different language set get lost
347- for ( final Rule . Phoneme newPhoneme : subBuilder .getPhonemes ()) {
336+ subBuilder .getPhonemes (). forEach ( newPhoneme -> {
348337 if (phonemes .containsKey (newPhoneme )) {
349338 final Rule .Phoneme oldPhoneme = phonemes .remove (newPhoneme );
350339 final Rule .Phoneme mergedPhoneme = oldPhoneme .mergeWithLanguage (newPhoneme .getLanguages ());
351340 phonemes .put (mergedPhoneme , mergedPhoneme );
352341 } else {
353342 phonemes .put (newPhoneme , newPhoneme );
354343 }
355- }
356- }
344+ });
345+ });
357346
358347 return new PhonemeBuilder (phonemes .keySet ());
359348 }
@@ -414,11 +403,10 @@ public String encode(String input, final Languages.LanguageSet languageSet) {
414403 // special-case handling of word prefixes based upon the name type
415404 switch (this .nameType ) {
416405 case SEPHARDIC :
417- for ( final String aWord : words ) {
406+ words . forEach ( aWord -> {
418407 final String [] parts = aWord .split ("'" );
419- final String lastPart = parts [parts .length - 1 ];
420- words2 .add (lastPart );
421- }
408+ words2 .add (parts [parts .length - 1 ]);
409+ });
422410 words2 .removeAll (NAME_PREFIXES .get (this .nameType ));
423411 break ;
424412 case ASHKENAZI :
@@ -441,9 +429,7 @@ public String encode(String input, final Languages.LanguageSet languageSet) {
441429 } else {
442430 // encode each word in a multi-word name separately (normally used for approx matches)
443431 final StringBuilder result = new StringBuilder ();
444- for (final String word : words2 ) {
445- result .append ("-" ).append (encode (word ));
446- }
432+ words2 .forEach (word -> result .append ("-" ).append (encode (word )));
447433 // return the result without the leading "-"
448434 return result .substring (1 );
449435 }
0 commit comments