ignite-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From GitBox <...@apache.org>
Subject [GitHub] [ignite] xtern commented on a change in pull request #6819: IGNITE-12116 Support array as key for caches.
Date Thu, 29 Aug 2019 12:14:30 GMT
xtern commented on a change in pull request #6819: IGNITE-12116 Support array as key for caches.
URL: https://github.com/apache/ignite/pull/6819#discussion_r319034968
 
 

 ##########
 File path: modules/core/src/main/java/org/apache/ignite/internal/util/IgniteUtils.java
 ##########
 @@ -5359,6 +5359,42 @@ public static void writeMap(ObjectOutput out, Map<?, ?> map)
throws IOException
         return map;
     }
 
+
+    /**
+     * Calculate a hashCode for an array.
+     *
+     * @param obj Object.
+     */
+    public static int hashCode(Object obj) {
+        if (obj.getClass().isArray()) {
+            if (obj instanceof byte[])
+                return Arrays.hashCode((byte[])obj);
+            if (obj instanceof short[])
+                return Arrays.hashCode((short[])obj);
+            if (obj instanceof int[])
+                return Arrays.hashCode((int[])obj);
+            if (obj instanceof long[])
+                return Arrays.hashCode((long[])obj);
+            if (obj instanceof float[])
+                return Arrays.hashCode((float[])obj);
+            if (obj instanceof double[])
+                return Arrays.hashCode((double[])obj);
+            if (obj instanceof char[])
+                return Arrays.hashCode((char[])obj);
+            if (obj instanceof boolean[])
+                return Arrays.hashCode((boolean[])obj);
+
+            int result = 1;
+
+            for (Object element : (Object[])obj)
+                result = 31 * result + hashCode(element);
 
 Review comment:
   When we put null-key we get NPE with the problem description  
   "java.lang.NullPointerException: Ouch! Argument cannot be null: key"
   
   But when we put "new String[] {"c", null, "a"}" we get just NPE, and  I think we should
at least explain the problem in the same way if this is the expected behavior.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

Mime
View raw message