You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by tn...@apache.org on 2013/11/17 22:14:50 UTC

svn commit: r1542823 - in /commons/proper/codec/trunk/src/main/java/org/apache/commons/codec/language/bm: PhoneticEngine.java Rule.java

Author: tn
Date: Sun Nov 17 21:14:50 2013
New Revision: 1542823

URL: http://svn.apache.org/r1542823
Log:
[CODEC-174] Fix Clirr error by renaming new Methods "Map Rule.getInstance(...)" to "Map Rule.getInstanceMap(...)" and re-introducing the original methods with the original signature "List Rule.getInstance(...)" and returning a joined result of getInstanceMap.

Modified:
    commons/proper/codec/trunk/src/main/java/org/apache/commons/codec/language/bm/PhoneticEngine.java
    commons/proper/codec/trunk/src/main/java/org/apache/commons/codec/language/bm/Rule.java

Modified: commons/proper/codec/trunk/src/main/java/org/apache/commons/codec/language/bm/PhoneticEngine.java
URL: http://svn.apache.org/viewvc/commons/proper/codec/trunk/src/main/java/org/apache/commons/codec/language/bm/PhoneticEngine.java?rev=1542823&r1=1542822&r2=1542823&view=diff
==============================================================================
--- commons/proper/codec/trunk/src/main/java/org/apache/commons/codec/language/bm/PhoneticEngine.java (original)
+++ commons/proper/codec/trunk/src/main/java/org/apache/commons/codec/language/bm/PhoneticEngine.java Sun Nov 17 21:14:50 2013
@@ -383,11 +383,11 @@ public class PhoneticEngine {
      *   of the input
      */
     public String encode(String input, final Languages.LanguageSet languageSet) {
-        final Map<String, List<Rule>> rules = Rule.getInstance(this.nameType, RuleType.RULES, languageSet);
+        final Map<String, List<Rule>> rules = Rule.getInstanceMap(this.nameType, RuleType.RULES, languageSet);
         // rules common across many (all) languages
-        final Map<String, List<Rule>> finalRules1 = Rule.getInstance(this.nameType, this.ruleType, "common");
+        final Map<String, List<Rule>> finalRules1 = Rule.getInstanceMap(this.nameType, this.ruleType, "common");
         // rules that apply to a specific language that may be ambiguous or wrong if applied to other languages
-        final Map<String, List<Rule>> finalRules2 = Rule.getInstance(this.nameType, this.ruleType, languageSet);
+        final Map<String, List<Rule>> finalRules2 = Rule.getInstanceMap(this.nameType, this.ruleType, languageSet);
 
         // tidy the input
         // lower case is a locale-dependent operation

Modified: commons/proper/codec/trunk/src/main/java/org/apache/commons/codec/language/bm/Rule.java
URL: http://svn.apache.org/viewvc/commons/proper/codec/trunk/src/main/java/org/apache/commons/codec/language/bm/Rule.java?rev=1542823&r1=1542822&r2=1542823&view=diff
==============================================================================
--- commons/proper/codec/trunk/src/main/java/org/apache/commons/codec/language/bm/Rule.java (original)
+++ commons/proper/codec/trunk/src/main/java/org/apache/commons/codec/language/bm/Rule.java Sun Nov 17 21:14:50 2013
@@ -32,6 +32,8 @@ import java.util.Set;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 
+import org.apache.commons.codec.language.bm.Languages.LanguageSet;
+
 /**
  * A phoneme rule.
  * <p>
@@ -273,10 +275,46 @@ public class Rule {
      *            the set of languages to consider
      * @return a list of Rules that apply
      */
-    public static Map<String, List<Rule>> getInstance(final NameType nameType, final RuleType rt,
+    public static List<Rule> getInstance(final NameType nameType, final RuleType rt,
                                          final Languages.LanguageSet langs) {
-        return langs.isSingleton() ? getInstance(nameType, rt, langs.getAny()) :
-                                     getInstance(nameType, rt, Languages.ANY);
+        final Map<String, List<Rule>> ruleMap = getInstanceMap(nameType, rt, langs);
+        final List<Rule> allRules = new ArrayList<Rule>();
+        for (final List<Rule> rules : ruleMap.values()) {
+            allRules.addAll(rules);
+        }
+        return allRules;
+    }
+
+    /**
+     * Gets rules for a combination of name type, rule type and a single language.
+     *
+     * @param nameType
+     *            the NameType to consider
+     * @param rt
+     *            the RuleType to consider
+     * @param lang
+     *            the language to consider
+     * @return a list of Rules that apply
+     */
+    public static List<Rule> getInstance(final NameType nameType, final RuleType rt, final String lang) {
+        return getInstance(nameType, rt, LanguageSet.from(new HashSet<String>(Arrays.asList(lang))));
+    }
+
+    /**
+     * Gets rules for a combination of name type, rule type and languages.
+     *
+     * @param nameType
+     *            the NameType to consider
+     * @param rt
+     *            the RuleType to consider
+     * @param langs
+     *            the set of languages to consider
+     * @return a map containing all Rules that apply, grouped by the first character of the rule pattern
+     */
+    public static Map<String, List<Rule>> getInstanceMap(final NameType nameType, final RuleType rt,
+                                                         final Languages.LanguageSet langs) {
+        return langs.isSingleton() ? getInstanceMap(nameType, rt, langs.getAny()) :
+                                     getInstanceMap(nameType, rt, Languages.ANY);
     }
 
     /**
@@ -288,9 +326,10 @@ public class Rule {
      *            the RuleType to consider
      * @param lang
      *            the language to consider
-     * @return a list rules for a combination of name type, rule type and a single language.
+     * @return a map containing all Rules that apply, grouped by the first character of the rule pattern
      */
-    public static Map<String, List<Rule>> getInstance(final NameType nameType, final RuleType rt, final String lang) {
+    public static Map<String, List<Rule>> getInstanceMap(final NameType nameType, final RuleType rt,
+                                                         final String lang) {
         final Map<String, List<Rule>> rules = RULES.get(nameType).get(rt).get(lang);
 
         if (rules == null) {