diff options
Diffstat (limited to 'javanano')
-rw-r--r-- | javanano/src/main/java/com/google/protobuf/nano/InternalNano.java | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/javanano/src/main/java/com/google/protobuf/nano/InternalNano.java b/javanano/src/main/java/com/google/protobuf/nano/InternalNano.java index 044c30dd..f3144652 100644 --- a/javanano/src/main/java/com/google/protobuf/nano/InternalNano.java +++ b/javanano/src/main/java/com/google/protobuf/nano/InternalNano.java @@ -531,4 +531,23 @@ public final class InternalNano { } return a.equals(b); } + + public static <K, V> int hashCode(Map<K, V> map) { + if (map == null) { + return 0; + } + int result = 0; + for (Entry<K, V> entry : map.entrySet()) { + result += hashCodeForMap(entry.getKey()) + ^ hashCodeForMap(entry.getValue()); + } + return result; + } + + private static int hashCodeForMap(Object o) { + if (o instanceof byte[]) { + return Arrays.hashCode((byte[]) o); + } + return o.hashCode(); + } } |