Madan Jampani | 6468955 | 2015-02-17 10:00:27 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2015 Open Networking Laboratory |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package org.onosproject.store.service; |
| 18 | |
Madan Jampani | 6468955 | 2015-02-17 10:00:27 -0800 | [diff] [blame] | 19 | /** |
| 20 | * Transactional Map data structure. |
| 21 | * <p> |
Madan Jampani | bff6d8f | 2015-03-31 16:53:47 -0700 | [diff] [blame] | 22 | * A TransactionalMap is created by invoking {@link TransactionContext#getTransactionalMap getTransactionalMap} |
| 23 | * method. All operations performed on this map within a transaction boundary are invisible externally |
Madan Jampani | 6468955 | 2015-02-17 10:00:27 -0800 | [diff] [blame] | 24 | * until the point when the transaction commits. A commit usually succeeds in the absence of conflicts. |
| 25 | * |
| 26 | * @param <K> type of key. |
| 27 | * @param <V> type of value. |
| 28 | */ |
| 29 | public interface TransactionalMap<K, V> { |
| 30 | |
| 31 | /** |
Madan Jampani | 6468955 | 2015-02-17 10:00:27 -0800 | [diff] [blame] | 32 | * Returns the value to which the specified key is mapped, or null if this |
| 33 | * map contains no mapping for the key. |
| 34 | * |
| 35 | * @param key the key whose associated value is to be returned |
| 36 | * @return the value to which the specified key is mapped, or null if |
| 37 | * this map contains no mapping for the key |
| 38 | */ |
| 39 | V get(K key); |
| 40 | |
| 41 | /** |
| 42 | * 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 |
| 44 | * specified value. |
| 45 | * |
| 46 | * @param key key with which the specified value is to be associated |
| 47 | * @param value value to be associated with the specified key |
| 48 | * @return the previous value associated with key, or null if there was |
| 49 | * no mapping for key. |
| 50 | */ |
| 51 | V put(K key, V value); |
| 52 | |
| 53 | /** |
| 54 | * Removes the mapping for a key from this map if it is present (optional operation). |
| 55 | * |
| 56 | * @param key key whose value is to be removed from the map |
| 57 | * @return the value to which this map previously associated the key, |
| 58 | * or null if the map contained no mapping for the key. |
| 59 | */ |
| 60 | V remove(K key); |
| 61 | |
| 62 | /** |
Madan Jampani | 6468955 | 2015-02-17 10:00:27 -0800 | [diff] [blame] | 63 | * If the specified key is not already associated with a value |
| 64 | * associates it with the given value and returns null, else returns the current value. |
| 65 | * |
| 66 | * @param key key with which the specified value is to be associated |
| 67 | * @param value value to be associated with the specified key |
| 68 | * @return the previous value associated with the specified key or null |
| 69 | * if key does not already mapped to a value. |
| 70 | */ |
| 71 | V putIfAbsent(K key, V value); |
| 72 | |
| 73 | /** |
| 74 | * Removes the entry for the specified key only if it is currently |
| 75 | * mapped to the specified value. |
| 76 | * |
| 77 | * @param key key with which the specified value is associated |
| 78 | * @param value value expected to be associated with the specified key |
| 79 | * @return true if the value was removed |
| 80 | */ |
| 81 | boolean remove(K key, V value); |
| 82 | |
| 83 | /** |
| 84 | * Replaces the entry for the specified key only if currently mapped |
| 85 | * to the specified value. |
| 86 | * |
| 87 | * @param key key with which the specified value is associated |
| 88 | * @param oldValue value expected to be associated with the specified key |
| 89 | * @param newValue value to be associated with the specified key |
| 90 | * @return true if the value was replaced |
| 91 | */ |
| 92 | boolean replace(K key, V oldValue, V newValue); |
| 93 | } |