blob: b4a1b4099866b522edef170094640024a8728e99 [file] [log] [blame]
Aaron Kruglikov47047b22016-03-31 16:52:48 -07001/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2016-present Open Networking Laboratory
Aaron Kruglikov47047b22016-03-31 16:52:48 -07003 *
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
19import org.onosproject.store.primitives.DefaultConsistentTreeMap;
20
21import java.util.Map;
22import java.util.NavigableSet;
23import java.util.concurrent.CompletableFuture;
24
25/**
26 * API for a distributed tree map implementation.
27 */
28public interface AsyncConsistentTreeMap<K, V> extends AsyncConsistentMap<K, V> {
29
30 /**
31 * Return the lowest key in the map.
32 *
33 * @return the key or null if none exist
34 */
35 CompletableFuture<K> firstKey();
36
37 /**
38 * Return the highest key in the map.
39 *
40 * @return the key or null if none exist
41 */
42 CompletableFuture<K> lastKey();
43
44 /**
45 * Returns the entry associated with the least key greater than or equal to the key.
46 *
47 * @param key the key
48 * @return the entry or null
49 */
50 CompletableFuture<Map.Entry<K, Versioned<V>>> ceilingEntry(K key);
51
52 /**
53 * Returns the entry associated with the greatest key less than or equal to key.
54 *
55 * @param key the key
56 * @return the entry or null
57 */
58 CompletableFuture<Map.Entry<K, Versioned<V>>> floorEntry(K key);
59
60 /**
61 * Returns the entry associated with the lest key greater than key.
62 *
63 * @param key the key
64 * @return the entry or null
65 */
66 CompletableFuture<Map.Entry<K, Versioned<V>>> higherEntry(K key);
67
68 /**
69 * Returns the entry associated with the largest key less than key.
70 *
71 * @param key the key
72 * @return the entry or null
73 */
74 CompletableFuture<Map.Entry<K, Versioned<V>>> lowerEntry(K key);
75
76 /**
77 * Return the entry associated with the lowest key in the map.
78 *
79 * @return the entry or null
80 */
81 CompletableFuture<Map.Entry<K, Versioned<V>>> firstEntry();
82
83 /**
84 * Return the entry assocaited with the highest key in the map.
85 *
86 * @return the entry or null
87 */
88 CompletableFuture<Map.Entry<K, Versioned<V>>> lastEntry();
89
90 /**
91 * Return and remove the entry associated with the lowest key.
92 *
93 * @return the entry or null
94 */
95 CompletableFuture<Map.Entry<K, Versioned<V>>> pollFirstEntry();
96
97 /**
98 * Return and remove the entry associated with the highest key.
99 *
100 * @return the entry or null
101 */
102 CompletableFuture<Map.Entry<K, Versioned<V>>> pollLastEntry();
103
104 /**
105 * Return the entry associated with the greatest key less than key.
106 *
107 * @param key the key
108 * @return the entry or null
109 */
110 CompletableFuture<K> lowerKey(K key);
111
112 /**
113 * Return the entry associated with the highest key less than or equal to key.
114 *
115 * @param key the key
116 * @return the entry or null
117 */
118 CompletableFuture<K> floorKey(K key);
119
120 /**
121 * Return the lowest key greater than or equal to key.
122 *
123 * @param key the key
124 * @return the key or null
125 */
126 CompletableFuture<K> ceilingKey(K key);
127
128 /**
129 * Return the lowest key greater than key.
130 *
131 * @param key the key
132 * @return the key or null
133 */
134 CompletableFuture<K> higherKey(K key);
135
136 /**
137 * Returns a navigable set of the keys in this map.
138 *
139 * @return a navigable key set
140 */
141 CompletableFuture<NavigableSet<K>> navigableKeySet();
142
143 default ConsistentTreeMap<K, V> asTreeMap() {
144 return asTreeMap(DistributedPrimitive.DEFAULT_OPERTATION_TIMEOUT_MILLIS);
145 }
146
147 default ConsistentTreeMap<K, V> asTreeMap(long timeoutMillis) {
148 return new DefaultConsistentTreeMap<>(this, timeoutMillis);
149 }
150
151
152}