![JAR search and dependency download from the Maven repository](/logo.png)
org.vvcephei.occ_map.AbstractEntry Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of occ-map Show documentation
Show all versions of occ-map Show documentation
A micro-lib providing a threadsafe map which provides optimistic concurrency control.
/*
* Written by Cliff Click and released to the public domain, as explained at
* http://creativecommons.org/licenses/publicdomain
*/
package org.vvcephei.occ_map;
import java.util.Map;
/**
* A simple implementation of {@link java.util.Map.Entry}.
* Does not implement {@link java.util.Map.Entry.setValue}, that is done by users of the class.
*
* Copied from https://github.com/boundary/high-scale-lib @ 3654434eda00b68d37d22dcd70e4f65db9432d06
* @author Cliff Click
* @param the type of keys maintained by this map
* @param the type of mapped values
*/
abstract class AbstractEntry implements Map.Entry {
/** Strongly typed key */
protected final TypeK _key;
/** Strongly typed value */
protected TypeV _val;
public AbstractEntry(final TypeK key, final TypeV val) { _key = key; _val = val; }
public AbstractEntry(final Map.Entry e) { _key = e.getKey(); _val = e.getValue(); }
/** Return "key=val" string */
public String toString() { return _key + "=" + _val; }
/** Return key */
public TypeK getKey () { return _key; }
/** Return val */
public TypeV getValue() { return _val; }
/** Equal if the underlying key & value are equal */
public boolean equals(final Object o) {
if (!(o instanceof Map.Entry)) return false;
final Map.Entry e = (Map.Entry)o;
return eq(_key, e.getKey()) && eq(_val, e.getValue());
}
/** Compute "key.hashCode() ^ val.hashCode()"
*/
public int hashCode() {
return
((_key == null) ? 0 : _key.hashCode()) ^
((_val == null) ? 0 : _val.hashCode());
}
private static boolean eq(final Object o1, final Object o2) {
return (o1 == null ? o2 == null : o1.equals(o2));
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy