blob: ebc66115eed8ca7059c90ab12fb4d24001104efb [file] [log] [blame]
Madan Jampani64689552015-02-17 10:00:27 -08001/*
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
17package org.onosproject.store.service;
18
Madan Jampani64689552015-02-17 10:00:27 -080019
20/**
21 * Transactional Map data structure.
22 * <p>
Madan Jampanibff6d8f2015-03-31 16:53:47 -070023 * A TransactionalMap is created by invoking {@link TransactionContext#getTransactionalMap getTransactionalMap}
24 * method. All operations performed on this map within a transaction boundary are invisible externally
Madan Jampani64689552015-02-17 10:00:27 -080025 * until the point when the transaction commits. A commit usually succeeds in the absence of conflicts.
26 *
27 * @param <K> type of key.
28 * @param <V> type of value.
29 */
30public interface TransactionalMap<K, V> {
31
32 /**
Madan Jampani64689552015-02-17 10:00:27 -080033 * Returns the value to which the specified key is mapped, or null if this
34 * map contains no mapping for the key.
35 *
36 * @param key the key whose associated value is to be returned
37 * @return the value to which the specified key is mapped, or null if
38 * this map contains no mapping for the key
39 */
40 V get(K key);
41
42 /**
43 * Associates the specified value with the specified key in this map (optional operation).
44 * If the map previously contained a mapping for the key, the old value is replaced by the
45 * specified value.
46 *
47 * @param key key with which the specified value is to be associated
48 * @param value value to be associated with the specified key
49 * @return the previous value associated with key, or null if there was
50 * no mapping for key.
51 */
52 V put(K key, V value);
53
54 /**
55 * Removes the mapping for a key from this map if it is present (optional operation).
56 *
57 * @param key key whose value is to be removed from the map
58 * @return the value to which this map previously associated the key,
59 * or null if the map contained no mapping for the key.
60 */
61 V remove(K key);
62
63 /**
Madan Jampani64689552015-02-17 10:00:27 -080064 * If the specified key is not already associated with a value
65 * associates it with the given value and returns null, else returns the current value.
66 *
67 * @param key key with which the specified value is to be associated
68 * @param value value to be associated with the specified key
69 * @return the previous value associated with the specified key or null
70 * if key does not already mapped to a value.
71 */
72 V putIfAbsent(K key, V value);
73
74 /**
75 * Removes the entry for the specified key only if it is currently
76 * mapped to the specified value.
77 *
78 * @param key key with which the specified value is associated
79 * @param value value expected to be associated with the specified key
80 * @return true if the value was removed
81 */
82 boolean remove(K key, V value);
83
84 /**
85 * Replaces the entry for the specified key only if currently mapped
86 * to the specified value.
87 *
88 * @param key key with which the specified value is associated
89 * @param oldValue value expected to be associated with the specified key
90 * @param newValue value to be associated with the specified key
91 * @return true if the value was replaced
92 */
93 boolean replace(K key, V oldValue, V newValue);
94}