]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.utils.datastructures/src/org/simantics/utils/datastructures/ArrayMapEntry.java
Merge commit '53059ca'
[simantics/platform.git] / bundles / org.simantics.utils.datastructures / src / org / simantics / utils / datastructures / ArrayMapEntry.java
diff --git a/bundles/org.simantics.utils.datastructures/src/org/simantics/utils/datastructures/ArrayMapEntry.java b/bundles/org.simantics.utils.datastructures/src/org/simantics/utils/datastructures/ArrayMapEntry.java
new file mode 100644 (file)
index 0000000..4a7fd2e
--- /dev/null
@@ -0,0 +1,80 @@
+/*******************************************************************************\r
+ * Copyright (c) 2007, 2016 Association for Decentralized Information Management\r
+ * in Industry THTH ry.\r
+ * All rights reserved. This program and the accompanying materials\r
+ * are made available under the terms of the Eclipse Public License v1.0\r
+ * which accompanies this distribution, and is available at\r
+ * http://www.eclipse.org/legal/epl-v10.html\r
+ *\r
+ * Contributors:\r
+ *     Semantum Oy - initial API and implementation\r
+ *******************************************************************************/\r
+package org.simantics.utils.datastructures;\r
+\r
+import java.util.Map;\r
+\r
+/**\r
+ * A common {@link Entry} implementation for both {@link ArrayMap}\r
+ * and {@link InterlacedArrayMap}.\r
+ * \r
+ * @author Tuukka Lehtonen\r
+ *\r
+ * @param <K> key class\r
+ * @param <V> value class\r
+ */\r
+class ArrayMapEntry<K, V> implements Map.Entry<K, V> {\r
+    final K key;\r
+    V value;\r
+\r
+    /**\r
+     * Creates new entry.\r
+     */\r
+    ArrayMapEntry(int h, K k, V v) {\r
+        value = v;\r
+        key = k;\r
+    }\r
+\r
+    @Override\r
+    public final K getKey() {\r
+        return key;\r
+    }\r
+\r
+    @Override\r
+    public final V getValue() {\r
+        return value;\r
+    }\r
+\r
+    @Override\r
+    public final V setValue(V newValue) {\r
+        V oldValue = value;\r
+        value = newValue;\r
+        return oldValue;\r
+    }\r
+\r
+    @Override\r
+    public final boolean equals(Object o) {\r
+        if (!(o instanceof Map.Entry<?, ?>))\r
+            return false;\r
+        Map.Entry<?, ?> e = (Map.Entry<?, ?>)o;\r
+        Object k1 = getKey();\r
+        Object k2 = e.getKey();\r
+        if (k1 == k2 || (k1 != null && k1.equals(k2))) {\r
+            Object v1 = getValue();\r
+            Object v2 = e.getValue();\r
+            if (v1 == v2 || (v1 != null && v1.equals(v2)))\r
+                return true;\r
+        }\r
+        return false;\r
+    }\r
+\r
+    @Override\r
+    public final int hashCode() {\r
+        return (key==null   ? 0 : key.hashCode()) ^\r
+        (value==null ? 0 : value.hashCode());\r
+    }\r
+\r
+    @Override\r
+    public final String toString() {\r
+        return getKey() + "=" + getValue();\r
+    }\r
+}
\ No newline at end of file