]> granicus.if.org Git - icu/commitdiff
ICU-12812 Fixed javac compiler warnings, Eclipse complier warnings, javadoc warnings...
authorYoshito Umaoka <y.umaoka@gmail.com>
Thu, 23 Mar 2017 06:50:00 +0000 (06:50 +0000)
committerYoshito Umaoka <y.umaoka@gmail.com>
Thu, 23 Mar 2017 06:50:00 +0000 (06:50 +0000)
X-SVN-Rev: 39917

icu4j/main/classes/core/src/com/ibm/icu/impl/locale/XCldrStub.java
icu4j/main/classes/core/src/com/ibm/icu/impl/locale/XLikelySubtags.java
icu4j/main/classes/core/src/com/ibm/icu/impl/locale/XLocaleDistance.java
icu4j/main/classes/core/src/com/ibm/icu/impl/locale/XLocaleMatcher.java
icu4j/main/tests/core/src/com/ibm/icu/dev/test/util/XLocaleDistanceTest.java
icu4j/main/tests/core/src/com/ibm/icu/dev/test/util/XLocaleMatcherTest.java

index ce1968b3feddde8f6b32099a590281ab9850bc4b..6d22a2779dd7de1e5e7ab30f2eb32986d3865877 100644 (file)
@@ -111,9 +111,22 @@ public class XCldrStub {
         }
         @Override
         public boolean equals(Object obj) {
-            Multimap<K,V> 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<T> implements Iterable<T>{
-        private Map<T,Long> data;
-        @Override
-        public Iterator<T> 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<T> implements Iterable<T>{
+//        private Map<T,Long> data;
+//        @Override
+//        public Iterator<T> 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 <T> 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);
index 5279bcdaaab8ab767ac3aaed797f41fe75ed9845..371b2bc24d5db27cfefc69abaea2b201d821bba9 100644 (file)
@@ -30,10 +30,10 @@ public class XLikelySubtags {
         return DEFAULT;
     }
 
+    @SuppressWarnings("unchecked")
     static abstract class Maker {
         abstract <V> V make();
 
-        @SuppressWarnings("unchecked")
         public <K,V> V getSubtable(Map<K, V> 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<Object,Object> make() {
                 return new HashMap<Object,Object>();
             }
@@ -52,7 +51,6 @@ public class XLikelySubtags {
 
         static final Maker TREEMAP = new Maker() {
             @Override
-            @SuppressWarnings("unchecked")
             public Map<Object,Object> make() {
                 return new TreeMap<Object,Object>();
             }
@@ -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<String, Map<String, Map<String, LSR>>> langTable, final String language, final String script, final String region, LSR newValue) {
         Map<String, Map<String, LSR>> scriptTable = Maker.TREEMAP.getSubtable(langTable, language);
         Map<String, LSR> 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 <V> StringBuilder show(Map<String,V> map, String indent, StringBuilder output) {
+    private static StringBuilder show(Map<?,?> map, String indent, StringBuilder output) {
         String first = indent.isEmpty() ? "" : "\t";
-        for (Entry<String,V> 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");
             }
index 6e1c1f138c02fab0b1745395f92274cef48a1fc2..9f98b3765ccc4052caad075c0f9d39c720332716 100644 (file)
@@ -77,6 +77,7 @@ public class XLocaleDistance {
         return Collections.unmodifiableList(distanceList);
     }
 
+    @SuppressWarnings("unused")
     private static Set<String> 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<String, String> 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<T> 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<String, Map<String, DistanceNode>> tables) {
             subtables = tables;
         }
+        @SuppressWarnings("unchecked")
         StringDistanceTable() {
             this(newMap());
         }
@@ -466,11 +479,13 @@ public class XLocaleDistance {
             for (Entry<String, Map<String, DistanceNode>> e1 : other.subtables.entrySet()) {
                 for (Entry<String, DistanceNode> 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<String, DistanceNode> sub2 = subtables.get(desired);
             if (sub2 == null) {
@@ -503,7 +518,6 @@ public class XLocaleDistance {
         public void addSubtables(
                 String desired, String supported,
                 Predicate<DistanceNode> 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<String, Map<String, DistanceNode>> 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<String, Map<String, DistanceNode>> 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<Row.R4<List<String>, List<String>, Integer, Boolean>>[] sorted = new ArrayList[3];
         sorted[0] = new ArrayList<Row.R4<List<String>, List<String>, Integer, Boolean>>();
         sorted[1] = new ArrayList<Row.R4<List<String>, List<String>, Integer, Boolean>>();
@@ -892,7 +905,6 @@ public class XLocaleDistance {
         }
 
         for (List<Row.R4<List<String>, List<String>, Integer, Boolean>> item1 : sorted) {
-            int debug = 0;
             for (Row.R4<List<String>, List<String>, Integer, Boolean> item2 : item1) {
                 List<String> desired = item2.get0();
                 List<String> 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<String> desiredBase = new ArrayList<String>(bar.splitToList(rule[0]));
             List<String> supportedBase = new ArrayList<String>(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<String> match) {
         List<String> alt = new ArrayList<String>(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<String,String> regionToPartition;
         /**
          * Used to support es_419 compared to es_AR, etc.
-         * @param variableToPartitionIn
-         * @param regionToPartitionIn
          */
         final Multimap<String,String> macroToPartitions;
         /**
@@ -1285,9 +1300,10 @@ public class XLocaleDistance {
             }
             return new StringDistanceTable(compact(item.subtables, 0));
         }
+        @SuppressWarnings({ "unchecked", "rawtypes" })
         <K,T> Map<K,T> compact(Map<K,T> item, int level) {
             if (toId(item) != null) {
-                return (Map<K,T>)intern(item);
+                return (Map<K, T>) intern(item);
             }
             Map<K,T> copy = new LinkedHashMap<K,T>();
             for (Entry<K,T> entry : item.entrySet()) {
index 3bd8a16e8d8f7893a599555baf1548b9ceb6aa40..4623884771a18f2644e633bee18fc810e8784b12 100644 (file)
@@ -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<ULocale> desiredLanguages, Output<ULocale> 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<ULocale> outputBestDesired) {
         int bestDistance = Integer.MAX_VALUE;
index 417d3ee86cc0eabf2247c15955e207ca16a30f25..3f3b24b589e7f2ffc5727a344da866f817012d76 100644 (file)
@@ -51,6 +51,7 @@ public class XLocaleDistanceTest extends TestFmwk {
     }
 
     // @ Test Disabled because of Linux; need to investigate.
+    @SuppressWarnings("unused")
     public void testTiming() {
         List<Arguments> testArgs = new ArrayList<Arguments>();
         for (List<String> line : tfh.getLines()) {
index 8e3b083fa88f8ebad1cb47da4f1ea8638027517d..0ba886598c2924a62c1c76adce3143bb37e7f2fb 100644 (file)
@@ -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 {