Madan Jampani

Added a utility method to MapValue for creating tombstone instances

Change-Id: I2ddc30ebb9dac3b865a13c0a32b46b39cafb1aa8
......@@ -314,7 +314,7 @@ public class EventuallyConsistentMapImpl<K, V>
checkState(!destroyed, destroyedMessage);
checkNotNull(key, ERROR_NULL_KEY);
// TODO prevent calls here if value is important for timestamp
MapValue<V> tombstone = new MapValue<>(null, timestampProvider.apply(key, null));
MapValue<V> tombstone = MapValue.tombstone(timestampProvider.apply(key, null));
MapValue<V> previousValue = removeInternal(key, Optional.empty(), tombstone);
if (previousValue != null) {
notifyPeers(new UpdateEntry<>(key, tombstone), peerUpdateFunction.apply(key, previousValue.get()));
......@@ -330,7 +330,7 @@ public class EventuallyConsistentMapImpl<K, V>
checkState(!destroyed, destroyedMessage);
checkNotNull(key, ERROR_NULL_KEY);
checkNotNull(value, ERROR_NULL_VALUE);
MapValue<V> tombstone = new MapValue<>(null, timestampProvider.apply(key, value));
MapValue<V> tombstone = MapValue.tombstone(timestampProvider.apply(key, value));
MapValue<V> previousValue = removeInternal(key, Optional.of(value), tombstone);
if (previousValue != null) {
notifyPeers(new UpdateEntry<>(key, tombstone), peerUpdateFunction.apply(key, previousValue.get()));
......@@ -561,7 +561,7 @@ public class EventuallyConsistentMapImpl<K, V>
if (remoteValueDigest != null && remoteValueDigest.isTombstone()) {
MapValue<V> previousValue = removeInternal(key,
Optional.empty(),
new MapValue<>(null, remoteValueDigest.timestamp()));
MapValue.tombstone(remoteValueDigest.timestamp()));
if (previousValue != null && previousValue.isAlive()) {
externalEvents.add(new EventuallyConsistentMapEvent<>(REMOVE, key, previousValue.get()));
}
......
......@@ -12,6 +12,17 @@ public class MapValue<V> implements Comparable<MapValue<V>> {
private final Timestamp timestamp;
private final V value;
/**
* Creates a tombstone value with the specified timestamp.
* @param timestamp timestamp for tombstone
* @return tombstone MapValue
*
* @param <U> value type
*/
public static <U> MapValue<U> tombstone(Timestamp timestamp) {
return new MapValue<>(null, timestamp);
}
public MapValue(V value, Timestamp timestamp) {
this.value = value;
this.timestamp = timestamp;
......