You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by gg...@apache.org on 2022/07/17 12:43:19 UTC

[commons-codec] branch master updated (2cab1c5b -> ab7f0792)

This is an automated email from the ASF dual-hosted git repository.

ggregory pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/commons-codec.git


    from 2cab1c5b Bump actions/cache from 3.0.4 to 3.0.5
     new 5e5a627f Long lines
     new ff724b8e Fix Site, RAT, and PMD; declutter the root folder
     new e3bfc84d Use forEach()
     new ab7f0792 Use forEach()

The 4 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .gitattributes                                     | 15 ++++++++
 pom.xml                                            |  6 +++-
 src/conf/checkstyle.xml                            |  2 +-
 pmd.xml => src/conf/pmd.xml                        |  0
 .../codec/language/DaitchMokotoffSoundex.java      |  5 +--
 .../org/apache/commons/codec/language/bm/Lang.java |  4 +--
 .../commons/codec/language/bm/Languages.java       |  9 ++---
 .../commons/codec/language/bm/PhoneticEngine.java  | 42 +++++++---------------
 .../org/apache/commons/codec/language/bm/Rule.java |  8 ++---
 9 files changed, 42 insertions(+), 49 deletions(-)
 rename pmd.xml => src/conf/pmd.xml (100%)


[commons-codec] 02/04: Fix Site, RAT, and PMD; declutter the root folder

Posted by gg...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-codec.git

commit ff724b8e032e8d0d43dea121d02c0e80a70c4656
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Sun Jul 17 08:26:02 2022 -0400

    Fix Site, RAT, and PMD; declutter the root folder
---
 .gitattributes              | 15 +++++++++++++++
 pom.xml                     |  6 +++++-
 pmd.xml => src/conf/pmd.xml |  0
 3 files changed, 20 insertions(+), 1 deletion(-)

diff --git a/.gitattributes b/.gitattributes
index 176a458f..bec231c1 100644
--- a/.gitattributes
+++ b/.gitattributes
@@ -1 +1,16 @@
+#   Licensed to the Apache Software Foundation (ASF) under one or more
+#   contributor license agreements.  See the NOTICE file distributed with
+#   this work for additional information regarding copyright ownership.
+#   The ASF licenses this file to You under the Apache License, Version 2.0
+#   (the "License"); you may not use this file except in compliance with
+#   the License.  You may obtain a copy of the License at
+#
+#       http://www.apache.org/licenses/LICENSE-2.0
+#
+#   Unless required by applicable law or agreed to in writing, software
+#   distributed under the License is distributed on an "AS IS" BASIS,
+#   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+#   See the License for the specific language governing permissions and
+#   limitations under the License.
+
 * text=auto
diff --git a/pom.xml b/pom.xml
index abd7a118..7e268b88 100644
--- a/pom.xml
+++ b/pom.xml
@@ -283,6 +283,7 @@ limitations under the License.
     <commons.encoding>UTF-8</commons.encoding>
     <checkstyle.header.file>${basedir}/src/conf/checkstyle-header.txt</checkstyle.header.file>
     <checkstyle.config.file>${basedir}/src/conf/checkstyle.xml</checkstyle.config.file>
+    <commons.rat.version>0.14</commons.rat.version>
     <commons.checkstyle-plugin.version>3.1.2</commons.checkstyle-plugin.version>
     <commons.checkstyle.version>9.3</commons.checkstyle.version>
     <commons.japicmp.version>0.15.7</commons.japicmp.version>
@@ -291,6 +292,7 @@ limitations under the License.
     <commons.surefire-report.version>3.0.0-M7</commons.surefire-report.version>
     <commons.animal-sniffer.version>1.21</commons.animal-sniffer.version>
     <commons.pmd.version>3.17.0</commons.pmd.version>
+    <commons.pmd-impl.version>6.47.0</commons.pmd-impl.version>
     <japicmp.skip>false</japicmp.skip>
     <jacoco.skip>false</jacoco.skip>
     <clirr.skip>true</clirr.skip>
@@ -346,6 +348,7 @@ limitations under the License.
         <artifactId>apache-rat-plugin</artifactId>
         <configuration>
           <excludes>
+            <exclude>src/test/resources/org/apache/commons/codec/bla.tar</exclude>
             <exclude>src/test/resources/org/apache/commons/codec/bla.tar.xz</exclude>
             <exclude>src/test/resources/org/apache/commons/codec/empty.bin</exclude>
             <exclude>src/test/resources/org/apache/commons/codec/small.bin</exclude>
@@ -420,6 +423,7 @@ limitations under the License.
         <artifactId>apache-rat-plugin</artifactId>
         <configuration>
           <excludes>
+            <exclude>src/test/resources/org/apache/commons/codec/bla.tar</exclude>
             <exclude>src/test/resources/org/apache/commons/codec/bla.tar.xz</exclude>
             <exclude>src/test/resources/org/apache/commons/codec/empty.bin</exclude>
             <exclude>src/test/resources/org/apache/commons/codec/small.bin</exclude>
@@ -446,7 +450,7 @@ limitations under the License.
           <targetJdk>${maven.compiler.target}</targetJdk>
           <linkXref>true</linkXref>
           <rulesets>
-            <ruleset>${basedir}/pmd.xml</ruleset>
+            <ruleset>${basedir}/src/conf/pmd.xml</ruleset>
           </rulesets>
         </configuration>
       </plugin>
diff --git a/pmd.xml b/src/conf/pmd.xml
similarity index 100%
rename from pmd.xml
rename to src/conf/pmd.xml


[commons-codec] 03/04: Use forEach()

Posted by gg...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-codec.git

commit e3bfc84d6fe9838c0f2e8a474736e730074ef444
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Sun Jul 17 08:27:26 2022 -0400

    Use forEach()
---
 src/main/java/org/apache/commons/codec/language/bm/Lang.java     | 4 ++--
 .../java/org/apache/commons/codec/language/bm/Languages.java     | 9 ++-------
 .../org/apache/commons/codec/language/bm/PhoneticEngine.java     | 4 +---
 3 files changed, 5 insertions(+), 12 deletions(-)

diff --git a/src/main/java/org/apache/commons/codec/language/bm/Lang.java b/src/main/java/org/apache/commons/codec/language/bm/Lang.java
index 186f8333..ae63f1cd 100644
--- a/src/main/java/org/apache/commons/codec/language/bm/Lang.java
+++ b/src/main/java/org/apache/commons/codec/language/bm/Lang.java
@@ -205,7 +205,7 @@ public class Lang {
         final String text = input.toLowerCase(Locale.ENGLISH);
 
         final Set<String> langs = new HashSet<>(this.languages.getLanguages());
-        for (final LangRule rule : this.rules) {
+        this.rules.forEach(rule -> {
             if (rule.matches(text)) {
                 if (rule.acceptOnMatch) {
                     langs.retainAll(rule.languages);
@@ -213,7 +213,7 @@ public class Lang {
                     langs.removeAll(rule.languages);
                 }
             }
-        }
+        });
 
         final Languages.LanguageSet ls = Languages.LanguageSet.from(langs);
         return ls.equals(Languages.NO_LANGUAGES) ? Languages.ANY_LANGUAGE : ls;
diff --git a/src/main/java/org/apache/commons/codec/language/bm/Languages.java b/src/main/java/org/apache/commons/codec/language/bm/Languages.java
index 53669df3..6f121ec2 100644
--- a/src/main/java/org/apache/commons/codec/language/bm/Languages.java
+++ b/src/main/java/org/apache/commons/codec/language/bm/Languages.java
@@ -24,6 +24,7 @@ import java.util.Map;
 import java.util.NoSuchElementException;
 import java.util.Scanner;
 import java.util.Set;
+import java.util.stream.Collectors;
 
 import org.apache.commons.codec.Resources;
 
@@ -125,13 +126,7 @@ public class Languages {
                 return this;
             }
             final SomeLanguages someLanguages = (SomeLanguages) other;
-            final Set<String> set = new HashSet<>(Math.min(languages.size(), someLanguages.languages.size()));
-            for (final String lang : languages) {
-                if (someLanguages.languages.contains(lang)) {
-                    set.add(lang);
-                }
-            }
-            return from(set);
+            return from(languages.stream().filter(lang -> someLanguages.languages.contains(lang)).collect(Collectors.toSet()));
         }
 
         @Override
diff --git a/src/main/java/org/apache/commons/codec/language/bm/PhoneticEngine.java b/src/main/java/org/apache/commons/codec/language/bm/PhoneticEngine.java
index 69abac28..8c2163d5 100644
--- a/src/main/java/org/apache/commons/codec/language/bm/PhoneticEngine.java
+++ b/src/main/java/org/apache/commons/codec/language/bm/PhoneticEngine.java
@@ -89,9 +89,7 @@ public class PhoneticEngine {
          * @param str   the characters to append to the phonemes
          */
         public void append(final CharSequence str) {
-            for (final Rule.Phoneme ph : this.phonemes) {
-                ph.append(str);
-            }
+            phonemes.forEach(ph -> ph.append(str));
         }
 
         /**


[commons-codec] 04/04: Use forEach()

Posted by gg...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-codec.git

commit ab7f0792599a625afdefad6796f154cd37db80f9
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Sun Jul 17 08:43:14 2022 -0400

    Use forEach()
---
 .../codec/language/DaitchMokotoffSoundex.java      |  5 +--
 .../commons/codec/language/bm/PhoneticEngine.java  | 38 +++++++---------------
 .../org/apache/commons/codec/language/bm/Rule.java |  8 ++---
 3 files changed, 16 insertions(+), 35 deletions(-)

diff --git a/src/main/java/org/apache/commons/codec/language/DaitchMokotoffSoundex.java b/src/main/java/org/apache/commons/codec/language/DaitchMokotoffSoundex.java
index d0cc6cbd..1f502b38 100644
--- a/src/main/java/org/apache/commons/codec/language/DaitchMokotoffSoundex.java
+++ b/src/main/java/org/apache/commons/codec/language/DaitchMokotoffSoundex.java
@@ -229,10 +229,7 @@ public class DaitchMokotoffSoundex implements StringEncoder {
         }
 
         // sort RULES by pattern length in descending order
-        for (final Map.Entry<Character, List<Rule>> rule : RULES.entrySet()) {
-            final List<Rule> ruleList = rule.getValue();
-            ruleList.sort((rule1, rule2) -> rule2.getPatternLength() - rule1.getPatternLength());
-        }
+        RULES.forEach((k, v) -> v.sort((rule1, rule2) -> rule2.getPatternLength() - rule1.getPatternLength()));
     }
 
     private static void parseRules(final Scanner scanner, final String location,
diff --git a/src/main/java/org/apache/commons/codec/language/bm/PhoneticEngine.java b/src/main/java/org/apache/commons/codec/language/bm/PhoneticEngine.java
index 8c2163d5..267e42b6 100644
--- a/src/main/java/org/apache/commons/codec/language/bm/PhoneticEngine.java
+++ b/src/main/java/org/apache/commons/codec/language/bm/PhoneticEngine.java
@@ -140,16 +140,7 @@ public class PhoneticEngine {
          * @return  the stringified phoneme set
          */
         public String makeString() {
-            final StringBuilder sb = new StringBuilder();
-
-            for (final Rule.Phoneme ph : this.phonemes) {
-                if (sb.length() > 0) {
-                    sb.append("|");
-                }
-                sb.append(ph.getPhonemeText());
-            }
-
-            return sb.toString();
+            return phonemes.stream().map(Rule.Phoneme::getPhonemeText).collect(Collectors.joining("|"));
         }
     }
 
@@ -314,22 +305,20 @@ public class PhoneticEngine {
      * @return the resulting phonemes
      */
     private PhonemeBuilder applyFinalRules(final PhonemeBuilder phonemeBuilder,
-                                           final Map<String, List<Rule>> finalRules) {
+            final Map<String, List<Rule>> finalRules) {
         Objects.requireNonNull(finalRules, "finalRules");
         if (finalRules.isEmpty()) {
             return phonemeBuilder;
         }
 
-        final Map<Rule.Phoneme, Rule.Phoneme> phonemes =
-            new TreeMap<>(Rule.Phoneme.COMPARATOR);
+        final Map<Rule.Phoneme, Rule.Phoneme> phonemes = new TreeMap<>(Rule.Phoneme.COMPARATOR);
 
-        for (final Rule.Phoneme phoneme : phonemeBuilder.getPhonemes()) {
+        phonemeBuilder.getPhonemes().forEach(phoneme -> {
             PhonemeBuilder subBuilder = PhonemeBuilder.empty(phoneme.getLanguages());
             final String phonemeText = phoneme.getPhonemeText().toString();
 
             for (int i = 0; i < phonemeText.length();) {
-                final RulesApplication rulesApplication =
-                        new RulesApplication(finalRules, phonemeText, subBuilder, i, maxPhonemes).invoke();
+                final RulesApplication rulesApplication = new RulesApplication(finalRules, phonemeText, subBuilder, i, maxPhonemes).invoke();
                 final boolean found = rulesApplication.isFound();
                 subBuilder = rulesApplication.getPhonemeBuilder();
 
@@ -344,7 +333,7 @@ public class PhoneticEngine {
             // the phonemes map orders the phonemes only based on their text, but ignores the language set
             // when adding new phonemes, check for equal phonemes and merge their language set, otherwise
             // phonemes with the same text but different language set get lost
-            for (final Rule.Phoneme newPhoneme : subBuilder.getPhonemes()) {
+            subBuilder.getPhonemes().forEach(newPhoneme -> {
                 if (phonemes.containsKey(newPhoneme)) {
                     final Rule.Phoneme oldPhoneme = phonemes.remove(newPhoneme);
                     final Rule.Phoneme mergedPhoneme = oldPhoneme.mergeWithLanguage(newPhoneme.getLanguages());
@@ -352,8 +341,8 @@ public class PhoneticEngine {
                 } else {
                     phonemes.put(newPhoneme, newPhoneme);
                 }
-            }
-        }
+            });
+        });
 
         return new PhonemeBuilder(phonemes.keySet());
     }
@@ -414,11 +403,10 @@ public class PhoneticEngine {
         // special-case handling of word prefixes based upon the name type
         switch (this.nameType) {
         case SEPHARDIC:
-            for (final String aWord : words) {
+            words.forEach(aWord -> {
                 final String[] parts = aWord.split("'");
-                final String lastPart = parts[parts.length - 1];
-                words2.add(lastPart);
-            }
+                words2.add(parts[parts.length - 1]);
+            });
             words2.removeAll(NAME_PREFIXES.get(this.nameType));
             break;
         case ASHKENAZI:
@@ -441,9 +429,7 @@ public class PhoneticEngine {
         } else {
             // encode each word in a multi-word name separately (normally used for approx matches)
             final StringBuilder result = new StringBuilder();
-            for (final String word : words2) {
-                result.append("-").append(encode(word));
-            }
+            words2.forEach(word -> result.append("-").append(encode(word)));
             // return the result without the leading "-"
             return result.substring(1);
         }
diff --git a/src/main/java/org/apache/commons/codec/language/bm/Rule.java b/src/main/java/org/apache/commons/codec/language/bm/Rule.java
index a37e7942..50e38603 100644
--- a/src/main/java/org/apache/commons/codec/language/bm/Rule.java
+++ b/src/main/java/org/apache/commons/codec/language/bm/Rule.java
@@ -214,13 +214,13 @@ public class Rule {
                 final Map<String, Map<String, List<Rule>>> rs = new HashMap<>();
 
                 final Languages ls = Languages.getInstance(s);
-                for (final String l : ls.getLanguages()) {
+                ls.getLanguages().forEach(l -> {
                     try (final Scanner scanner = createScanner(s, rt, l)) {
                         rs.put(l, parseRules(scanner, createResourceName(s, rt, l)));
                     } catch (final IllegalStateException e) {
                         throw new IllegalStateException("Problem processing " + createResourceName(s, rt, l), e);
                     }
-                }
+                });
                 if (!rt.equals(RuleType.RULES)) {
                     try (final Scanner scanner = createScanner(s, rt, "common")) {
                         rs.put("common", parseRules(scanner, createResourceName(s, rt, "common")));
@@ -288,9 +288,7 @@ public class Rule {
                                          final Languages.LanguageSet langs) {
         final Map<String, List<Rule>> ruleMap = getInstanceMap(nameType, rt, langs);
         final List<Rule> allRules = new ArrayList<>();
-        for (final List<Rule> rules : ruleMap.values()) {
-            allRules.addAll(rules);
-        }
+        ruleMap.values().forEach(rules -> allRules.addAll(rules));
         return allRules;
     }
 


[commons-codec] 01/04: Long lines

Posted by gg...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-codec.git

commit 5e5a627f7516cb816a576cdb0fbfe2647f547abc
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Sun Jul 17 08:03:18 2022 -0400

    Long lines
---
 src/conf/checkstyle.xml | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/conf/checkstyle.xml b/src/conf/checkstyle.xml
index ddb492a5..d3f9855a 100644
--- a/src/conf/checkstyle.xml
+++ b/src/conf/checkstyle.xml
@@ -68,7 +68,7 @@ limitations under the License.
   <module name="LineLength">
       <!-- Ignore lines that begin with " * ", such as within a Javadoc comment. -->
       <property name="ignorePattern" value="^ *\* *[^ ]"/>
-      <property name="max" value="120"/>
+      <property name="max" value="160"/>
   </module>
 
 </module>