Skip to content

Commit f986994

Browse files
committed
[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.
git-svn-id: https://svn.apache.org/repos/asf/commons/proper/codec/trunk@1542823 13f79535-47bb-0310-9956-ffa450edef68
1 parent 78c7512 commit f986994

2 files changed

Lines changed: 47 additions & 8 deletions

File tree

src/main/java/org/apache/commons/codec/language/bm/PhoneticEngine.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -383,11 +383,11 @@ public String encode(final String input) {
383383
* of the input
384384
*/
385385
public String encode(String input, final Languages.LanguageSet languageSet) {
386-
final Map<String, List<Rule>> rules = Rule.getInstance(this.nameType, RuleType.RULES, languageSet);
386+
final Map<String, List<Rule>> rules = Rule.getInstanceMap(this.nameType, RuleType.RULES, languageSet);
387387
// rules common across many (all) languages
388-
final Map<String, List<Rule>> finalRules1 = Rule.getInstance(this.nameType, this.ruleType, "common");
388+
final Map<String, List<Rule>> finalRules1 = Rule.getInstanceMap(this.nameType, this.ruleType, "common");
389389
// rules that apply to a specific language that may be ambiguous or wrong if applied to other languages
390-
final Map<String, List<Rule>> finalRules2 = Rule.getInstance(this.nameType, this.ruleType, languageSet);
390+
final Map<String, List<Rule>> finalRules2 = Rule.getInstanceMap(this.nameType, this.ruleType, languageSet);
391391

392392
// tidy the input
393393
// lower case is a locale-dependent operation

src/main/java/org/apache/commons/codec/language/bm/Rule.java

Lines changed: 44 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@
3232
import java.util.regex.Matcher;
3333
import java.util.regex.Pattern;
3434

35+
import org.apache.commons.codec.language.bm.Languages.LanguageSet;
36+
3537
/**
3638
* A phoneme rule.
3739
* <p>
@@ -273,10 +275,46 @@ private static boolean endsWith(final CharSequence input, final CharSequence suf
273275
* the set of languages to consider
274276
* @return a list of Rules that apply
275277
*/
276-
public static Map<String, List<Rule>> getInstance(final NameType nameType, final RuleType rt,
278+
public static List<Rule> getInstance(final NameType nameType, final RuleType rt,
277279
final Languages.LanguageSet langs) {
278-
return langs.isSingleton() ? getInstance(nameType, rt, langs.getAny()) :
279-
getInstance(nameType, rt, Languages.ANY);
280+
final Map<String, List<Rule>> ruleMap = getInstanceMap(nameType, rt, langs);
281+
final List<Rule> allRules = new ArrayList<Rule>();
282+
for (final List<Rule> rules : ruleMap.values()) {
283+
allRules.addAll(rules);
284+
}
285+
return allRules;
286+
}
287+
288+
/**
289+
* Gets rules for a combination of name type, rule type and a single language.
290+
*
291+
* @param nameType
292+
* the NameType to consider
293+
* @param rt
294+
* the RuleType to consider
295+
* @param lang
296+
* the language to consider
297+
* @return a list of Rules that apply
298+
*/
299+
public static List<Rule> getInstance(final NameType nameType, final RuleType rt, final String lang) {
300+
return getInstance(nameType, rt, LanguageSet.from(new HashSet<String>(Arrays.asList(lang))));
301+
}
302+
303+
/**
304+
* Gets rules for a combination of name type, rule type and languages.
305+
*
306+
* @param nameType
307+
* the NameType to consider
308+
* @param rt
309+
* the RuleType to consider
310+
* @param langs
311+
* the set of languages to consider
312+
* @return a map containing all Rules that apply, grouped by the first character of the rule pattern
313+
*/
314+
public static Map<String, List<Rule>> getInstanceMap(final NameType nameType, final RuleType rt,
315+
final Languages.LanguageSet langs) {
316+
return langs.isSingleton() ? getInstanceMap(nameType, rt, langs.getAny()) :
317+
getInstanceMap(nameType, rt, Languages.ANY);
280318
}
281319

282320
/**
@@ -288,9 +326,10 @@ public static Map<String, List<Rule>> getInstance(final NameType nameType, final
288326
* the RuleType to consider
289327
* @param lang
290328
* the language to consider
291-
* @return a list rules for a combination of name type, rule type and a single language.
329+
* @return a map containing all Rules that apply, grouped by the first character of the rule pattern
292330
*/
293-
public static Map<String, List<Rule>> getInstance(final NameType nameType, final RuleType rt, final String lang) {
331+
public static Map<String, List<Rule>> getInstanceMap(final NameType nameType, final RuleType rt,
332+
final String lang) {
294333
final Map<String, List<Rule>> rules = RULES.get(nameType).get(rt).get(lang);
295334

296335
if (rules == null) {

0 commit comments

Comments
 (0)