X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.utils.datastructures%2Fsrc%2Forg%2Fsimantics%2Futils%2Fdatastructures%2FArrayMapEntry.java;fp=bundles%2Forg.simantics.utils.datastructures%2Fsrc%2Forg%2Fsimantics%2Futils%2Fdatastructures%2FArrayMapEntry.java;h=4a7fd2e45fd0663686740f761779f70b2ca3cecb;hb=53059ca1a958697cc6235d27628614fbaa944d59;hp=0000000000000000000000000000000000000000;hpb=e87f0965679502de281692c298d66a7ae9507bd8;p=simantics%2Fplatform.git 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 index 000000000..4a7fd2e45 --- /dev/null +++ b/bundles/org.simantics.utils.datastructures/src/org/simantics/utils/datastructures/ArrayMapEntry.java @@ -0,0 +1,80 @@ +/******************************************************************************* + * Copyright (c) 2007, 2016 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Semantum Oy - initial API and implementation + *******************************************************************************/ +package org.simantics.utils.datastructures; + +import java.util.Map; + +/** + * A common {@link Entry} implementation for both {@link ArrayMap} + * and {@link InterlacedArrayMap}. + * + * @author Tuukka Lehtonen + * + * @param key class + * @param value class + */ +class ArrayMapEntry implements Map.Entry { + final K key; + V value; + + /** + * Creates new entry. + */ + ArrayMapEntry(int h, K k, V v) { + value = v; + key = k; + } + + @Override + public final K getKey() { + return key; + } + + @Override + public final V getValue() { + return value; + } + + @Override + public final V setValue(V newValue) { + V oldValue = value; + value = newValue; + return oldValue; + } + + @Override + public final boolean equals(Object o) { + if (!(o instanceof Map.Entry)) + return false; + Map.Entry e = (Map.Entry)o; + Object k1 = getKey(); + Object k2 = e.getKey(); + if (k1 == k2 || (k1 != null && k1.equals(k2))) { + Object v1 = getValue(); + Object v2 = e.getValue(); + if (v1 == v2 || (v1 != null && v1.equals(v2))) + return true; + } + return false; + } + + @Override + public final int hashCode() { + return (key==null ? 0 : key.hashCode()) ^ + (value==null ? 0 : value.hashCode()); + } + + @Override + public final String toString() { + return getKey() + "=" + getValue(); + } +} \ No newline at end of file