From: Yoshito Umaoka Date: Thu, 23 Mar 2017 06:50:00 +0000 (+0000) Subject: ICU-12812 Fixed javac compiler warnings, Eclipse complier warnings, javadoc warnings... X-Git-Tag: release-59-rc~55 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=f8add014b1fb7b9973a43a15776f593576b4b866;p=icu ICU-12812 Fixed javac compiler warnings, Eclipse complier warnings, javadoc warnings and issues found by FindBugs. X-SVN-Rev: 39917 --- diff --git a/icu4j/main/classes/core/src/com/ibm/icu/impl/locale/XCldrStub.java b/icu4j/main/classes/core/src/com/ibm/icu/impl/locale/XCldrStub.java index ce1968b3fed..6d22a2779dd 100644 --- a/icu4j/main/classes/core/src/com/ibm/icu/impl/locale/XCldrStub.java +++ b/icu4j/main/classes/core/src/com/ibm/icu/impl/locale/XCldrStub.java @@ -111,9 +111,22 @@ public class XCldrStub { } @Override public boolean equals(Object obj) { - Multimap other = (Multimap) obj; + if (this == obj) { + return true; + } + if (!(obj instanceof Multimap)) { + return false; + } + Multimap other = (Multimap) obj; return map.equals(other.map); } + + @Override + public int hashCode() { + // Not designed, return an arbitrary constant -123 for now + assert false; + return -123; + } } public static class Multimaps { @@ -215,21 +228,21 @@ public class XCldrStub { } - public static class Counter implements Iterable{ - private Map data; - @Override - public Iterator iterator() { - return data.keySet().iterator(); - } - public long get(T s) { - Long result = data.get(s); - return result != null ? result : 0L; - } - public void add(T item, int count) { - Long result = data.get(item); - data.put(item, result == null ? count : result + count); - } - } +// public static class Counter implements Iterable{ +// private Map data; +// @Override +// public Iterator iterator() { +// return data.keySet().iterator(); +// } +// public long get(T s) { +// Long result = data.get(s); +// return result != null ? result : 0L; +// } +// public void add(T item, int count) { +// Long result = data.get(item); +// data.put(item, result == null ? count : result + count); +// } +// } public static String join(T[] source, String separator) { StringBuilder result = new StringBuilder(); @@ -362,7 +375,8 @@ public class XCldrStub { } } public static String getRelativeFileName(Class class1, String filename) { - URL resource = class1.getResource(filename); + URL resource = class1 == null ? + FileUtilities.class.getResource(filename) : class1.getResource(filename); String resourceString = resource.toString(); if (resourceString.startsWith("file:")) { return resourceString.substring(5); diff --git a/icu4j/main/classes/core/src/com/ibm/icu/impl/locale/XLikelySubtags.java b/icu4j/main/classes/core/src/com/ibm/icu/impl/locale/XLikelySubtags.java index 5279bcdaaab..371b2bc24d5 100644 --- a/icu4j/main/classes/core/src/com/ibm/icu/impl/locale/XLikelySubtags.java +++ b/icu4j/main/classes/core/src/com/ibm/icu/impl/locale/XLikelySubtags.java @@ -30,10 +30,10 @@ public class XLikelySubtags { return DEFAULT; } + @SuppressWarnings("unchecked") static abstract class Maker { abstract V make(); - @SuppressWarnings("unchecked") public V getSubtable(Map langTable, final K language) { V scriptTable = langTable.get(language); if (scriptTable == null) { @@ -44,7 +44,6 @@ public class XLikelySubtags { static final Maker HASHMAP = new Maker() { @Override - @SuppressWarnings("unchecked") public Map make() { return new HashMap(); } @@ -52,7 +51,6 @@ public class XLikelySubtags { static final Maker TREEMAP = new Maker() { @Override - @SuppressWarnings("unchecked") public Map make() { return new TreeMap(); } @@ -199,6 +197,12 @@ public class XLikelySubtags { } @Override public boolean equals(Object obj) { + if (this == obj) { + return false; + } + if (!(obj instanceof LSR)) { + return false; + } LSR other = (LSR) obj; return language.equals(other.language) && script.equals(other.script) @@ -359,17 +363,15 @@ public class XLikelySubtags { private void set(Map>> langTable, final String language, final String script, final String region, LSR newValue) { Map> scriptTable = Maker.TREEMAP.getSubtable(langTable, language); Map regionTable = Maker.TREEMAP.getSubtable(scriptTable, script); - LSR oldValue = regionTable.get(region); - if (oldValue != null) { - int debug = 0; - } +// LSR oldValue = regionTable.get(region); +// if (oldValue != null) { +// int debug = 0; +// } regionTable.put(region, newValue); } /** * Convenience methods - * @param source - * @return */ public LSR maximize(String source) { return maximize(ULocale.forLanguageTag(source)); @@ -438,6 +440,7 @@ public class XLikelySubtags { } } + @SuppressWarnings("unused") private LSR minimizeSubtags(String languageIn, String scriptIn, String regionIn, Minimize fieldToFavor) { LSR result = maximize(languageIn, scriptIn, regionIn); @@ -456,7 +459,7 @@ public class XLikelySubtags { if (result.script.equals(value00.script)) { //script is default if (result.region.equals(value00.region)) { return result.replace(null, "", ""); - } else if (fieldToFavor == fieldToFavor.FAVOR_REGION) { + } else if (fieldToFavor == Minimize.FAVOR_REGION) { return result.replace(null, "", null); } else { favorRegionOk = true; @@ -474,14 +477,14 @@ public class XLikelySubtags { return result; } - private static StringBuilder show(Map map, String indent, StringBuilder output) { + private static StringBuilder show(Map map, String indent, StringBuilder output) { String first = indent.isEmpty() ? "" : "\t"; - for (Entry e : map.entrySet()) { - String key = e.getKey(); - V value = e.getValue(); + for (Entry e : map.entrySet()) { + String key = e.getKey().toString(); + Object value = e.getValue(); output.append(first + (key.isEmpty() ? "∅" : key)); if (value instanceof Map) { - show((Map)value, indent+"\t", output); + show((Map)value, indent+"\t", output); } else { output.append("\t" + Utility.toString(value)).append("\n"); } diff --git a/icu4j/main/classes/core/src/com/ibm/icu/impl/locale/XLocaleDistance.java b/icu4j/main/classes/core/src/com/ibm/icu/impl/locale/XLocaleDistance.java index 6e1c1f138c0..9f98b3765cc 100644 --- a/icu4j/main/classes/core/src/com/ibm/icu/impl/locale/XLocaleDistance.java +++ b/icu4j/main/classes/core/src/com/ibm/icu/impl/locale/XLocaleDistance.java @@ -77,6 +77,7 @@ public class XLocaleDistance { return Collections.unmodifiableList(distanceList); } + @SuppressWarnings("unused") private static Set xGetParadigmLocales() { ICUResourceBundle suppData = LocaleMatcher.getICUSupplementalData(); ICUResourceBundle languageMatchingInfo = suppData.findTopLevel("languageMatchingInfo"); @@ -87,6 +88,7 @@ public class XLocaleDistance { return Collections.unmodifiableSet(paradigmLocales); } + @SuppressWarnings("unused") private static Map xGetMatchVariables() { ICUResourceBundle suppData = LocaleMatcher.getICUSupplementalData(); ICUResourceBundle languageMatchingInfo = suppData.findTopLevel("languageMatchingInfo"); @@ -237,7 +239,8 @@ public class XLocaleDistance { return false; } DistanceNode other = (DistanceNode) obj; - return distance == other.distance; + return distance == other.distance + && this.getClass().equals(other.getClass()); } @Override public int hashCode() { @@ -331,10 +334,13 @@ public class XLocaleDistance { } @Override public boolean equals(Object obj) { + if (this == obj) { + return true; + } if (!(obj instanceof IdMakerFull)) { return false; } - IdMakerFull other = (IdMakerFull) obj; + IdMakerFull other = (IdMakerFull) obj; return intToObject.equals(other.intToObject); } @Override @@ -353,11 +359,16 @@ public class XLocaleDistance { @Override public boolean equals(Object obj) { + if (this == obj) { + return true; + } if (!(obj instanceof StringDistanceNode)) { return false; } StringDistanceNode other = (StringDistanceNode) obj; - return distance == other.distance && Utility.equals(distanceTable, other.distanceTable); + return distance == other.distance + && Utility.equals(distanceTable, other.distanceTable) + && super.equals(other); } @Override public int hashCode() { @@ -400,6 +411,7 @@ public class XLocaleDistance { defaultRegionDistance = regionNode.distance; } + @SuppressWarnings("rawtypes") private static Map newMap() { // for debugging return new TreeMap(); } @@ -414,6 +426,7 @@ public class XLocaleDistance { StringDistanceTable(Map> tables) { subtables = tables; } + @SuppressWarnings("unchecked") StringDistanceTable() { this(newMap()); } @@ -466,11 +479,13 @@ public class XLocaleDistance { for (Entry> e1 : other.subtables.entrySet()) { for (Entry e2 : e1.getValue().entrySet()) { DistanceNode value = e2.getValue(); + @SuppressWarnings("unused") DistanceNode subNode = addSubtable(e1.getKey(), e2.getKey(), value.distance); } } } + @SuppressWarnings("unchecked") DistanceNode addSubtable(String desired, String supported, int distance) { Map sub2 = subtables.get(desired); if (sub2 == null) { @@ -503,7 +518,6 @@ public class XLocaleDistance { public void addSubtables( String desired, String supported, Predicate action) { - int count = 0; DistanceNode node = getNode(desired, supported); if (node == null) { // get the distance it would have @@ -523,6 +537,7 @@ public class XLocaleDistance { int percentage) { // add to all the values that have the matching desiredLang and supportedLang + @SuppressWarnings("unused") boolean haveKeys = false; for (Entry> e1 : subtables.entrySet()) { String key1 = e1.getKey(); @@ -552,6 +567,7 @@ public class XLocaleDistance { int percentage) { // add to all the values that have the matching desiredLang and supportedLang + @SuppressWarnings("unused") boolean haveKeys = false; for (Entry> e1 : subtables.entrySet()) { String key1 = e1.getKey(); @@ -718,10 +734,6 @@ public class XLocaleDistance { /** * Returns distance, from 0 to ABOVE_THRESHOLD. * ULocales must be in canonical, addLikelySubtags format. Returns distance - * @param desired - * @param supported - * @param distanceOption - * @return */ public int distanceRaw(LSR desired, LSR supported, int threshold, DistanceOption distanceOption) { return distanceRaw(desired.language, supported.language, @@ -870,6 +882,7 @@ public class XLocaleDistance { Splitter bar = Splitter.on('_'); + @SuppressWarnings({"unchecked", "rawtypes"}) List, List, Integer, Boolean>>[] sorted = new ArrayList[3]; sorted[0] = new ArrayList, List, Integer, Boolean>>(); sorted[1] = new ArrayList, List, Integer, Boolean>>(); @@ -892,7 +905,6 @@ public class XLocaleDistance { } for (List, List, Integer, Boolean>> item1 : sorted) { - int debug = 0; for (Row.R4, List, Integer, Boolean> item2 : item1) { List desired = item2.get0(); List supported = item2.get1(); @@ -915,9 +927,9 @@ public class XLocaleDistance { // + "\" distance=\"" // + rule[2] // + "\"/>"); - if (rule[0].equals("en_*_*") || rule[1].equals("*_*_*")) { - int debug = 0; - } +// if (rule[0].equals("en_*_*") || rule[1].equals("*_*_*")) { +// int debug = 0; +// } List desiredBase = new ArrayList(bar.splitToList(rule[0])); List supportedBase = new ArrayList(bar.splitToList(rule[1])); Integer distance = 100-Integer.parseInt(rule[2]); @@ -946,7 +958,7 @@ public class XLocaleDistance { DEFAULT = new XLocaleDistance(defaultDistanceTable.compact(), defaultRegionMapper); - if (false && PRINT_OVERRIDES) { + if (PRINT_OVERRIDES) { System.out.println(defaultRegionMapper); System.out.println(defaultDistanceTable); throw new IllegalArgumentException(); @@ -970,23 +982,28 @@ public class XLocaleDistance { private static String fixedName(List match) { List alt = new ArrayList(match); + int size = alt.size(); + assert size >= 1 && size <= 3; + StringBuilder result = new StringBuilder(); - switch(alt.size()) { - case 3: + + if (size >= 3) { String region = alt.get(2); if (region.equals("*") || region.startsWith("$")) { result.append(region); } else { result.append(english.regionDisplayName(region)); } - case 2: + } + if (size >= 2) { String script = alt.get(1); if (script.equals("*")) { result.insert(0, script); } else { result.insert(0, english.scriptDisplayName(script)); } - case 1: + } + if (size >= 1) { String language = alt.get(0); if (language.equals("*")) { result.insert(0, language); @@ -1056,8 +1073,6 @@ public class XLocaleDistance { final Map regionToPartition; /** * Used to support es_419 compared to es_AR, etc. - * @param variableToPartitionIn - * @param regionToPartitionIn */ final Multimap macroToPartitions; /** @@ -1285,9 +1300,10 @@ public class XLocaleDistance { } return new StringDistanceTable(compact(item.subtables, 0)); } + @SuppressWarnings({ "unchecked", "rawtypes" }) Map compact(Map item, int level) { if (toId(item) != null) { - return (Map)intern(item); + return (Map) intern(item); } Map copy = new LinkedHashMap(); for (Entry entry : item.entrySet()) { diff --git a/icu4j/main/classes/core/src/com/ibm/icu/impl/locale/XLocaleMatcher.java b/icu4j/main/classes/core/src/com/ibm/icu/impl/locale/XLocaleMatcher.java index 3bd8a16e8d8..4623884771a 100644 --- a/icu4j/main/classes/core/src/com/ibm/icu/impl/locale/XLocaleMatcher.java +++ b/icu4j/main/classes/core/src/com/ibm/icu/impl/locale/XLocaleMatcher.java @@ -50,7 +50,7 @@ public class XLocaleMatcher { private DistanceOption distanceOption; /** * @param languagePriorityList the languagePriorityList to set - * @return + * @return this Builder object */ public Builder setSupportedLocales(String languagePriorityList) { this.supportedLanguagesList = asSet(LocalePriorityList.add(languagePriorityList).build()); @@ -67,7 +67,7 @@ public class XLocaleMatcher { /** * @param thresholdDistance the thresholdDistance to set, with -1 = default - * @return + * @return this Builder object */ public Builder setThresholdDistance(int thresholdDistance) { this.thresholdDistance = thresholdDistance; @@ -75,7 +75,7 @@ public class XLocaleMatcher { } /** * @param demotionPerAdditionalDesiredLocale the demotionPerAdditionalDesiredLocale to set, with -1 = default - * @return + * @return this Builder object */ public Builder setDemotionPerAdditionalDesiredLocale(int demotionPerAdditionalDesiredLocale) { this.demotionPerAdditionalDesiredLocale = demotionPerAdditionalDesiredLocale; @@ -84,7 +84,7 @@ public class XLocaleMatcher { /** * @param localeDistance the localeDistance to set, with default = XLocaleDistance.getDefault(). - * @return + * @return this Builder object */ public Builder setLocaleDistance(XLocaleDistance localeDistance) { this.localeDistance = localeDistance; @@ -93,8 +93,8 @@ public class XLocaleMatcher { /** * Set the default language, with null = default = first supported language - * @param defaultLanguage - * @return + * @param defaultLanguage the default language + * @return this Builder object */ public Builder setDefaultLanguage(ULocale defaultLanguage) { this.defaultLanguage = defaultLanguage; @@ -104,8 +104,8 @@ public class XLocaleMatcher { /** * If true, then the language differences are smaller than than script differences. * This is used in situations (such as maps) where it is better to fall back to the same script than a similar language. - * @param distanceOption - * @return + * @param distanceOption the distance option + * @return this Builder object */ public Builder setDistanceOption(DistanceOption distanceOption) { this.distanceOption = distanceOption; @@ -119,7 +119,7 @@ public class XLocaleMatcher { /** * Returns a builder used in chaining parameters for building a Locale Matcher. - * @return + * @return this Builder object */ public static Builder builder() { return new Builder(); @@ -243,7 +243,7 @@ public class XLocaleMatcher { * @param desiredLanguages Typically the supplied user's languages, in order of preference, with best first. * @param outputBestDesired The one of the desired languages that matched best. * Set to null if the best match was not below the threshold distance. - * @return + * @return the best match. */ public ULocale getBestMatch(Set desiredLanguages, Output outputBestDesired) { // fast path for singleton @@ -311,10 +311,10 @@ public class XLocaleMatcher { /** * Get the best match between the desired languages and supported languages - * @param desiredLanguages Typically the supplied user's languages, in order of preference, with best first. + * @param desiredLocale the supplied user's language. * @param outputBestDesired The one of the desired languages that matched best. * Set to null if the best match was not below the threshold distance. - * @return + * @return the best match. */ public ULocale getBestMatch(ULocale desiredLocale, Output outputBestDesired) { int bestDistance = Integer.MAX_VALUE; diff --git a/icu4j/main/tests/core/src/com/ibm/icu/dev/test/util/XLocaleDistanceTest.java b/icu4j/main/tests/core/src/com/ibm/icu/dev/test/util/XLocaleDistanceTest.java index 417d3ee86cc..3f3b24b589e 100644 --- a/icu4j/main/tests/core/src/com/ibm/icu/dev/test/util/XLocaleDistanceTest.java +++ b/icu4j/main/tests/core/src/com/ibm/icu/dev/test/util/XLocaleDistanceTest.java @@ -51,6 +51,7 @@ public class XLocaleDistanceTest extends TestFmwk { } // @ Test Disabled because of Linux; need to investigate. + @SuppressWarnings("unused") public void testTiming() { List testArgs = new ArrayList(); for (List line : tfh.getLines()) { diff --git a/icu4j/main/tests/core/src/com/ibm/icu/dev/test/util/XLocaleMatcherTest.java b/icu4j/main/tests/core/src/com/ibm/icu/dev/test/util/XLocaleMatcherTest.java index 8e3b083fa88..0ba886598c2 100644 --- a/icu4j/main/tests/core/src/com/ibm/icu/dev/test/util/XLocaleMatcherTest.java +++ b/icu4j/main/tests/core/src/com/ibm/icu/dev/test/util/XLocaleMatcherTest.java @@ -48,6 +48,7 @@ public class XLocaleMatcherTest extends TestFmwk { return new XLocaleMatcher(LocalePriorityList.add(string).build()); } + @SuppressWarnings("unused") private XLocaleMatcher newXLocaleMatcher(LocalePriorityList string, int d) { return XLocaleMatcher.builder().setSupportedLocales(string).setThresholdDistance(d).build(); } @@ -272,6 +273,7 @@ public class XLocaleMatcherTest extends TestFmwk { private static final Splitter COMMA_SPACE = Splitter.on(Pattern.compile(",\\s*|\\s+")).trimResults(); private static final Joiner JOIN_COMMA_SPACE = Joiner.on(", "); + @SuppressWarnings("unused") private static final UnicodeSet DIGITS = new UnicodeSet("[0-9]").freeze(); class MyTestFileHandler extends DataDrivenTestHelper {