
de.tsl2.nano.collection.Entry Maven / Gradle / Ivy
package de.tsl2.nano.collection;
import java.io.Serializable;
import java.util.Map;
import de.tsl2.nano.core.util.Util;
/**
* part of {@link MapEntrySet}. as the hashmap implementation doesn't make Map.Entry serializable, we have to write our
* own entry class.
*
* @param
* @param
* @author Tom
* @version $Revision$
*/
public class Entry implements Map.Entry, Serializable {
/** serialVersionUID */
private static final long serialVersionUID = 1L;
K key;
V value;
boolean sync;
Map map;
/**
* constructor no map connection available. {@link MapEntrySet} has to collect this entry on adding.
*/
public Entry() {
}
Entry(Map.Entry src, boolean sync, Map map) {
key = src.getKey();
value = src.getValue();
this.sync = sync;
this.map = map;
}
/**
* constructor
*
* @param key
* @param value
*/
public Entry(K key, V value) {
super();
this.key = key;
this.value = value;
}
@Override
public K getKey() {
return key;
}
public void setKey(K key) {
this.key = key;
}
@Override
public V getValue() {
return value;
}
@Override
public V setValue(V value) {
this.value = value;
if (sync) {
map.put(key, value);
}
return value;
}
@Override
public String toString() {
return Util.toString(getClass(), key, value);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy