blob: 79c482dbe100e2401d9973e2f37524be3a269e2b [file] [log] [blame]
Madan Jampani64689552015-02-17 10:00:27 -08001/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2015-present Open Networking Laboratory
Madan Jampani64689552015-02-17 10:00:27 -08003 *
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 * Transactional Map data structure.
21 * <p>
Madan Jampanibff6d8f2015-03-31 16:53:47 -070022 * 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 Jampani64689552015-02-17 10:00:27 -080024 * 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 */
29public interface TransactionalMap<K, V> {
30
31 /**
Madan Jampani64689552015-02-17 10:00:27 -080032 * 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 SHIMIZU637ae5d2016-06-10 11:08:13 -070042 * 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 Jampani64689552015-02-17 10:00:27 -080049 * 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 Jampani64689552015-02-17 10:00:27 -080070 * 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 SHIMIZU637ae5d2016-06-10 11:08:13 -0700100}