Committed by
Gerrit Code Review
ONOS-4690: containsKey() in TransactionalMap
Change-Id: I13a5eea3871a9a6cc5f808b662584d1892ff19bd
Showing
2 changed files
with
13 additions
and
1 deletions
... | @@ -39,6 +39,13 @@ public interface TransactionalMap<K, V> { | ... | @@ -39,6 +39,13 @@ public interface TransactionalMap<K, V> { |
39 | V get(K key); | 39 | V get(K key); |
40 | 40 | ||
41 | /** | 41 | /** |
42 | + * Returns true if this map contains a mapping for the specified key. | ||
43 | + * @param key key whose presence in this map to be tested | ||
44 | + * @return true if this map contains a mapping for the specified key | ||
45 | + */ | ||
46 | + boolean containsKey(K key); | ||
47 | + | ||
48 | + /** | ||
42 | * Associates the specified value with the specified key in this map (optional operation). | 49 | * Associates the specified value with the specified key in this map (optional operation). |
43 | * If the map previously contained a mapping for the key, the old value is replaced by the | 50 | * If the map previously contained a mapping for the key, the old value is replaced by the |
44 | * specified value. | 51 | * specified value. |
... | @@ -90,4 +97,4 @@ public interface TransactionalMap<K, V> { | ... | @@ -90,4 +97,4 @@ public interface TransactionalMap<K, V> { |
90 | * @return true if the value was replaced | 97 | * @return true if the value was replaced |
91 | */ | 98 | */ |
92 | boolean replace(K key, V oldValue, V newValue); | 99 | boolean replace(K key, V oldValue, V newValue); |
93 | -} | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
100 | +} | ... | ... |
... | @@ -109,6 +109,11 @@ public class DefaultTransactionalMap<K, V> implements TransactionalMap<K, V>, Tr | ... | @@ -109,6 +109,11 @@ public class DefaultTransactionalMap<K, V> implements TransactionalMap<K, V>, Tr |
109 | } | 109 | } |
110 | 110 | ||
111 | @Override | 111 | @Override |
112 | + public boolean containsKey(K key) { | ||
113 | + return get(key) != null; | ||
114 | + } | ||
115 | + | ||
116 | + @Override | ||
112 | public V put(K key, V value) { | 117 | public V put(K key, V value) { |
113 | checkState(txContext.isOpen(), TX_CLOSED_ERROR); | 118 | checkState(txContext.isOpen(), TX_CLOSED_ERROR); |
114 | checkNotNull(value, ERROR_NULL_VALUE); | 119 | checkNotNull(value, ERROR_NULL_VALUE); | ... | ... |
-
Please register or login to post a comment