Madan Jampani | 6468955 | 2015-02-17 10:00:27 -0800 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2015-present Open Networking Foundation |
Madan Jampani | 6468955 | 2015-02-17 10:00:27 -0800 | [diff] [blame] | 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 | /** |
Sho SHIMIZU | 637ae5d | 2016-06-10 11:08:13 -0700 | [diff] [blame] | 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 | /** |
Madan Jampani | 6468955 | 2015-02-17 10:00:27 -0800 | [diff] [blame] | 49 | * Associates the specified value with the specified key in this map (optional operation). |
| 50 | * If the map previously contained a mapping for the key, the old value is replaced by the |
| 51 | * specified value. |
| 52 | * |
| 53 | * @param key key with which the specified value is to be associated |
| 54 | * @param value value to be associated with the specified key |
| 55 | * @return the previous value associated with key, or null if there was |
| 56 | * no mapping for key. |
| 57 | */ |
| 58 | V put(K key, V value); |
| 59 | |
| 60 | /** |
| 61 | * Removes the mapping for a key from this map if it is present (optional operation). |
| 62 | * |
| 63 | * @param key key whose value is to be removed from the map |
| 64 | * @return the value to which this map previously associated the key, |
| 65 | * or null if the map contained no mapping for the key. |
| 66 | */ |
| 67 | V remove(K key); |
| 68 | |
| 69 | /** |
Madan Jampani | 6468955 | 2015-02-17 10:00:27 -0800 | [diff] [blame] | 70 | * If the specified key is not already associated with a value |
| 71 | * associates it with the given value and returns null, else returns the current value. |
| 72 | * |
| 73 | * @param key key with which the specified value is to be associated |
| 74 | * @param value value to be associated with the specified key |
| 75 | * @return the previous value associated with the specified key or null |
| 76 | * if key does not already mapped to a value. |
| 77 | */ |
| 78 | V putIfAbsent(K key, V value); |
| 79 | |
| 80 | /** |
| 81 | * Removes the entry for the specified key only if it is currently |
| 82 | * mapped to the specified value. |
| 83 | * |
| 84 | * @param key key with which the specified value is associated |
| 85 | * @param value value expected to be associated with the specified key |
| 86 | * @return true if the value was removed |
| 87 | */ |
| 88 | boolean remove(K key, V value); |
| 89 | |
| 90 | /** |
| 91 | * Replaces the entry for the specified key only if currently mapped |
| 92 | * to the specified value. |
| 93 | * |
| 94 | * @param key key with which the specified value is associated |
| 95 | * @param oldValue value expected to be associated with the specified key |
| 96 | * @param newValue value to be associated with the specified key |
| 97 | * @return true if the value was replaced |
| 98 | */ |
| 99 | boolean replace(K key, V oldValue, V newValue); |
Sho SHIMIZU | 637ae5d | 2016-06-10 11:08:13 -0700 | [diff] [blame] | 100 | } |