commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From s...@apache.org
Subject [text] Fix generics warnings; allows several casts to be dropped
Date Tue, 07 Feb 2017 10:58:44 GMT
Repository: commons-text
Updated Branches:
  refs/heads/master d24d8b257 -> 72733aea2


Fix generics warnings; allows several casts to be dropped

Project: http://git-wip-us.apache.org/repos/asf/commons-text/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-text/commit/72733aea
Tree: http://git-wip-us.apache.org/repos/asf/commons-text/tree/72733aea
Diff: http://git-wip-us.apache.org/repos/asf/commons-text/diff/72733aea

Branch: refs/heads/master
Commit: 72733aea2fa536d98804ee09358fa50ca9ce41a8
Parents: d24d8b2
Author: Sebb <sebb@apache.org>
Authored: Tue Feb 7 10:57:17 2017 +0000
Committer: Sebb <sebb@apache.org>
Committed: Tue Feb 7 10:57:17 2017 +0000

----------------------------------------------------------------------
 .../text/beta/translate/EntityArrays.java       |  4 ++--
 .../text/beta/translate/LookupTranslator.java   | 11 +++++------
 .../beta/translate/SingleLookupTranslator.java  | 20 +++++++++-----------
 .../beta/translate/SinglePassTranslator.java    |  2 +-
 .../text/beta/translate/EntityArraysTest.java   |  3 ++-
 5 files changed, 19 insertions(+), 21 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-text/blob/72733aea/src/main/java/org/apache/commons/text/beta/translate/EntityArrays.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/text/beta/translate/EntityArrays.java b/src/main/java/org/apache/commons/text/beta/translate/EntityArrays.java
index 6c8a891..2db22f0 100644
--- a/src/main/java/org/apache/commons/text/beta/translate/EntityArrays.java
+++ b/src/main/java/org/apache/commons/text/beta/translate/EntityArrays.java
@@ -434,9 +434,9 @@ public class EntityArrays {
      */
     public static Map<CharSequence, CharSequence> invert(final Map<CharSequence,
CharSequence> map) {
         Map<CharSequence, CharSequence> newMap = new HashMap<>();
-        Iterator it = map.entrySet().iterator();
+        Iterator<Map.Entry<CharSequence, CharSequence>> it = map.entrySet().iterator();
         while (it.hasNext()) {
-            Map.Entry pair = (Map.Entry)it.next();
+            Map.Entry<CharSequence, CharSequence> pair = it.next();
             newMap.put((CharSequence) pair.getValue(), (CharSequence) pair.getKey());
         }
         return newMap;

http://git-wip-us.apache.org/repos/asf/commons-text/blob/72733aea/src/main/java/org/apache/commons/text/beta/translate/LookupTranslator.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/text/beta/translate/LookupTranslator.java b/src/main/java/org/apache/commons/text/beta/translate/LookupTranslator.java
index 3e8bd0b..064ab27 100644
--- a/src/main/java/org/apache/commons/text/beta/translate/LookupTranslator.java
+++ b/src/main/java/org/apache/commons/text/beta/translate/LookupTranslator.java
@@ -55,14 +55,13 @@ public class LookupTranslator extends CharSequenceTranslator {
         prefixSet = new HashSet<>();
         int _shortest = Integer.MAX_VALUE;
         int _longest = 0;
-        Iterator it = lookupMap.entrySet().iterator();
+        Iterator<Map.Entry<CharSequence, CharSequence>> it = lookupMap.entrySet().iterator();
 
         while (it.hasNext()) {
-            Map.Entry pair = (Map.Entry)it.next();
-            this.lookupMap.put(((CharSequence) pair.getKey()).toString(),
-                    ((CharSequence) pair.getValue()).toString());
-            this.prefixSet.add(((CharSequence) pair.getKey()).charAt(0));
-            final int sz = ((CharSequence) pair.getKey()).length();
+            Map.Entry<CharSequence, CharSequence> pair = it.next();
+            this.lookupMap.put(pair.getKey().toString(), pair.getValue().toString());
+            this.prefixSet.add((pair.getKey()).charAt(0));
+            final int sz = pair.getKey().length();
             if (sz < _shortest) {
                 _shortest = sz;
             }

http://git-wip-us.apache.org/repos/asf/commons-text/blob/72733aea/src/main/java/org/apache/commons/text/beta/translate/SingleLookupTranslator.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/text/beta/translate/SingleLookupTranslator.java
b/src/main/java/org/apache/commons/text/beta/translate/SingleLookupTranslator.java
index 744f701..b98cf57 100644
--- a/src/main/java/org/apache/commons/text/beta/translate/SingleLookupTranslator.java
+++ b/src/main/java/org/apache/commons/text/beta/translate/SingleLookupTranslator.java
@@ -56,11 +56,10 @@ public class SingleLookupTranslator extends CharSequenceTranslator {
     public SingleLookupTranslator(Map<CharSequence, CharSequence>... inputMaps) {
         Map<CharSequence, CharSequence> lookup = new HashMap<>();
         for (Map<CharSequence, CharSequence> input : inputMaps) {
-            Iterator it = input.entrySet().iterator();
+            Iterator<Map.Entry<CharSequence, CharSequence>> it = input.entrySet().iterator();
             while (it.hasNext()) {
-                Map.Entry pair = (Map.Entry) it.next();
-                lookup.put((CharSequence) pair.getKey(),
-                        (CharSequence) pair.getValue());
+                Map.Entry<CharSequence, CharSequence> pair = it.next();
+                lookup.put(pair.getKey(), pair.getValue());
             }
         }
         lookupMap = new HashMap<String, String>();
@@ -70,20 +69,19 @@ public class SingleLookupTranslator extends CharSequenceTranslator {
         int _shortestValue = Integer.MAX_VALUE;
         int _longestValue = 0;
         if (lookup != null) {
-            Iterator it = lookup.entrySet().iterator();
+            Iterator<Map.Entry<CharSequence, CharSequence>> it = lookup.entrySet().iterator();
             while (it.hasNext()) {
-                Map.Entry pair = (Map.Entry) it.next();
-                this.lookupMap.put(((CharSequence) pair.getKey()).toString(),
-                        ((CharSequence) pair.getValue()).toString().toString());
-                this.prefixSet.add(((CharSequence) pair.getKey()).charAt(0));
-                final int sz = ((CharSequence) pair.getKey()).length();
+                Map.Entry<CharSequence, CharSequence> pair = it.next();
+                this.lookupMap.put(pair.getKey().toString(), pair.getValue().toString().toString());
+                this.prefixSet.add(pair.getKey().charAt(0));
+                final int sz = pair.getKey().length();
                 if (sz < _shortest) {
                     _shortest = sz;
                 }
                 if (sz > _longest) {
                     _longest = sz;
                 }
-                final int sizeOfValue = lookup.get(((CharSequence) pair.getKey())).length();
+                final int sizeOfValue = lookup.get(pair.getKey()).length();
                 if (sizeOfValue < _shortestValue) {
                     _shortestValue = sizeOfValue;
                 }

http://git-wip-us.apache.org/repos/asf/commons-text/blob/72733aea/src/main/java/org/apache/commons/text/beta/translate/SinglePassTranslator.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/text/beta/translate/SinglePassTranslator.java
b/src/main/java/org/apache/commons/text/beta/translate/SinglePassTranslator.java
index a8bdf45..1d06ec6 100644
--- a/src/main/java/org/apache/commons/text/beta/translate/SinglePassTranslator.java
+++ b/src/main/java/org/apache/commons/text/beta/translate/SinglePassTranslator.java
@@ -38,7 +38,7 @@ abstract class SinglePassTranslator extends CharSequenceTranslator {
     }
 
     private String getClassName() {
-        final Class clazz = this.getClass();
+        final Class<? extends SinglePassTranslator> clazz = this.getClass();
         return clazz.isAnonymousClass() ?  clazz.getName() : clazz.getSimpleName();
     }
 

http://git-wip-us.apache.org/repos/asf/commons-text/blob/72733aea/src/test/java/org/apache/commons/text/beta/translate/EntityArraysTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/text/beta/translate/EntityArraysTest.java b/src/test/java/org/apache/commons/text/beta/translate/EntityArraysTest.java
index 2bb8d59..38b796e 100644
--- a/src/test/java/org/apache/commons/text/beta/translate/EntityArraysTest.java
+++ b/src/test/java/org/apache/commons/text/beta/translate/EntityArraysTest.java
@@ -50,7 +50,8 @@ public class EntityArraysTest  {
                     mapDeclarationCounter++;
                 } else if (line.contains("Collections.unmodifiableMap(initialMap);")) {
                     String mapVariableName = line.split("=")[0].trim();
-                    Map<String,String> mapValue = (Map)EntityArrays.class.getDeclaredField(mapVariableName).get(EntityArrays.class);
+                    @SuppressWarnings("unchecked") // This is test code
+                    Map<String,String> mapValue = (Map<String, String>)EntityArrays.class.getDeclaredField(mapVariableName).get(EntityArrays.class);
                     // Validate that we are not inserting into the same key twice in the
map declaration. If this,
                     // indeed was the case the keySet().size() would be smaller than the
number of put() statements
                     assertEquals(mapDeclarationCounter, mapValue.keySet().size());


Mime
View raw message