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 2013/01/07 17:08:07 UTC
svn commit: r1429868 [3/6] - in /commons/proper/codec/trunk/src:
main/java/org/apache/commons/codec/
main/java/org/apache/commons/codec/binary/
main/java/org/apache/commons/codec/digest/
main/java/org/apache/commons/codec/language/ main/java/org/apache...
Modified: commons/proper/codec/trunk/src/main/java/org/apache/commons/codec/language/bm/Lang.java
URL: http://svn.apache.org/viewvc/commons/proper/codec/trunk/src/main/java/org/apache/commons/codec/language/bm/Lang.java?rev=1429868&r1=1429867&r2=1429868&view=diff
==============================================================================
--- commons/proper/codec/trunk/src/main/java/org/apache/commons/codec/language/bm/Lang.java (original)
+++ commons/proper/codec/trunk/src/main/java/org/apache/commons/codec/language/bm/Lang.java Mon Jan 7 16:08:05 2013
@@ -82,13 +82,13 @@ public class Lang {
private final Set<String> languages;
private final Pattern pattern;
- private LangRule(Pattern pattern, Set<String> languages, boolean acceptOnMatch) {
+ private LangRule(final Pattern pattern, final Set<String> languages, final boolean acceptOnMatch) {
this.pattern = pattern;
this.languages = languages;
this.acceptOnMatch = acceptOnMatch;
}
- public boolean matches(String txt) {
+ public boolean matches(final String txt) {
return this.pattern.matcher(txt).find();
}
}
@@ -98,7 +98,7 @@ public class Lang {
private static final String LANGUAGE_RULES_RN = "org/apache/commons/codec/language/bm/lang.txt";
static {
- for (NameType s : NameType.values()) {
+ for (final NameType s : NameType.values()) {
Langs.put(s, loadFromResource(LANGUAGE_RULES_RN, Languages.getInstance(s)));
}
}
@@ -110,7 +110,7 @@ public class Lang {
* the NameType to look up
* @return a Lang encapsulating the language guessing rules for that name type
*/
- public static Lang instance(NameType nameType) {
+ public static Lang instance(final NameType nameType) {
return Langs.get(nameType);
}
@@ -126,18 +126,18 @@ public class Lang {
* the languages that these rules will support
* @return a Lang encapsulating the loaded language-guessing rules.
*/
- public static Lang loadFromResource(String languageRulesResourceName, Languages languages) {
- List<LangRule> rules = new ArrayList<LangRule>();
- InputStream lRulesIS = Lang.class.getClassLoader().getResourceAsStream(languageRulesResourceName);
+ public static Lang loadFromResource(final String languageRulesResourceName, final Languages languages) {
+ final List<LangRule> rules = new ArrayList<LangRule>();
+ final InputStream lRulesIS = Lang.class.getClassLoader().getResourceAsStream(languageRulesResourceName);
if (lRulesIS == null) {
throw new IllegalStateException("Unable to resolve required resource:" + LANGUAGE_RULES_RN);
}
- Scanner scanner = new Scanner(lRulesIS, ResourceConstants.ENCODING);
+ final Scanner scanner = new Scanner(lRulesIS, ResourceConstants.ENCODING);
boolean inExtendedComment = false;
while (scanner.hasNextLine()) {
- String rawLine = scanner.nextLine();
+ final String rawLine = scanner.nextLine();
String line = rawLine;
if (inExtendedComment) {
@@ -150,7 +150,7 @@ public class Lang {
inExtendedComment = true;
} else {
// discard comments
- int cmtI = line.indexOf(ResourceConstants.CMT);
+ final int cmtI = line.indexOf(ResourceConstants.CMT);
if (cmtI >= 0) {
line = line.substring(0, cmtI);
}
@@ -163,16 +163,16 @@ public class Lang {
}
// split it up
- String[] parts = line.split("\\s+");
+ final String[] parts = line.split("\\s+");
if (parts.length != 3) {
throw new IllegalArgumentException("Malformed line '" + rawLine + "' in language resource '" +
languageRulesResourceName + "'");
}
- Pattern pattern = Pattern.compile(parts[0]);
- String[] langs = parts[1].split("\\+");
- boolean accept = parts[2].equals("true");
+ final Pattern pattern = Pattern.compile(parts[0]);
+ final String[] langs = parts[1].split("\\+");
+ final boolean accept = parts[2].equals("true");
rules.add(new LangRule(pattern, new HashSet<String>(Arrays.asList(langs)), accept));
}
@@ -185,7 +185,7 @@ public class Lang {
private final Languages languages;
private final List<LangRule> rules;
- private Lang(List<LangRule> rules, Languages languages) {
+ private Lang(final List<LangRule> rules, final Languages languages) {
this.rules = Collections.unmodifiableList(rules);
this.languages = languages;
}
@@ -197,8 +197,8 @@ public class Lang {
* the word
* @return the language that the word originates from or {@link Languages#ANY} if there was no unique match
*/
- public String guessLanguage(String text) {
- Languages.LanguageSet ls = guessLanguages(text);
+ public String guessLanguage(final String text) {
+ final Languages.LanguageSet ls = guessLanguages(text);
return ls.isSingleton() ? ls.getAny() : Languages.ANY;
}
@@ -209,11 +209,11 @@ public class Lang {
* the word
* @return a Set of Strings of language names that are potential matches for the input word
*/
- public Languages.LanguageSet guessLanguages(String input) {
- String text = input.toLowerCase(Locale.ENGLISH);
+ public Languages.LanguageSet guessLanguages(final String input) {
+ final String text = input.toLowerCase(Locale.ENGLISH);
- Set<String> langs = new HashSet<String>(this.languages.getLanguages());
- for (LangRule rule : this.rules) {
+ final Set<String> langs = new HashSet<String>(this.languages.getLanguages());
+ for (final LangRule rule : this.rules) {
if (rule.matches(text)) {
if (rule.acceptOnMatch) {
langs.retainAll(rule.languages);
@@ -223,7 +223,7 @@ public class Lang {
}
}
- Languages.LanguageSet ls = Languages.LanguageSet.from(langs);
+ final Languages.LanguageSet ls = Languages.LanguageSet.from(langs);
return ls.equals(Languages.NO_LANGUAGES) ? Languages.ANY_LANGUAGE : ls;
}
}
Modified: commons/proper/codec/trunk/src/main/java/org/apache/commons/codec/language/bm/Languages.java
URL: http://svn.apache.org/viewvc/commons/proper/codec/trunk/src/main/java/org/apache/commons/codec/language/bm/Languages.java?rev=1429868&r1=1429867&r2=1429868&view=diff
==============================================================================
--- commons/proper/codec/trunk/src/main/java/org/apache/commons/codec/language/bm/Languages.java (original)
+++ commons/proper/codec/trunk/src/main/java/org/apache/commons/codec/language/bm/Languages.java Mon Jan 7 16:08:05 2013
@@ -60,7 +60,7 @@ public class Languages {
*/
public static abstract class LanguageSet {
- public static LanguageSet from(Set<String> langs) {
+ public static LanguageSet from(final Set<String> langs) {
return langs.isEmpty() ? NO_LANGUAGES : new SomeLanguages(langs);
}
@@ -81,12 +81,12 @@ public class Languages {
public static final class SomeLanguages extends LanguageSet {
private final Set<String> languages;
- private SomeLanguages(Set<String> languages) {
+ private SomeLanguages(final Set<String> languages) {
this.languages = Collections.unmodifiableSet(languages);
}
@Override
- public boolean contains(String language) {
+ public boolean contains(final String language) {
return this.languages.contains(language);
}
@@ -110,17 +110,17 @@ public class Languages {
}
@Override
- public LanguageSet restrictTo(LanguageSet other) {
+ public LanguageSet restrictTo(final LanguageSet other) {
if (other == NO_LANGUAGES) {
return other;
} else if (other == ANY_LANGUAGE) {
return this;
} else {
- SomeLanguages sl = (SomeLanguages) other;
+ final SomeLanguages sl = (SomeLanguages) other;
if (sl.languages.containsAll(languages)) {
return this;
} else {
- Set<String> ls = new HashSet<String>(this.languages);
+ final Set<String> ls = new HashSet<String>(this.languages);
ls.retainAll(sl.languages);
return from(ls);
}
@@ -139,28 +139,28 @@ public class Languages {
private static final Map<NameType, Languages> LANGUAGES = new EnumMap<NameType, Languages>(NameType.class);
static {
- for (NameType s : NameType.values()) {
+ for (final NameType s : NameType.values()) {
LANGUAGES.put(s, getInstance(langResourceName(s)));
}
}
- public static Languages getInstance(NameType nameType) {
+ public static Languages getInstance(final NameType nameType) {
return LANGUAGES.get(nameType);
}
- public static Languages getInstance(String languagesResourceName) {
+ public static Languages getInstance(final String languagesResourceName) {
// read languages list
- Set<String> ls = new HashSet<String>();
- InputStream langIS = Languages.class.getClassLoader().getResourceAsStream(languagesResourceName);
+ final Set<String> ls = new HashSet<String>();
+ final InputStream langIS = Languages.class.getClassLoader().getResourceAsStream(languagesResourceName);
if (langIS == null) {
throw new IllegalArgumentException("Unable to resolve required resource: " + languagesResourceName);
}
- Scanner lsScanner = new Scanner(langIS, ResourceConstants.ENCODING);
+ final Scanner lsScanner = new Scanner(langIS, ResourceConstants.ENCODING);
boolean inExtendedComment = false;
while (lsScanner.hasNextLine()) {
- String line = lsScanner.nextLine().trim();
+ final String line = lsScanner.nextLine().trim();
if (inExtendedComment) {
if (line.endsWith(ResourceConstants.EXT_CMT_END)) {
inExtendedComment = false;
@@ -177,7 +177,7 @@ public class Languages {
return new Languages(Collections.unmodifiableSet(ls));
}
- private static String langResourceName(NameType nameType) {
+ private static String langResourceName(final NameType nameType) {
return String.format("org/apache/commons/codec/language/bm/%s_languages.txt", nameType.getName());
}
@@ -188,7 +188,7 @@ public class Languages {
*/
public static final LanguageSet NO_LANGUAGES = new LanguageSet() {
@Override
- public boolean contains(String language) {
+ public boolean contains(final String language) {
return false;
}
@@ -208,7 +208,7 @@ public class Languages {
}
@Override
- public LanguageSet restrictTo(LanguageSet other) {
+ public LanguageSet restrictTo(final LanguageSet other) {
return this;
}
@@ -223,7 +223,7 @@ public class Languages {
*/
public static final LanguageSet ANY_LANGUAGE = new LanguageSet() {
@Override
- public boolean contains(String language) {
+ public boolean contains(final String language) {
return true;
}
@@ -243,7 +243,7 @@ public class Languages {
}
@Override
- public LanguageSet restrictTo(LanguageSet other) {
+ public LanguageSet restrictTo(final LanguageSet other) {
return other;
}
@@ -253,7 +253,7 @@ public class Languages {
}
};
- private Languages(Set<String> languages) {
+ private Languages(final Set<String> languages) {
this.languages = languages;
}
Modified: commons/proper/codec/trunk/src/main/java/org/apache/commons/codec/language/bm/NameType.java
URL: http://svn.apache.org/viewvc/commons/proper/codec/trunk/src/main/java/org/apache/commons/codec/language/bm/NameType.java?rev=1429868&r1=1429867&r2=1429868&view=diff
==============================================================================
--- commons/proper/codec/trunk/src/main/java/org/apache/commons/codec/language/bm/NameType.java (original)
+++ commons/proper/codec/trunk/src/main/java/org/apache/commons/codec/language/bm/NameType.java Mon Jan 7 16:08:05 2013
@@ -38,7 +38,7 @@ public enum NameType {
private final String name;
- NameType(String name) {
+ NameType(final String name) {
this.name = name;
}
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=1429868&r1=1429867&r2=1429868&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 Mon Jan 7 16:08:05 2013
@@ -64,13 +64,13 @@ public class PhoneticEngine {
* @param languages the set of languages
* @return a new, empty phoneme builder
*/
- public static PhonemeBuilder empty(Languages.LanguageSet languages) {
+ public static PhonemeBuilder empty(final Languages.LanguageSet languages) {
return new PhonemeBuilder(Collections.singleton(new Rule.Phoneme("", languages)));
}
private final Set<Rule.Phoneme> phonemes;
- private PhonemeBuilder(Set<Rule.Phoneme> phonemes) {
+ private PhonemeBuilder(final Set<Rule.Phoneme> phonemes) {
this.phonemes = phonemes;
}
@@ -80,10 +80,10 @@ public class PhoneticEngine {
* @param str the characters to append to the phonemes
* @return a new phoneme builder lenghtened by <code>str</code>
*/
- public PhonemeBuilder append(CharSequence str) {
- Set<Rule.Phoneme> newPhonemes = new LinkedHashSet<Rule.Phoneme>();
+ public PhonemeBuilder append(final CharSequence str) {
+ final Set<Rule.Phoneme> newPhonemes = new LinkedHashSet<Rule.Phoneme>();
- for (Rule.Phoneme ph : this.phonemes) {
+ for (final Rule.Phoneme ph : this.phonemes) {
newPhonemes.add(ph.append(str));
}
@@ -101,12 +101,12 @@ public class PhoneticEngine {
* @return a new phoneme builder containing the results of <code>phonemeExpr</code> applied to each phoneme
* in turn
*/
- public PhonemeBuilder apply(Rule.PhonemeExpr phonemeExpr, int maxPhonemes) {
- Set<Rule.Phoneme> newPhonemes = new LinkedHashSet<Rule.Phoneme>();
+ public PhonemeBuilder apply(final Rule.PhonemeExpr phonemeExpr, final int maxPhonemes) {
+ final Set<Rule.Phoneme> newPhonemes = new LinkedHashSet<Rule.Phoneme>();
- EXPR: for (Rule.Phoneme left : this.phonemes) {
- for (Rule.Phoneme right : phonemeExpr.getPhonemes()) {
- Rule.Phoneme join = left.join(right);
+ EXPR: for (final Rule.Phoneme left : this.phonemes) {
+ for (final Rule.Phoneme right : phonemeExpr.getPhonemes()) {
+ final Rule.Phoneme join = left.join(right);
if (!join.getLanguages().isEmpty()) {
if (newPhonemes.size() < maxPhonemes) {
newPhonemes.add(join);
@@ -139,7 +139,7 @@ public class PhoneticEngine {
public String makeString() {
final StringBuilder sb = new StringBuilder();
- for (Rule.Phoneme ph : this.phonemes) {
+ for (final Rule.Phoneme ph : this.phonemes) {
if (sb.length() > 0) {
sb.append("|");
}
@@ -168,11 +168,11 @@ public class PhoneticEngine {
private PhonemeBuilder phonemeBuilder;
private int i;
- private int maxPhonemes;
+ private final int maxPhonemes;
private boolean found;
- public RulesApplication(List<Rule> finalRules, CharSequence input,
- PhonemeBuilder phonemeBuilder, int i, int maxPhonemes) {
+ public RulesApplication(final List<Rule> finalRules, final CharSequence input,
+ final PhonemeBuilder phonemeBuilder, final int i, final int maxPhonemes) {
if (finalRules == null) {
throw new NullPointerException("The finalRules argument must not be null");
}
@@ -201,8 +201,8 @@ public class PhoneticEngine {
public RulesApplication invoke() {
this.found = false;
int patternLength = 0;
- for (Rule rule : this.finalRules) {
- String pattern = rule.getPattern();
+ for (final Rule rule : this.finalRules) {
+ final String pattern = rule.getPattern();
patternLength = pattern.length();
if (!rule.patternAndContextMatches(this.input, this.i)) {
@@ -254,7 +254,7 @@ public class PhoneticEngine {
final CharSequence[][] cache = new CharSequence[cached.length()][cached.length()];
return new CharSequence() {
@Override
- public char charAt(int index) {
+ public char charAt(final int index) {
return cached.charAt(index);
}
@@ -264,7 +264,7 @@ public class PhoneticEngine {
}
@Override
- public CharSequence subSequence(int start, int end) {
+ public CharSequence subSequence(final int start, final int end) {
if (start == end) {
return "";
}
@@ -285,9 +285,9 @@ public class PhoneticEngine {
* @param sep String to separate them with
* @return a single String consisting of each element of <code>strings</code> interleaved by <code>sep</code>
*/
- private static String join(Iterable<String> strings, String sep) {
- StringBuilder sb = new StringBuilder();
- Iterator<String> si = strings.iterator();
+ private static String join(final Iterable<String> strings, final String sep) {
+ final StringBuilder sb = new StringBuilder();
+ final Iterator<String> si = strings.iterator();
if (si.hasNext()) {
sb.append(si.next());
}
@@ -320,7 +320,7 @@ public class PhoneticEngine {
* @param concat
* if it will concatenate multiple encodings
*/
- public PhoneticEngine(NameType nameType, RuleType ruleType, boolean concat) {
+ public PhoneticEngine(final NameType nameType, final RuleType ruleType, final boolean concat) {
this(nameType, ruleType, concat, DEFAULT_MAX_PHONEMES);
}
@@ -337,7 +337,7 @@ public class PhoneticEngine {
* the maximum number of phonemes that will be handled
* @since 1.7
*/
- public PhoneticEngine(NameType nameType, RuleType ruleType, boolean concat, int maxPhonemes) {
+ public PhoneticEngine(final NameType nameType, final RuleType ruleType, final boolean concat, final int maxPhonemes) {
if (ruleType == RuleType.RULES) {
throw new IllegalArgumentException("ruleType must not be " + RuleType.RULES);
}
@@ -356,7 +356,7 @@ public class PhoneticEngine {
* @param finalRules the final rules to apply
* @return the resulting phonemes
*/
- private PhonemeBuilder applyFinalRules(PhonemeBuilder phonemeBuilder, List<Rule> finalRules) {
+ private PhonemeBuilder applyFinalRules(final PhonemeBuilder phonemeBuilder, final List<Rule> finalRules) {
if (finalRules == null) {
throw new NullPointerException("finalRules can not be null");
}
@@ -364,16 +364,16 @@ public class PhoneticEngine {
return phonemeBuilder;
}
- Set<Rule.Phoneme> phonemes = new TreeSet<Rule.Phoneme>(Rule.Phoneme.COMPARATOR);
+ final Set<Rule.Phoneme> phonemes = new TreeSet<Rule.Phoneme>(Rule.Phoneme.COMPARATOR);
- for (Rule.Phoneme phoneme : phonemeBuilder.getPhonemes()) {
+ for (final Rule.Phoneme phoneme : phonemeBuilder.getPhonemes()) {
PhonemeBuilder subBuilder = PhonemeBuilder.empty(phoneme.getLanguages());
- CharSequence phonemeText = cacheSubSequence(phoneme.getPhonemeText());
+ final CharSequence phonemeText = cacheSubSequence(phoneme.getPhonemeText());
for (int i = 0; i < phonemeText.length();) {
- RulesApplication rulesApplication =
+ final RulesApplication rulesApplication =
new RulesApplication(finalRules, phonemeText, subBuilder, i, maxPhonemes).invoke();
- boolean found = rulesApplication.isFound();
+ final boolean found = rulesApplication.isFound();
subBuilder = rulesApplication.getPhonemeBuilder();
if (!found) {
@@ -397,8 +397,8 @@ public class PhoneticEngine {
* the String to encode
* @return the encoding of the input
*/
- public String encode(String input) {
- Languages.LanguageSet languageSet = this.lang.guessLanguages(input);
+ public String encode(final String input) {
+ final Languages.LanguageSet languageSet = this.lang.guessLanguages(input);
return encode(input, languageSet);
}
@@ -424,16 +424,16 @@ public class PhoneticEngine {
if (this.nameType == NameType.GENERIC) {
if (input.length() >= 2 && input.substring(0, 2).equals("d'")) { // check for d'
- String remainder = input.substring(2);
- String combined = "d" + remainder;
+ final String remainder = input.substring(2);
+ final String combined = "d" + remainder;
return "(" + encode(remainder) + ")-(" + encode(combined) + ")";
}
- for (String l : NAME_PREFIXES.get(this.nameType)) {
+ for (final String l : NAME_PREFIXES.get(this.nameType)) {
// handle generic prefixes
if (input.startsWith(l + " ")) {
// check for any prefix in the words list
- String remainder = input.substring(l.length() + 1); // input without the prefix
- String combined = l + remainder; // input with prefix without space
+ final String remainder = input.substring(l.length() + 1); // input without the prefix
+ final String combined = l + remainder; // input with prefix without space
return "(" + encode(remainder) + ")-(" + encode(combined) + ")";
}
}
@@ -445,9 +445,9 @@ public class PhoneticEngine {
// special-case handling of word prefixes based upon the name type
switch (this.nameType) {
case SEPHARDIC:
- for (String aWord : words) {
- String[] parts = aWord.split("'");
- String lastPart = parts[parts.length - 1];
+ for (final String aWord : words) {
+ final String[] parts = aWord.split("'");
+ final String lastPart = parts[parts.length - 1];
words2.add(lastPart);
}
words2.removeAll(NAME_PREFIXES.get(this.nameType));
@@ -471,8 +471,8 @@ public class PhoneticEngine {
input = words.iterator().next();
} else {
// encode each word in a multi-word name separately (normally used for approx matches)
- StringBuilder result = new StringBuilder();
- for (String word : words2) {
+ final StringBuilder result = new StringBuilder();
+ for (final String word : words2) {
result.append("-").append(encode(word));
}
// return the result without the leading "-"
@@ -482,9 +482,9 @@ public class PhoneticEngine {
PhonemeBuilder phonemeBuilder = PhonemeBuilder.empty(languageSet);
// loop over each char in the input - we will handle the increment manually
- CharSequence inputCache = cacheSubSequence(input);
+ final CharSequence inputCache = cacheSubSequence(input);
for (int i = 0; i < inputCache.length();) {
- RulesApplication rulesApplication =
+ final RulesApplication rulesApplication =
new RulesApplication(rules, inputCache, phonemeBuilder, i, maxPhonemes).invoke();
i = rulesApplication.getI();
phonemeBuilder = rulesApplication.getPhonemeBuilder();
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=1429868&r1=1429867&r2=1429868&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 Mon Jan 7 16:08:05 2013
@@ -82,12 +82,12 @@ public class Rule {
public static final class Phoneme implements PhonemeExpr {
public static final Comparator<Phoneme> COMPARATOR = new Comparator<Phoneme>() {
@Override
- public int compare(Phoneme o1, Phoneme o2) {
+ public int compare(final Phoneme o1, final Phoneme o2) {
for (int i = 0; i < o1.phonemeText.length(); i++) {
if (i >= o2.phonemeText.length()) {
return +1;
}
- int c = o1.phonemeText.charAt(i) - o2.phonemeText.charAt(i);
+ final int c = o1.phonemeText.charAt(i) - o2.phonemeText.charAt(i);
if (c != 0) {
return c;
}
@@ -104,12 +104,12 @@ public class Rule {
private final CharSequence phonemeText;
private final Languages.LanguageSet languages;
- public Phoneme(CharSequence phonemeText, Languages.LanguageSet languages) {
+ public Phoneme(final CharSequence phonemeText, final Languages.LanguageSet languages) {
this.phonemeText = phonemeText;
this.languages = languages;
}
- public Phoneme append(CharSequence str) {
+ public Phoneme append(final CharSequence str) {
return new Phoneme(this.phonemeText.toString() + str.toString(), this.languages);
}
@@ -126,7 +126,7 @@ public class Rule {
return this.phonemeText;
}
- public Phoneme join(Phoneme right) {
+ public Phoneme join(final Phoneme right) {
return new Phoneme(this.phonemeText.toString() + right.phonemeText.toString(),
this.languages.restrictTo(right.languages));
}
@@ -139,7 +139,7 @@ public class Rule {
public static final class PhonemeList implements PhonemeExpr {
private final List<Phoneme> phonemes;
- public PhonemeList(List<Phoneme> phonemes) {
+ public PhonemeList(final List<Phoneme> phonemes) {
this.phonemes = phonemes;
}
@@ -158,7 +158,7 @@ public class Rule {
public static final RPattern ALL_STRINGS_RMATCHER = new RPattern() {
@Override
- public boolean isMatch(CharSequence input) {
+ public boolean isMatch(final CharSequence input) {
return true;
}
};
@@ -173,17 +173,17 @@ public class Rule {
new EnumMap<NameType, Map<RuleType, Map<String, List<Rule>>>>(NameType.class);
static {
- for (NameType s : NameType.values()) {
- Map<RuleType, Map<String, List<Rule>>> rts = new EnumMap<RuleType, Map<String, List<Rule>>>(RuleType.class);
+ for (final NameType s : NameType.values()) {
+ final Map<RuleType, Map<String, List<Rule>>> rts = new EnumMap<RuleType, Map<String, List<Rule>>>(RuleType.class);
- for (RuleType rt : RuleType.values()) {
- Map<String, List<Rule>> rs = new HashMap<String, List<Rule>>();
+ for (final RuleType rt : RuleType.values()) {
+ final Map<String, List<Rule>> rs = new HashMap<String, List<Rule>>();
- Languages ls = Languages.getInstance(s);
- for (String l : ls.getLanguages()) {
+ final Languages ls = Languages.getInstance(s);
+ for (final String l : ls.getLanguages()) {
try {
rs.put(l, parseRules(createScanner(s, rt, l), createResourceName(s, rt, l)));
- } catch (IllegalStateException e) {
+ } catch (final IllegalStateException e) {
throw new IllegalStateException("Problem processing " + createResourceName(s, rt, l), e);
}
}
@@ -198,7 +198,7 @@ public class Rule {
}
}
- private static boolean contains(CharSequence chars, char input) {
+ private static boolean contains(final CharSequence chars, final char input) {
for (int i = 0; i < chars.length(); i++) {
if (chars.charAt(i) == input) {
return true;
@@ -207,14 +207,14 @@ public class Rule {
return false;
}
- private static String createResourceName(NameType nameType, RuleType rt, String lang) {
+ private static String createResourceName(final NameType nameType, final RuleType rt, final String lang) {
return String.format("org/apache/commons/codec/language/bm/%s_%s_%s.txt",
nameType.getName(), rt.getName(), lang);
}
- private static Scanner createScanner(NameType nameType, RuleType rt, String lang) {
- String resName = createResourceName(nameType, rt, lang);
- InputStream rulesIS = Languages.class.getClassLoader().getResourceAsStream(resName);
+ private static Scanner createScanner(final NameType nameType, final RuleType rt, final String lang) {
+ final String resName = createResourceName(nameType, rt, lang);
+ final InputStream rulesIS = Languages.class.getClassLoader().getResourceAsStream(resName);
if (rulesIS == null) {
throw new IllegalArgumentException("Unable to load resource: " + resName);
@@ -223,9 +223,9 @@ public class Rule {
return new Scanner(rulesIS, ResourceConstants.ENCODING);
}
- private static Scanner createScanner(String lang) {
- String resName = String.format("org/apache/commons/codec/language/bm/%s.txt", lang);
- InputStream rulesIS = Languages.class.getClassLoader().getResourceAsStream(resName);
+ private static Scanner createScanner(final String lang) {
+ final String resName = String.format("org/apache/commons/codec/language/bm/%s.txt", lang);
+ final InputStream rulesIS = Languages.class.getClassLoader().getResourceAsStream(resName);
if (rulesIS == null) {
throw new IllegalArgumentException("Unable to load resource: " + resName);
@@ -234,7 +234,7 @@ public class Rule {
return new Scanner(rulesIS, ResourceConstants.ENCODING);
}
- private static boolean endsWith(CharSequence input, CharSequence suffix) {
+ private static boolean endsWith(final CharSequence input, final CharSequence suffix) {
if (suffix.length() > input.length()) {
return false;
}
@@ -257,7 +257,7 @@ public class Rule {
* the set of languages to consider
* @return a list of Rules that apply
*/
- public static List<Rule> getInstance(NameType nameType, RuleType rt, Languages.LanguageSet langs) {
+ 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);
}
@@ -273,8 +273,8 @@ public class Rule {
* the language to consider
* @return a list rules for a combination of name type, rule type and a single language.
*/
- public static List<Rule> getInstance(NameType nameType, RuleType rt, String lang) {
- List<Rule> rules = RULES.get(nameType).get(rt).get(lang);
+ public static List<Rule> getInstance(final NameType nameType, final RuleType rt, final String lang) {
+ final List<Rule> rules = RULES.get(nameType).get(rt).get(lang);
if (rules == null) {
throw new IllegalArgumentException(String.format("No rules found for %s, %s, %s.",
@@ -284,15 +284,15 @@ public class Rule {
return rules;
}
- private static Phoneme parsePhoneme(String ph) {
- int open = ph.indexOf("[");
+ private static Phoneme parsePhoneme(final String ph) {
+ final int open = ph.indexOf("[");
if (open >= 0) {
if (!ph.endsWith("]")) {
throw new IllegalArgumentException("Phoneme expression contains a '[' but does not end in ']'");
}
- String before = ph.substring(0, open);
- String in = ph.substring(open + 1, ph.length() - 1);
- Set<String> langs = new HashSet<String>(Arrays.asList(in.split("[+]")));
+ final String before = ph.substring(0, open);
+ final String in = ph.substring(open + 1, ph.length() - 1);
+ final Set<String> langs = new HashSet<String>(Arrays.asList(in.split("[+]")));
return new Phoneme(before, Languages.LanguageSet.from(langs));
} else {
@@ -300,15 +300,15 @@ public class Rule {
}
}
- private static PhonemeExpr parsePhonemeExpr(String ph) {
+ private static PhonemeExpr parsePhonemeExpr(final String ph) {
if (ph.startsWith("(")) { // we have a bracketed list of options
if (!ph.endsWith(")")) {
throw new IllegalArgumentException("Phoneme starts with '(' so must end with ')'");
}
- List<Phoneme> phs = new ArrayList<Phoneme>();
- String body = ph.substring(1, ph.length() - 1);
- for (String part : body.split("[|]")) {
+ final List<Phoneme> phs = new ArrayList<Phoneme>();
+ final String body = ph.substring(1, ph.length() - 1);
+ for (final String part : body.split("[|]")) {
phs.add(parsePhoneme(part));
}
if (body.startsWith("|") || body.endsWith("|")) {
@@ -322,13 +322,13 @@ public class Rule {
}
private static List<Rule> parseRules(final Scanner scanner, final String location) {
- List<Rule> lines = new ArrayList<Rule>();
+ final List<Rule> lines = new ArrayList<Rule>();
int currentLine = 0;
boolean inMultilineComment = false;
while (scanner.hasNextLine()) {
currentLine++;
- String rawLine = scanner.nextLine();
+ final String rawLine = scanner.nextLine();
String line = rawLine;
if (inMultilineComment) {
@@ -340,7 +340,7 @@ public class Rule {
inMultilineComment = true;
} else {
// discard comments
- int cmtI = line.indexOf(ResourceConstants.CMT);
+ final int cmtI = line.indexOf(ResourceConstants.CMT);
if (cmtI >= 0) {
line = line.substring(0, cmtI);
}
@@ -354,7 +354,7 @@ public class Rule {
if (line.startsWith(HASH_INCLUDE)) {
// include statement
- String incl = line.substring(HASH_INCLUDE.length()).trim();
+ final String incl = line.substring(HASH_INCLUDE.length()).trim();
if (incl.contains(" ")) {
throw new IllegalArgumentException("Malformed import statement '" + rawLine + "' in " +
location);
@@ -363,18 +363,18 @@ public class Rule {
}
} else {
// rule
- String[] parts = line.split("\\s+");
+ final String[] parts = line.split("\\s+");
if (parts.length != 4) {
throw new IllegalArgumentException("Malformed rule statement split into " + parts.length +
" parts: " + rawLine + " in " + location);
} else {
try {
- String pat = stripQuotes(parts[0]);
- String lCon = stripQuotes(parts[1]);
- String rCon = stripQuotes(parts[2]);
- PhonemeExpr ph = parsePhonemeExpr(stripQuotes(parts[3]));
+ final String pat = stripQuotes(parts[0]);
+ final String lCon = stripQuotes(parts[1]);
+ final String rCon = stripQuotes(parts[2]);
+ final PhonemeExpr ph = parsePhonemeExpr(stripQuotes(parts[3]));
final int cLine = currentLine;
- Rule r = new Rule(pat, lCon, rCon, ph) {
+ final Rule r = new Rule(pat, lCon, rCon, ph) {
private final int myLine = cLine;
private final String loc = location;
@@ -389,7 +389,7 @@ public class Rule {
}
};
lines.add(r);
- } catch (IllegalArgumentException e) {
+ } catch (final IllegalArgumentException e) {
throw new IllegalStateException("Problem parsing line '" + currentLine + "' in " +
location, e);
}
@@ -410,10 +410,10 @@ public class Rule {
* @return an RPattern that will match this regex
*/
private static RPattern pattern(final String regex) {
- boolean startsWith = regex.startsWith("^");
- boolean endsWith = regex.endsWith("$");
+ final boolean startsWith = regex.startsWith("^");
+ final boolean endsWith = regex.endsWith("$");
final String content = regex.substring(startsWith ? 1 : 0, endsWith ? regex.length() - 1 : regex.length());
- boolean boxes = content.contains("[");
+ final boolean boxes = content.contains("[");
if (!boxes) {
if (startsWith && endsWith) {
@@ -422,14 +422,14 @@ public class Rule {
// empty
return new RPattern() {
@Override
- public boolean isMatch(CharSequence input) {
+ public boolean isMatch(final CharSequence input) {
return input.length() == 0;
}
};
} else {
return new RPattern() {
@Override
- public boolean isMatch(CharSequence input) {
+ public boolean isMatch(final CharSequence input) {
return input.equals(content);
}
};
@@ -441,7 +441,7 @@ public class Rule {
// matches from start
return new RPattern() {
@Override
- public boolean isMatch(CharSequence input) {
+ public boolean isMatch(final CharSequence input) {
return startsWith(input, content);
}
};
@@ -449,20 +449,20 @@ public class Rule {
// matches from start
return new RPattern() {
@Override
- public boolean isMatch(CharSequence input) {
+ public boolean isMatch(final CharSequence input) {
return endsWith(input, content);
}
};
}
} else {
- boolean startsWithBox = content.startsWith("[");
- boolean endsWithBox = content.endsWith("]");
+ final boolean startsWithBox = content.startsWith("[");
+ final boolean endsWithBox = content.endsWith("]");
if (startsWithBox && endsWithBox) {
String boxContent = content.substring(1, content.length() - 1);
if (!boxContent.contains("[")) {
// box containing alternatives
- boolean negate = boxContent.startsWith("^");
+ final boolean negate = boxContent.startsWith("^");
if (negate) {
boxContent = boxContent.substring(1);
}
@@ -473,7 +473,7 @@ public class Rule {
// exact match
return new RPattern() {
@Override
- public boolean isMatch(CharSequence input) {
+ public boolean isMatch(final CharSequence input) {
return input.length() == 1 && contains(bContent, input.charAt(0)) == shouldMatch;
}
};
@@ -481,7 +481,7 @@ public class Rule {
// first char
return new RPattern() {
@Override
- public boolean isMatch(CharSequence input) {
+ public boolean isMatch(final CharSequence input) {
return input.length() > 0 && contains(bContent, input.charAt(0)) == shouldMatch;
}
};
@@ -489,7 +489,7 @@ public class Rule {
// last char
return new RPattern() {
@Override
- public boolean isMatch(CharSequence input) {
+ public boolean isMatch(final CharSequence input) {
return input.length() > 0 &&
contains(bContent, input.charAt(input.length() - 1)) == shouldMatch;
}
@@ -503,14 +503,14 @@ public class Rule {
Pattern pattern = Pattern.compile(regex);
@Override
- public boolean isMatch(CharSequence input) {
- Matcher matcher = pattern.matcher(input);
+ public boolean isMatch(final CharSequence input) {
+ final Matcher matcher = pattern.matcher(input);
return matcher.find();
}
};
}
- private static boolean startsWith(CharSequence input, CharSequence prefix) {
+ private static boolean startsWith(final CharSequence input, final CharSequence prefix) {
if (prefix.length() > input.length()) {
return false;
}
@@ -554,7 +554,7 @@ public class Rule {
* @param phoneme
* the resulting phoneme
*/
- public Rule(String pattern, String lContext, String rContext, PhonemeExpr phoneme) {
+ public Rule(final String pattern, final String lContext, final String rContext, final PhonemeExpr phoneme) {
this.pattern = pattern;
this.lContext = pattern(lContext + "$");
this.rContext = pattern("^" + rContext);
@@ -608,13 +608,13 @@ public class Rule {
* the int position within the input
* @return true if the pattern and left/right context match, false otherwise
*/
- public boolean patternAndContextMatches(CharSequence input, int i) {
+ public boolean patternAndContextMatches(final CharSequence input, final int i) {
if (i < 0) {
throw new IndexOutOfBoundsException("Can not match pattern at negative indexes");
}
- int patternLength = this.pattern.length();
- int ipl = i + patternLength;
+ final int patternLength = this.pattern.length();
+ final int ipl = i + patternLength;
if (ipl > input.length()) {
// not enough room for the pattern to match
Modified: commons/proper/codec/trunk/src/main/java/org/apache/commons/codec/language/bm/RuleType.java
URL: http://svn.apache.org/viewvc/commons/proper/codec/trunk/src/main/java/org/apache/commons/codec/language/bm/RuleType.java?rev=1429868&r1=1429867&r2=1429868&view=diff
==============================================================================
--- commons/proper/codec/trunk/src/main/java/org/apache/commons/codec/language/bm/RuleType.java (original)
+++ commons/proper/codec/trunk/src/main/java/org/apache/commons/codec/language/bm/RuleType.java Mon Jan 7 16:08:05 2013
@@ -34,7 +34,7 @@ public enum RuleType {
private final String name;
- RuleType(String name) {
+ RuleType(final String name) {
this.name = name;
}
Modified: commons/proper/codec/trunk/src/main/java/org/apache/commons/codec/net/BCodec.java
URL: http://svn.apache.org/viewvc/commons/proper/codec/trunk/src/main/java/org/apache/commons/codec/net/BCodec.java?rev=1429868&r1=1429867&r2=1429868&view=diff
==============================================================================
--- commons/proper/codec/trunk/src/main/java/org/apache/commons/codec/net/BCodec.java (original)
+++ commons/proper/codec/trunk/src/main/java/org/apache/commons/codec/net/BCodec.java Mon Jan 7 16:08:05 2013
@@ -89,7 +89,7 @@ public class BCodec extends RFC1522Codec
}
@Override
- protected byte[] doEncoding(byte[] bytes) {
+ protected byte[] doEncoding(final byte[] bytes) {
if (bytes == null) {
return null;
}
@@ -97,7 +97,7 @@ public class BCodec extends RFC1522Codec
}
@Override
- protected byte[] doDecoding(byte[] bytes) {
+ protected byte[] doDecoding(final byte[] bytes) {
if (bytes == null) {
return null;
}
@@ -140,7 +140,7 @@ public class BCodec extends RFC1522Codec
}
try {
return this.encodeText(value, charset);
- } catch (UnsupportedEncodingException e) {
+ } catch (final UnsupportedEncodingException e) {
throw new EncoderException(e.getMessage(), e);
}
}
@@ -155,7 +155,7 @@ public class BCodec extends RFC1522Codec
* thrown if a failure condition is encountered during the encoding process.
*/
@Override
- public String encode(String value) throws EncoderException {
+ public String encode(final String value) throws EncoderException {
if (value == null) {
return null;
}
@@ -173,13 +173,13 @@ public class BCodec extends RFC1522Codec
* A decoder exception is thrown if a failure condition is encountered during the decode process.
*/
@Override
- public String decode(String value) throws DecoderException {
+ public String decode(final String value) throws DecoderException {
if (value == null) {
return null;
}
try {
return this.decodeText(value);
- } catch (UnsupportedEncodingException e) {
+ } catch (final UnsupportedEncodingException e) {
throw new DecoderException(e.getMessage(), e);
}
}
@@ -194,7 +194,7 @@ public class BCodec extends RFC1522Codec
* thrown if a failure condition is encountered during the encoding process.
*/
@Override
- public Object encode(Object value) throws EncoderException {
+ public Object encode(final Object value) throws EncoderException {
if (value == null) {
return null;
} else if (value instanceof String) {
@@ -218,7 +218,7 @@ public class BCodec extends RFC1522Codec
* during the decode process.
*/
@Override
- public Object decode(Object value) throws DecoderException {
+ public Object decode(final Object value) throws DecoderException {
if (value == null) {
return null;
} else if (value instanceof String) {
Modified: commons/proper/codec/trunk/src/main/java/org/apache/commons/codec/net/QCodec.java
URL: http://svn.apache.org/viewvc/commons/proper/codec/trunk/src/main/java/org/apache/commons/codec/net/QCodec.java?rev=1429868&r1=1429867&r2=1429868&view=diff
==============================================================================
--- commons/proper/codec/trunk/src/main/java/org/apache/commons/codec/net/QCodec.java (original)
+++ commons/proper/codec/trunk/src/main/java/org/apache/commons/codec/net/QCodec.java Mon Jan 7 16:08:05 2013
@@ -150,11 +150,11 @@ public class QCodec extends RFC1522Codec
}
@Override
- protected byte[] doEncoding(byte[] bytes) {
+ protected byte[] doEncoding(final byte[] bytes) {
if (bytes == null) {
return null;
}
- byte[] data = QuotedPrintableCodec.encodeQuotedPrintable(PRINTABLE_CHARS, bytes);
+ final byte[] data = QuotedPrintableCodec.encodeQuotedPrintable(PRINTABLE_CHARS, bytes);
if (this.encodeBlanks) {
for (int i = 0; i < data.length; i++) {
if (data[i] == BLANK) {
@@ -166,21 +166,21 @@ public class QCodec extends RFC1522Codec
}
@Override
- protected byte[] doDecoding(byte[] bytes) throws DecoderException {
+ protected byte[] doDecoding(final byte[] bytes) throws DecoderException {
if (bytes == null) {
return null;
}
boolean hasUnderscores = false;
- for (byte b : bytes) {
+ for (final byte b : bytes) {
if (b == UNDERSCORE) {
hasUnderscores = true;
break;
}
}
if (hasUnderscores) {
- byte[] tmp = new byte[bytes.length];
+ final byte[] tmp = new byte[bytes.length];
for (int i = 0; i < bytes.length; i++) {
- byte b = bytes[i];
+ final byte b = bytes[i];
if (b != UNDERSCORE) {
tmp[i] = b;
} else {
@@ -228,7 +228,7 @@ public class QCodec extends RFC1522Codec
}
try {
return encodeText(str, charset);
- } catch (UnsupportedEncodingException e) {
+ } catch (final UnsupportedEncodingException e) {
throw new EncoderException(e.getMessage(), e);
}
}
@@ -243,7 +243,7 @@ public class QCodec extends RFC1522Codec
* thrown if a failure condition is encountered during the encoding process.
*/
@Override
- public String encode(String str) throws EncoderException {
+ public String encode(final String str) throws EncoderException {
if (str == null) {
return null;
}
@@ -261,13 +261,13 @@ public class QCodec extends RFC1522Codec
* A decoder exception is thrown if a failure condition is encountered during the decode process.
*/
@Override
- public String decode(String str) throws DecoderException {
+ public String decode(final String str) throws DecoderException {
if (str == null) {
return null;
}
try {
return decodeText(str);
- } catch (UnsupportedEncodingException e) {
+ } catch (final UnsupportedEncodingException e) {
throw new DecoderException(e.getMessage(), e);
}
}
@@ -282,7 +282,7 @@ public class QCodec extends RFC1522Codec
* thrown if a failure condition is encountered during the encoding process.
*/
@Override
- public Object encode(Object obj) throws EncoderException {
+ public Object encode(final Object obj) throws EncoderException {
if (obj == null) {
return null;
} else if (obj instanceof String) {
@@ -306,7 +306,7 @@ public class QCodec extends RFC1522Codec
* during the decode process.
*/
@Override
- public Object decode(Object obj) throws DecoderException {
+ public Object decode(final Object obj) throws DecoderException {
if (obj == null) {
return null;
} else if (obj instanceof String) {
@@ -352,7 +352,7 @@ public class QCodec extends RFC1522Codec
* @param b
* {@code true} if SPACE characters are to be transformed, {@code false} otherwise
*/
- public void setEncodeBlanks(boolean b) {
+ public void setEncodeBlanks(final boolean b) {
this.encodeBlanks = b;
}
}
Modified: commons/proper/codec/trunk/src/main/java/org/apache/commons/codec/net/QuotedPrintableCodec.java
URL: http://svn.apache.org/viewvc/commons/proper/codec/trunk/src/main/java/org/apache/commons/codec/net/QuotedPrintableCodec.java?rev=1429868&r1=1429867&r2=1429868&view=diff
==============================================================================
--- commons/proper/codec/trunk/src/main/java/org/apache/commons/codec/net/QuotedPrintableCodec.java (original)
+++ commons/proper/codec/trunk/src/main/java/org/apache/commons/codec/net/QuotedPrintableCodec.java Mon Jan 7 16:08:05 2013
@@ -101,7 +101,7 @@ public class QuotedPrintableCodec implem
* the default string charset to use.
* @since 1.7
*/
- public QuotedPrintableCodec(Charset charset) {
+ public QuotedPrintableCodec(final Charset charset) {
this.charset = charset;
}
@@ -120,7 +120,7 @@ public class QuotedPrintableCodec implem
*
* @since 1.7 throws UnsupportedCharsetException if the named charset is unavailable
*/
- public QuotedPrintableCodec(String charsetName)
+ public QuotedPrintableCodec(final String charsetName)
throws IllegalCharsetNameException, IllegalArgumentException, UnsupportedCharsetException {
this(Charset.forName(charsetName));
}
@@ -133,10 +133,10 @@ public class QuotedPrintableCodec implem
* @param buffer
* the buffer to write to
*/
- private static final void encodeQuotedPrintable(int b, ByteArrayOutputStream buffer) {
+ private static final void encodeQuotedPrintable(final int b, final ByteArrayOutputStream buffer) {
buffer.write(ESCAPE_CHAR);
- char hex1 = Character.toUpperCase(Character.forDigit((b >> 4) & 0xF, 16));
- char hex2 = Character.toUpperCase(Character.forDigit(b & 0xF, 16));
+ final char hex1 = Character.toUpperCase(Character.forDigit((b >> 4) & 0xF, 16));
+ final char hex2 = Character.toUpperCase(Character.forDigit(b & 0xF, 16));
buffer.write(hex1);
buffer.write(hex2);
}
@@ -153,15 +153,15 @@ public class QuotedPrintableCodec implem
* array of bytes to be encoded
* @return array of bytes containing quoted-printable data
*/
- public static final byte[] encodeQuotedPrintable(BitSet printable, byte[] bytes) {
+ public static final byte[] encodeQuotedPrintable(BitSet printable, final byte[] bytes) {
if (bytes == null) {
return null;
}
if (printable == null) {
printable = PRINTABLE_CHARS;
}
- ByteArrayOutputStream buffer = new ByteArrayOutputStream();
- for (byte c : bytes) {
+ final ByteArrayOutputStream buffer = new ByteArrayOutputStream();
+ for (final byte c : bytes) {
int b = c;
if (b < 0) {
b = 256 + b;
@@ -188,19 +188,19 @@ public class QuotedPrintableCodec implem
* @throws DecoderException
* Thrown if quoted-printable decoding is unsuccessful
*/
- public static final byte[] decodeQuotedPrintable(byte[] bytes) throws DecoderException {
+ public static final byte[] decodeQuotedPrintable(final byte[] bytes) throws DecoderException {
if (bytes == null) {
return null;
}
- ByteArrayOutputStream buffer = new ByteArrayOutputStream();
+ final ByteArrayOutputStream buffer = new ByteArrayOutputStream();
for (int i = 0; i < bytes.length; i++) {
- int b = bytes[i];
+ final int b = bytes[i];
if (b == ESCAPE_CHAR) {
try {
- int u = Utils.digit16(bytes[++i]);
- int l = Utils.digit16(bytes[++i]);
+ final int u = Utils.digit16(bytes[++i]);
+ final int l = Utils.digit16(bytes[++i]);
buffer.write((char) ((u << 4) + l));
- } catch (ArrayIndexOutOfBoundsException e) {
+ } catch (final ArrayIndexOutOfBoundsException e) {
throw new DecoderException("Invalid quoted-printable encoding", e);
}
} else {
@@ -221,7 +221,7 @@ public class QuotedPrintableCodec implem
* @return array of bytes containing quoted-printable data
*/
@Override
- public byte[] encode(byte[] bytes) {
+ public byte[] encode(final byte[] bytes) {
return encodeQuotedPrintable(PRINTABLE_CHARS, bytes);
}
@@ -239,7 +239,7 @@ public class QuotedPrintableCodec implem
* Thrown if quoted-printable decoding is unsuccessful
*/
@Override
- public byte[] decode(byte[] bytes) throws DecoderException {
+ public byte[] decode(final byte[] bytes) throws DecoderException {
return decodeQuotedPrintable(bytes);
}
@@ -258,7 +258,7 @@ public class QuotedPrintableCodec implem
* @see #getCharset()
*/
@Override
- public String encode(String str) throws EncoderException {
+ public String encode(final String str) throws EncoderException {
return this.encode(str, getCharset());
}
@@ -275,7 +275,7 @@ public class QuotedPrintableCodec implem
* Thrown if quoted-printable decoding is unsuccessful
* @since 1.7
*/
- public String decode(String str, Charset charset) throws DecoderException {
+ public String decode(final String str, final Charset charset) throws DecoderException {
if (str == null) {
return null;
}
@@ -296,7 +296,7 @@ public class QuotedPrintableCodec implem
* @throws UnsupportedEncodingException
* Thrown if charset is not supported
*/
- public String decode(String str, String charset) throws DecoderException, UnsupportedEncodingException {
+ public String decode(final String str, final String charset) throws DecoderException, UnsupportedEncodingException {
if (str == null) {
return null;
}
@@ -315,7 +315,7 @@ public class QuotedPrintableCodec implem
* @see #getCharset()
*/
@Override
- public String decode(String str) throws DecoderException {
+ public String decode(final String str) throws DecoderException {
return this.decode(str, this.getCharset());
}
@@ -330,7 +330,7 @@ public class QuotedPrintableCodec implem
* unsuccessful
*/
@Override
- public Object encode(Object obj) throws EncoderException {
+ public Object encode(final Object obj) throws EncoderException {
if (obj == null) {
return null;
} else if (obj instanceof byte[]) {
@@ -356,7 +356,7 @@ public class QuotedPrintableCodec implem
* condition is encountered during the decode process.
*/
@Override
- public Object decode(Object obj) throws DecoderException {
+ public Object decode(final Object obj) throws DecoderException {
if (obj == null) {
return null;
} else if (obj instanceof byte[]) {
@@ -402,7 +402,7 @@ public class QuotedPrintableCodec implem
* @return quoted-printable string
* @since 1.7
*/
- public String encode(String str, Charset charset) {
+ public String encode(final String str, final Charset charset) {
if (str == null) {
return null;
}
@@ -423,7 +423,7 @@ public class QuotedPrintableCodec implem
* @throws UnsupportedEncodingException
* Thrown if the charset is not supported
*/
- public String encode(String str, String charset) throws UnsupportedEncodingException {
+ public String encode(final String str, final String charset) throws UnsupportedEncodingException {
if (str == null) {
return null;
}
Modified: commons/proper/codec/trunk/src/main/java/org/apache/commons/codec/net/RFC1522Codec.java
URL: http://svn.apache.org/viewvc/commons/proper/codec/trunk/src/main/java/org/apache/commons/codec/net/RFC1522Codec.java?rev=1429868&r1=1429867&r2=1429868&view=diff
==============================================================================
--- commons/proper/codec/trunk/src/main/java/org/apache/commons/codec/net/RFC1522Codec.java (original)
+++ commons/proper/codec/trunk/src/main/java/org/apache/commons/codec/net/RFC1522Codec.java Mon Jan 7 16:08:05 2013
@@ -69,13 +69,13 @@ abstract class RFC1522Codec {
if (text == null) {
return null;
}
- StringBuilder buffer = new StringBuilder();
+ final StringBuilder buffer = new StringBuilder();
buffer.append(PREFIX);
buffer.append(charset);
buffer.append(SEP);
buffer.append(this.getEncoding());
buffer.append(SEP);
- byte [] rawData = this.doEncoding(text.getBytes(charset));
+ final byte [] rawData = this.doEncoding(text.getBytes(charset));
buffer.append(StringUtils.newStringUsAscii(rawData));
buffer.append(POSTFIX);
return buffer.toString();
@@ -129,13 +129,13 @@ abstract class RFC1522Codec {
if (!text.startsWith(PREFIX) || !text.endsWith(POSTFIX)) {
throw new DecoderException("RFC 1522 violation: malformed encoded content");
}
- int terminator = text.length() - 2;
+ final int terminator = text.length() - 2;
int from = 2;
int to = text.indexOf(SEP, from);
if (to == terminator) {
throw new DecoderException("RFC 1522 violation: charset token not found");
}
- String charset = text.substring(from, to);
+ final String charset = text.substring(from, to);
if (charset.equals("")) {
throw new DecoderException("RFC 1522 violation: charset not specified");
}
@@ -144,7 +144,7 @@ abstract class RFC1522Codec {
if (to == terminator) {
throw new DecoderException("RFC 1522 violation: encoding token not found");
}
- String encoding = text.substring(from, to);
+ final String encoding = text.substring(from, to);
if (!getEncoding().equalsIgnoreCase(encoding)) {
throw new DecoderException("This codec cannot decode " + encoding + " encoded content");
}
Modified: commons/proper/codec/trunk/src/main/java/org/apache/commons/codec/net/URLCodec.java
URL: http://svn.apache.org/viewvc/commons/proper/codec/trunk/src/main/java/org/apache/commons/codec/net/URLCodec.java?rev=1429868&r1=1429867&r2=1429868&view=diff
==============================================================================
--- commons/proper/codec/trunk/src/main/java/org/apache/commons/codec/net/URLCodec.java (original)
+++ commons/proper/codec/trunk/src/main/java/org/apache/commons/codec/net/URLCodec.java Mon Jan 7 16:08:05 2013
@@ -104,7 +104,7 @@ public class URLCodec implements BinaryE
*
* @param charset the default string charset to use.
*/
- public URLCodec(String charset) {
+ public URLCodec(final String charset) {
super();
this.charset = charset;
}
@@ -118,7 +118,7 @@ public class URLCodec implements BinaryE
* array of bytes to convert to URL safe characters
* @return array of bytes containing URL safe characters
*/
- public static final byte[] encodeUrl(BitSet urlsafe, byte[] bytes) {
+ public static final byte[] encodeUrl(BitSet urlsafe, final byte[] bytes) {
if (bytes == null) {
return null;
}
@@ -126,8 +126,8 @@ public class URLCodec implements BinaryE
urlsafe = WWW_FORM_URL;
}
- ByteArrayOutputStream buffer = new ByteArrayOutputStream();
- for (byte c : bytes) {
+ final ByteArrayOutputStream buffer = new ByteArrayOutputStream();
+ for (final byte c : bytes) {
int b = c;
if (b < 0) {
b = 256 + b;
@@ -139,8 +139,8 @@ public class URLCodec implements BinaryE
buffer.write(b);
} else {
buffer.write(ESCAPE_CHAR);
- char hex1 = Character.toUpperCase(Character.forDigit((b >> 4) & 0xF, RADIX));
- char hex2 = Character.toUpperCase(Character.forDigit(b & 0xF, RADIX));
+ final char hex1 = Character.toUpperCase(Character.forDigit((b >> 4) & 0xF, RADIX));
+ final char hex2 = Character.toUpperCase(Character.forDigit(b & 0xF, RADIX));
buffer.write(hex1);
buffer.write(hex2);
}
@@ -158,21 +158,21 @@ public class URLCodec implements BinaryE
* @throws DecoderException
* Thrown if URL decoding is unsuccessful
*/
- public static final byte[] decodeUrl(byte[] bytes) throws DecoderException {
+ public static final byte[] decodeUrl(final byte[] bytes) throws DecoderException {
if (bytes == null) {
return null;
}
- ByteArrayOutputStream buffer = new ByteArrayOutputStream();
+ final ByteArrayOutputStream buffer = new ByteArrayOutputStream();
for (int i = 0; i < bytes.length; i++) {
- int b = bytes[i];
+ final int b = bytes[i];
if (b == '+') {
buffer.write(' ');
} else if (b == ESCAPE_CHAR) {
try {
- int u = Utils.digit16(bytes[++i]);
- int l = Utils.digit16(bytes[++i]);
+ final int u = Utils.digit16(bytes[++i]);
+ final int l = Utils.digit16(bytes[++i]);
buffer.write((char) ((u << 4) + l));
- } catch (ArrayIndexOutOfBoundsException e) {
+ } catch (final ArrayIndexOutOfBoundsException e) {
throw new DecoderException("Invalid URL encoding: ", e);
}
} else {
@@ -190,7 +190,7 @@ public class URLCodec implements BinaryE
* @return array of bytes containing URL safe characters
*/
@Override
- public byte[] encode(byte[] bytes) {
+ public byte[] encode(final byte[] bytes) {
return encodeUrl(WWW_FORM_URL, bytes);
}
@@ -206,7 +206,7 @@ public class URLCodec implements BinaryE
* Thrown if URL decoding is unsuccessful
*/
@Override
- public byte[] decode(byte[] bytes) throws DecoderException {
+ public byte[] decode(final byte[] bytes) throws DecoderException {
return decodeUrl(bytes);
}
@@ -221,7 +221,7 @@ public class URLCodec implements BinaryE
* @throws UnsupportedEncodingException
* Thrown if charset is not supported
*/
- public String encode(String str, String charset) throws UnsupportedEncodingException {
+ public String encode(final String str, final String charset) throws UnsupportedEncodingException {
if (str == null) {
return null;
}
@@ -240,13 +240,13 @@ public class URLCodec implements BinaryE
* @see #getDefaultCharset()
*/
@Override
- public String encode(String str) throws EncoderException {
+ public String encode(final String str) throws EncoderException {
if (str == null) {
return null;
}
try {
return encode(str, getDefaultCharset());
- } catch (UnsupportedEncodingException e) {
+ } catch (final UnsupportedEncodingException e) {
throw new EncoderException(e.getMessage(), e);
}
}
@@ -266,7 +266,7 @@ public class URLCodec implements BinaryE
* @throws UnsupportedEncodingException
* Thrown if charset is not supported
*/
- public String decode(String str, String charset) throws DecoderException, UnsupportedEncodingException {
+ public String decode(final String str, final String charset) throws DecoderException, UnsupportedEncodingException {
if (str == null) {
return null;
}
@@ -285,13 +285,13 @@ public class URLCodec implements BinaryE
* @see #getDefaultCharset()
*/
@Override
- public String decode(String str) throws DecoderException {
+ public String decode(final String str) throws DecoderException {
if (str == null) {
return null;
}
try {
return decode(str, getDefaultCharset());
- } catch (UnsupportedEncodingException e) {
+ } catch (final UnsupportedEncodingException e) {
throw new DecoderException(e.getMessage(), e);
}
}
@@ -306,7 +306,7 @@ public class URLCodec implements BinaryE
* Thrown if URL encoding is not applicable to objects of this type or if encoding is unsuccessful
*/
@Override
- public Object encode(Object obj) throws EncoderException {
+ public Object encode(final Object obj) throws EncoderException {
if (obj == null) {
return null;
} else if (obj instanceof byte[]) {
@@ -331,7 +331,7 @@ public class URLCodec implements BinaryE
* condition is encountered during the decode process.
*/
@Override
- public Object decode(Object obj) throws DecoderException {
+ public Object decode(final Object obj) throws DecoderException {
if (obj == null) {
return null;
} else if (obj instanceof byte[]) {
Modified: commons/proper/codec/trunk/src/main/java/org/apache/commons/codec/net/Utils.java
URL: http://svn.apache.org/viewvc/commons/proper/codec/trunk/src/main/java/org/apache/commons/codec/net/Utils.java?rev=1429868&r1=1429867&r2=1429868&view=diff
==============================================================================
--- commons/proper/codec/trunk/src/main/java/org/apache/commons/codec/net/Utils.java (original)
+++ commons/proper/codec/trunk/src/main/java/org/apache/commons/codec/net/Utils.java Mon Jan 7 16:08:05 2013
@@ -39,8 +39,8 @@ class Utils {
* @throws DecoderException
* Thrown when the byte is not valid per {@link Character#digit(char,int)}
*/
- static int digit16(byte b) throws DecoderException {
- int i = Character.digit((char) b, 16);
+ static int digit16(final byte b) throws DecoderException {
+ final int i = Character.digit((char) b, 16);
if (i == -1) {
throw new DecoderException("Invalid URL encoding: not a valid digit (radix " + URLCodec.RADIX + "): " + b);
}
Modified: commons/proper/codec/trunk/src/test/java/org/apache/commons/codec/BinaryEncoderAbstractTest.java
URL: http://svn.apache.org/viewvc/commons/proper/codec/trunk/src/test/java/org/apache/commons/codec/BinaryEncoderAbstractTest.java?rev=1429868&r1=1429867&r2=1429868&view=diff
==============================================================================
--- commons/proper/codec/trunk/src/test/java/org/apache/commons/codec/BinaryEncoderAbstractTest.java (original)
+++ commons/proper/codec/trunk/src/test/java/org/apache/commons/codec/BinaryEncoderAbstractTest.java Mon Jan 7 16:08:05 2013
@@ -28,16 +28,16 @@ public abstract class BinaryEncoderAbstr
@Test
public void testEncodeEmpty() throws Exception {
- BinaryEncoder encoder = makeEncoder();
+ final BinaryEncoder encoder = makeEncoder();
encoder.encode(new byte[0]);
}
@Test
public void testEncodeNull() throws Exception {
- BinaryEncoder encoder = makeEncoder();
+ final BinaryEncoder encoder = makeEncoder();
try {
encoder.encode(null);
- } catch (EncoderException ee) {
+ } catch (final EncoderException ee) {
// An exception should be thrown
}
}
Modified: commons/proper/codec/trunk/src/test/java/org/apache/commons/codec/DecoderExceptionTest.java
URL: http://svn.apache.org/viewvc/commons/proper/codec/trunk/src/test/java/org/apache/commons/codec/DecoderExceptionTest.java?rev=1429868&r1=1429867&r2=1429868&view=diff
==============================================================================
--- commons/proper/codec/trunk/src/test/java/org/apache/commons/codec/DecoderExceptionTest.java (original)
+++ commons/proper/codec/trunk/src/test/java/org/apache/commons/codec/DecoderExceptionTest.java Mon Jan 7 16:08:05 2013
@@ -35,28 +35,28 @@ public class DecoderExceptionTest {
@Test
public void testConstructor0() {
- DecoderException e = new DecoderException();
+ final DecoderException e = new DecoderException();
assertNull(e.getMessage());
assertNull(e.getCause());
}
@Test
public void testConstructorString() {
- DecoderException e = new DecoderException(MSG);
+ final DecoderException e = new DecoderException(MSG);
assertEquals(MSG, e.getMessage());
assertNull(e.getCause());
}
@Test
public void testConstructorStringThrowable() {
- DecoderException e = new DecoderException(MSG, t);
+ final DecoderException e = new DecoderException(MSG, t);
assertEquals(MSG, e.getMessage());
assertEquals(t, e.getCause());
}
@Test
public void testConstructorThrowable() {
- DecoderException e = new DecoderException(t);
+ final DecoderException e = new DecoderException(t);
assertEquals(t.getClass().getName(), e.getMessage());
assertEquals(t, e.getCause());
}
Modified: commons/proper/codec/trunk/src/test/java/org/apache/commons/codec/EncoderExceptionTest.java
URL: http://svn.apache.org/viewvc/commons/proper/codec/trunk/src/test/java/org/apache/commons/codec/EncoderExceptionTest.java?rev=1429868&r1=1429867&r2=1429868&view=diff
==============================================================================
--- commons/proper/codec/trunk/src/test/java/org/apache/commons/codec/EncoderExceptionTest.java (original)
+++ commons/proper/codec/trunk/src/test/java/org/apache/commons/codec/EncoderExceptionTest.java Mon Jan 7 16:08:05 2013
@@ -35,28 +35,28 @@ public class EncoderExceptionTest {
@Test
public void testConstructor0() {
- EncoderException e = new EncoderException();
+ final EncoderException e = new EncoderException();
assertNull(e.getMessage());
assertNull(e.getCause());
}
@Test
public void testConstructorString() {
- EncoderException e = new EncoderException(MSG);
+ final EncoderException e = new EncoderException(MSG);
assertEquals(MSG, e.getMessage());
assertNull(e.getCause());
}
@Test
public void testConstructorStringThrowable() {
- EncoderException e = new EncoderException(MSG, t);
+ final EncoderException e = new EncoderException(MSG, t);
assertEquals(MSG, e.getMessage());
assertEquals(t, e.getCause());
}
@Test
public void testConstructorThrowable() {
- EncoderException e = new EncoderException(t);
+ final EncoderException e = new EncoderException(t);
assertEquals(t.getClass().getName(), e.getMessage());
assertEquals(t, e.getCause());
}
Modified: commons/proper/codec/trunk/src/test/java/org/apache/commons/codec/StringEncoderAbstractTest.java
URL: http://svn.apache.org/viewvc/commons/proper/codec/trunk/src/test/java/org/apache/commons/codec/StringEncoderAbstractTest.java?rev=1429868&r1=1429867&r2=1429868&view=diff
==============================================================================
--- commons/proper/codec/trunk/src/test/java/org/apache/commons/codec/StringEncoderAbstractTest.java (original)
+++ commons/proper/codec/trunk/src/test/java/org/apache/commons/codec/StringEncoderAbstractTest.java Mon Jan 7 16:08:05 2013
@@ -30,18 +30,18 @@ public abstract class StringEncoderAbstr
protected T stringEncoder = this.createStringEncoder();
- public void checkEncoding(String expected, String source) throws EncoderException {
+ public void checkEncoding(final String expected, final String source) throws EncoderException {
Assert.assertEquals("Source: " + source, expected, this.getStringEncoder().encode(source));
}
- protected void checkEncodings(String[][] data) throws EncoderException {
- for (String[] element : data) {
+ protected void checkEncodings(final String[][] data) throws EncoderException {
+ for (final String[] element : data) {
this.checkEncoding(element[1], element[0]);
}
}
- protected void checkEncodingVariations(String expected, String data[]) throws EncoderException {
- for (String element : data) {
+ protected void checkEncodingVariations(final String expected, final String data[]) throws EncoderException {
+ for (final String element : data) {
this.checkEncoding(expected, element);
}
}
@@ -54,7 +54,7 @@ public abstract class StringEncoderAbstr
@Test
public void testEncodeEmpty() throws Exception {
- Encoder encoder = this.getStringEncoder();
+ final Encoder encoder = this.getStringEncoder();
encoder.encode("");
encoder.encode(" ");
encoder.encode("\t");
@@ -62,10 +62,10 @@ public abstract class StringEncoderAbstr
@Test
public void testEncodeNull() throws Exception {
- StringEncoder encoder = this.getStringEncoder();
+ final StringEncoder encoder = this.getStringEncoder();
try {
encoder.encode(null);
- } catch (EncoderException ee) {
+ } catch (final EncoderException ee) {
// An exception should be thrown
}
}
@@ -74,9 +74,9 @@ public abstract class StringEncoderAbstr
public void testEncodeWithInvalidObject() throws Exception {
boolean exceptionThrown = false;
try {
- StringEncoder encoder = this.getStringEncoder();
+ final StringEncoder encoder = this.getStringEncoder();
encoder.encode(new Float(3.4));
- } catch (Exception e) {
+ } catch (final Exception e) {
exceptionThrown = true;
}
Assert.assertTrue("An exception was not thrown when we tried to encode " + "a Float object", exceptionThrown);
@@ -84,15 +84,15 @@ public abstract class StringEncoderAbstr
@Test
public void testLocaleIndependence() throws Exception {
- StringEncoder encoder = this.getStringEncoder();
+ final StringEncoder encoder = this.getStringEncoder();
- String[] data = {"I", "i",};
+ final String[] data = {"I", "i",};
- Locale orig = Locale.getDefault();
- Locale[] locales = {Locale.ENGLISH, new Locale("tr"), Locale.getDefault()};
+ final Locale orig = Locale.getDefault();
+ final Locale[] locales = {Locale.ENGLISH, new Locale("tr"), Locale.getDefault()};
try {
- for (String element : data) {
+ for (final String element : data) {
String ref = null;
for (int j = 0; j < locales.length; j++) {
Locale.setDefault(locales[j]);
@@ -102,7 +102,7 @@ public abstract class StringEncoderAbstr
String cur = null;
try {
cur = encoder.encode(element);
- } catch (Exception e) {
+ } catch (final Exception e) {
Assert.fail(Locale.getDefault().toString() + ": " + e.getMessage());
}
Assert.assertEquals(Locale.getDefault().toString() + ": ", ref, cur);
Modified: commons/proper/codec/trunk/src/test/java/org/apache/commons/codec/StringEncoderComparatorTest.java
URL: http://svn.apache.org/viewvc/commons/proper/codec/trunk/src/test/java/org/apache/commons/codec/StringEncoderComparatorTest.java?rev=1429868&r1=1429867&r2=1429868&view=diff
==============================================================================
--- commons/proper/codec/trunk/src/test/java/org/apache/commons/codec/StringEncoderComparatorTest.java (original)
+++ commons/proper/codec/trunk/src/test/java/org/apache/commons/codec/StringEncoderComparatorTest.java Mon Jan 7 16:08:05 2013
@@ -37,7 +37,7 @@ public class StringEncoderComparatorTest
@Test
public void testComparatorWithSoundex() throws Exception {
- StringEncoderComparator sCompare =
+ final StringEncoderComparator sCompare =
new StringEncoderComparator( new Soundex() );
assertTrue( "O'Brien and O'Brian didn't come out with " +
@@ -47,16 +47,16 @@ public class StringEncoderComparatorTest
@Test
public void testComparatorWithDoubleMetaphone() throws Exception {
- StringEncoderComparator sCompare = new StringEncoderComparator(new DoubleMetaphone());
+ final StringEncoderComparator sCompare = new StringEncoderComparator(new DoubleMetaphone());
- String[] testArray = { "Jordan", "Sosa", "Prior", "Pryor" };
- List<String> testList = Arrays.asList(testArray);
+ final String[] testArray = { "Jordan", "Sosa", "Prior", "Pryor" };
+ final List<String> testList = Arrays.asList(testArray);
- String[] controlArray = { "Jordan", "Prior", "Pryor", "Sosa" };
+ final String[] controlArray = { "Jordan", "Prior", "Pryor", "Sosa" };
Collections.sort(testList, sCompare);
- String[] resultArray = testList.toArray(new String[0]);
+ final String[] resultArray = testList.toArray(new String[0]);
for (int i = 0; i < resultArray.length; i++) {
assertEquals("Result Array not Equal to Control Array at index: " + i, controlArray[i], resultArray[i]);
@@ -65,10 +65,10 @@ public class StringEncoderComparatorTest
@Test
public void testComparatorWithDoubleMetaphoneAndInvalidInput() throws Exception {
- StringEncoderComparator sCompare =
+ final StringEncoderComparator sCompare =
new StringEncoderComparator( new DoubleMetaphone() );
- int compare = sCompare.compare(new Double(3.0), Long.valueOf(3));
+ final int compare = sCompare.compare(new Double(3.0), Long.valueOf(3));
assertEquals( "Trying to compare objects that make no sense to the underlying encoder should return a zero compare code",
0, compare);
}