提交 4d49550d authored 作者: Andrei Tokar's avatar Andrei Tokar

inline MVMap.put(,,) and MVMap.areValuesEqual(,)

上级 07d3c8b3
......@@ -148,19 +148,7 @@ public class MVMap<K, V> extends AbstractMap<K, V>
@Override
public V put(K key, V value) {
DataUtils.checkArgument(value != null, "The value may not be null");
return put(key, value, DecisionMaker.PUT);
}
/**
* Add or replace a key-value pair.
*
* @param key the key (may not be null)
* @param value the value (may not be null)
* @param decisionMaker callback object for update logic
* @return the old value if the key existed, or null otherwise
*/
public final V put(K key, V value, DecisionMaker<? super V> decisionMaker) {
return operate(key, value, decisionMaker);
return operate(key, value, DecisionMaker.PUT);
}
/**
......@@ -467,7 +455,7 @@ public class MVMap<K, V> extends AbstractMap<K, V>
*/
@Override
public final V putIfAbsent(K key, V value) {
return put(key, value, DecisionMaker.IF_ABSENT);
return operate(key, value, DecisionMaker.IF_ABSENT);
}
/**
......@@ -485,17 +473,6 @@ public class MVMap<K, V> extends AbstractMap<K, V>
return decisionMaker.getDecision() != Decision.ABORT;
}
/**
* Check whether the two values are equal.
*
* @param a the first value
* @param b the second value
* @return true if they are equal
*/
public final boolean areValuesEqual(Object a, Object b) {
return areValuesEqual(valueType, a, b);
}
/**
* Check whether the two values are equal.
*
......@@ -520,9 +497,9 @@ public class MVMap<K, V> extends AbstractMap<K, V>
@Override
public final boolean replace(K key, V oldValue, V newValue) {
EqualsDecisionMaker<V> decisionMaker = new EqualsDecisionMaker<>(valueType, oldValue);
V result = put(key, newValue, decisionMaker);
V result = operate(key, newValue, decisionMaker);
boolean res = decisionMaker.getDecision() != Decision.ABORT;
assert !res || areValuesEqual(oldValue, result) : oldValue + " != " + result;
assert !res || areValuesEqual(valueType, oldValue, result) : oldValue + " != " + result;
return res;
}
......@@ -535,7 +512,7 @@ public class MVMap<K, V> extends AbstractMap<K, V>
*/
@Override
public final V replace(K key, V value) {
return put(key, value, DecisionMaker.IF_PRESENT);
return operate(key, value, DecisionMaker.IF_PRESENT);
}
/**
......@@ -1641,7 +1618,7 @@ public class MVMap<K, V> extends AbstractMap<K, V>
/**
* Provides revised value for insert/update based on original input value
* and value currently existing in the map.
* This method is not invoked only after decide(), if it returns PUT.
* This method is only invoked after call to decide(), if it returns PUT.
* @param existingValue value currently exists in the map
* @param providedValue original input value
* @param <T> value type
......@@ -1660,12 +1637,12 @@ public class MVMap<K, V> extends AbstractMap<K, V>
}
/**
* Apply an operation to a key-value pair.
* Add, replace or remove a key-value pair.
*
* @param key key to operate on
* @param value new value
* @param key the key (may not be null)
* @param value new value, it may be null when removal is indended
* @param decisionMaker command object to make choices during transaction.
* @return new value
* @return previous value, if mapping for that key existed, or null otherwise
*/
@SuppressWarnings("unchecked")
public V operate(K key, V value, DecisionMaker<? super V> decisionMaker) {
......
......@@ -303,7 +303,7 @@ public class TransactionMap<K, V> extends AbstractMap<K, V> {
// and any non-null value will do
@SuppressWarnings("unchecked")
K k = (K) key;
result = map.put(k, VersionedValue.DUMMY, decisionMaker);
result = map.operate(k, VersionedValue.DUMMY, decisionMaker);
MVMap.Decision decision = decisionMaker.getDecision();
assert decision != null;
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论