Changing tree map interface to only allow a value type parameter, key is always string.
Change-Id: I727e62401998fec63acf9e584cfb79a6ed02b569
Showing
4 changed files
with
129 additions
and
80 deletions
| ... | @@ -27,6 +27,7 @@ import org.onosproject.store.service.Versioned; | ... | @@ -27,6 +27,7 @@ import org.onosproject.store.service.Versioned; |
| 27 | 27 | ||
| 28 | import java.util.Collection; | 28 | import java.util.Collection; |
| 29 | import java.util.Map; | 29 | import java.util.Map; |
| 30 | +import java.util.NavigableMap; | ||
| 30 | import java.util.NavigableSet; | 31 | import java.util.NavigableSet; |
| 31 | import java.util.Set; | 32 | import java.util.Set; |
| 32 | import java.util.concurrent.CompletableFuture; | 33 | import java.util.concurrent.CompletableFuture; |
| ... | @@ -41,14 +42,16 @@ import java.util.function.Predicate; | ... | @@ -41,14 +42,16 @@ import java.util.function.Predicate; |
| 41 | /** | 42 | /** |
| 42 | * Implementation of the {@link ConsistentTreeMap} interface. | 43 | * Implementation of the {@link ConsistentTreeMap} interface. |
| 43 | */ | 44 | */ |
| 44 | -public class DefaultConsistentTreeMap<K, V> extends Synchronous<AsyncConsistentTreeMap<K, V>> | 45 | +public class DefaultConsistentTreeMap<V> |
| 45 | - implements ConsistentTreeMap<K, V> { | 46 | + extends Synchronous<AsyncConsistentTreeMap<V>> |
| 47 | + implements ConsistentTreeMap<V> { | ||
| 46 | private static final int MAX_DELAY_BETWEEN_RETRY_MILLIS = 50; | 48 | private static final int MAX_DELAY_BETWEEN_RETRY_MILLIS = 50; |
| 47 | - private final AsyncConsistentTreeMap<K, V> treeMap; | 49 | + private final AsyncConsistentTreeMap<V> treeMap; |
| 48 | private final long operationTimeoutMillis; | 50 | private final long operationTimeoutMillis; |
| 49 | - private Map<K, V> javaMap; | 51 | + private Map<String, V> javaMap; |
| 50 | 52 | ||
| 51 | - public DefaultConsistentTreeMap(AsyncConsistentTreeMap<K, V> treeMap, long operationTimeoutMillis) { | 53 | + public DefaultConsistentTreeMap(AsyncConsistentTreeMap<V> treeMap, |
| 54 | + long operationTimeoutMillis) { | ||
| 52 | super(treeMap); | 55 | super(treeMap); |
| 53 | this.treeMap = treeMap; | 56 | this.treeMap = treeMap; |
| 54 | this.operationTimeoutMillis = operationTimeoutMillis; | 57 | this.operationTimeoutMillis = operationTimeoutMillis; |
| ... | @@ -69,72 +72,72 @@ public class DefaultConsistentTreeMap<K, V> extends Synchronous<AsyncConsistentT | ... | @@ -69,72 +72,72 @@ public class DefaultConsistentTreeMap<K, V> extends Synchronous<AsyncConsistentT |
| 69 | } | 72 | } |
| 70 | 73 | ||
| 71 | @Override | 74 | @Override |
| 72 | - public K firstKey() { | 75 | + public String firstKey() { |
| 73 | return complete(treeMap.firstKey()); | 76 | return complete(treeMap.firstKey()); |
| 74 | } | 77 | } |
| 75 | 78 | ||
| 76 | @Override | 79 | @Override |
| 77 | - public K lastKey() { | 80 | + public String lastKey() { |
| 78 | return complete(treeMap.lastKey()); | 81 | return complete(treeMap.lastKey()); |
| 79 | } | 82 | } |
| 80 | 83 | ||
| 81 | @Override | 84 | @Override |
| 82 | - public Map.Entry<K, Versioned<V>> ceilingEntry(K key) { | 85 | + public Map.Entry<String, Versioned<V>> ceilingEntry(String key) { |
| 83 | return complete(treeMap.ceilingEntry(key)); | 86 | return complete(treeMap.ceilingEntry(key)); |
| 84 | } | 87 | } |
| 85 | 88 | ||
| 86 | @Override | 89 | @Override |
| 87 | - public Map.Entry<K, Versioned<V>> floorEntry(K key) { | 90 | + public Map.Entry<String, Versioned<V>> floorEntry(String key) { |
| 88 | return complete(treeMap.floorEntry(key)); | 91 | return complete(treeMap.floorEntry(key)); |
| 89 | } | 92 | } |
| 90 | 93 | ||
| 91 | @Override | 94 | @Override |
| 92 | - public Map.Entry<K, Versioned<V>> higherEntry(K key) { | 95 | + public Map.Entry<String, Versioned<V>> higherEntry(String key) { |
| 93 | return complete(treeMap.higherEntry(key)); | 96 | return complete(treeMap.higherEntry(key)); |
| 94 | } | 97 | } |
| 95 | 98 | ||
| 96 | @Override | 99 | @Override |
| 97 | - public Map.Entry<K, Versioned<V>> lowerEntry(K key) { | 100 | + public Map.Entry<String, Versioned<V>> lowerEntry(String key) { |
| 98 | return complete(treeMap.lowerEntry(key)); | 101 | return complete(treeMap.lowerEntry(key)); |
| 99 | } | 102 | } |
| 100 | 103 | ||
| 101 | @Override | 104 | @Override |
| 102 | - public Map.Entry<K, Versioned<V>> firstEntry() { | 105 | + public Map.Entry<String, Versioned<V>> firstEntry() { |
| 103 | return complete(treeMap.firstEntry()); | 106 | return complete(treeMap.firstEntry()); |
| 104 | } | 107 | } |
| 105 | 108 | ||
| 106 | @Override | 109 | @Override |
| 107 | - public Map.Entry<K, Versioned<V>> lastEntry() { | 110 | + public Map.Entry<String, Versioned<V>> lastEntry() { |
| 108 | return complete(treeMap.lastEntry()); | 111 | return complete(treeMap.lastEntry()); |
| 109 | } | 112 | } |
| 110 | 113 | ||
| 111 | @Override | 114 | @Override |
| 112 | - public Map.Entry<K, Versioned<V>> pollFirstEntry() { | 115 | + public Map.Entry<String, Versioned<V>> pollFirstEntry() { |
| 113 | return complete(treeMap.pollFirstEntry()); | 116 | return complete(treeMap.pollFirstEntry()); |
| 114 | } | 117 | } |
| 115 | 118 | ||
| 116 | @Override | 119 | @Override |
| 117 | - public Map.Entry<K, Versioned<V>> pollLastEntry() { | 120 | + public Map.Entry<String, Versioned<V>> pollLastEntry() { |
| 118 | return complete(treeMap.pollLastEntry()); | 121 | return complete(treeMap.pollLastEntry()); |
| 119 | } | 122 | } |
| 120 | 123 | ||
| 121 | @Override | 124 | @Override |
| 122 | - public K lowerKey(K key) { | 125 | + public String lowerKey(String key) { |
| 123 | return complete(treeMap.lowerKey(key)); | 126 | return complete(treeMap.lowerKey(key)); |
| 124 | } | 127 | } |
| 125 | 128 | ||
| 126 | @Override | 129 | @Override |
| 127 | - public K floorKey(K key) { | 130 | + public String floorKey(String key) { |
| 128 | return complete(treeMap.floorKey(key)); | 131 | return complete(treeMap.floorKey(key)); |
| 129 | } | 132 | } |
| 130 | 133 | ||
| 131 | @Override | 134 | @Override |
| 132 | - public K ceilingKey(K key) { | 135 | + public String ceilingKey(String key) { |
| 133 | return complete(treeMap.ceilingKey(key)); | 136 | return complete(treeMap.ceilingKey(key)); |
| 134 | } | 137 | } |
| 135 | 138 | ||
| 136 | @Override | 139 | @Override |
| 137 | - public K higherKey(K key) { | 140 | + public String higherKey(String key) { |
| 138 | return complete(treeMap.higherKey(key)); | 141 | return complete(treeMap.higherKey(key)); |
| 139 | } | 142 | } |
| 140 | 143 | ||
| ... | @@ -144,7 +147,7 @@ public class DefaultConsistentTreeMap<K, V> extends Synchronous<AsyncConsistentT | ... | @@ -144,7 +147,7 @@ public class DefaultConsistentTreeMap<K, V> extends Synchronous<AsyncConsistentT |
| 144 | * {@inheritDoc} | 147 | * {@inheritDoc} |
| 145 | * <p>This may be a long operation with greater risk of timeout.</p> | 148 | * <p>This may be a long operation with greater risk of timeout.</p> |
| 146 | */ | 149 | */ |
| 147 | - public NavigableSet<K> navigableKeySet() { | 150 | + public NavigableSet<String> navigableKeySet() { |
| 148 | return complete(treeMap.navigableKeySet()); | 151 | return complete(treeMap.navigableKeySet()); |
| 149 | } | 152 | } |
| 150 | 153 | ||
| ... | @@ -159,7 +162,7 @@ public class DefaultConsistentTreeMap<K, V> extends Synchronous<AsyncConsistentT | ... | @@ -159,7 +162,7 @@ public class DefaultConsistentTreeMap<K, V> extends Synchronous<AsyncConsistentT |
| 159 | } | 162 | } |
| 160 | 163 | ||
| 161 | @Override | 164 | @Override |
| 162 | - public boolean containsKey(K key) { | 165 | + public boolean containsKey(String key) { |
| 163 | return complete(treeMap.containsKey(key)); | 166 | return complete(treeMap.containsKey(key)); |
| 164 | } | 167 | } |
| 165 | 168 | ||
| ... | @@ -169,43 +172,54 @@ public class DefaultConsistentTreeMap<K, V> extends Synchronous<AsyncConsistentT | ... | @@ -169,43 +172,54 @@ public class DefaultConsistentTreeMap<K, V> extends Synchronous<AsyncConsistentT |
| 169 | } | 172 | } |
| 170 | 173 | ||
| 171 | @Override | 174 | @Override |
| 172 | - public Versioned<V> get(K key) { | 175 | + public Versioned<V> get(String key) { |
| 173 | return complete(treeMap.get(key)); | 176 | return complete(treeMap.get(key)); |
| 174 | } | 177 | } |
| 175 | 178 | ||
| 176 | @Override | 179 | @Override |
| 177 | - public Versioned<V> computeIfAbsent(K key, Function<? super K, ? extends V> mappingFunction) { | 180 | + public Versioned<V> computeIfAbsent(String key, |
| 181 | + Function<? super String, | ||
| 182 | + ? extends V> mappingFunction) { | ||
| 178 | return complete(treeMap.computeIfAbsent(key, mappingFunction)); | 183 | return complete(treeMap.computeIfAbsent(key, mappingFunction)); |
| 179 | } | 184 | } |
| 180 | 185 | ||
| 181 | @Override | 186 | @Override |
| 182 | - public Versioned<V> compute(K key, BiFunction<? super K, ? super V, ? extends V> remappingFunction) { | 187 | + public Versioned<V> compute(String key, |
| 188 | + BiFunction<? super String, | ||
| 189 | + ? super V, | ||
| 190 | + ? extends V> remappingFunction) { | ||
| 183 | return complete(treeMap.compute(key, remappingFunction)); | 191 | return complete(treeMap.compute(key, remappingFunction)); |
| 184 | } | 192 | } |
| 185 | 193 | ||
| 186 | @Override | 194 | @Override |
| 187 | - public Versioned<V> computeIfPresent(K key, BiFunction<? super K, ? super V, ? extends V> remappingFunction) { | 195 | + public Versioned<V> computeIfPresent( |
| 196 | + String key, | ||
| 197 | + BiFunction<? super String, | ||
| 198 | + ? super V, | ||
| 199 | + ? extends V> remappingFunction) { | ||
| 188 | return complete(treeMap.computeIfPresent(key, remappingFunction)); | 200 | return complete(treeMap.computeIfPresent(key, remappingFunction)); |
| 189 | } | 201 | } |
| 190 | 202 | ||
| 191 | @Override | 203 | @Override |
| 192 | - public Versioned<V> computeIf(K key, Predicate<? super V> condition, | 204 | + public Versioned<V> computeIf(String key, Predicate<? super V> condition, |
| 193 | - BiFunction<? super K, ? super V, ? extends V> remappingFunction) { | 205 | + BiFunction<? super String, |
| 206 | + ? super V, | ||
| 207 | + ? extends V> remappingFunction) { | ||
| 194 | return complete(treeMap.computeIf(key, condition, remappingFunction)); | 208 | return complete(treeMap.computeIf(key, condition, remappingFunction)); |
| 195 | } | 209 | } |
| 196 | 210 | ||
| 197 | @Override | 211 | @Override |
| 198 | - public Versioned<V> put(K key, V value) { | 212 | + public Versioned<V> put(String key, V value) { |
| 199 | return complete(treeMap.put(key, value)); | 213 | return complete(treeMap.put(key, value)); |
| 200 | } | 214 | } |
| 201 | 215 | ||
| 202 | @Override | 216 | @Override |
| 203 | - public Versioned<V> putAndGet(K key, V value) { | 217 | + public Versioned<V> putAndGet(String key, V value) { |
| 204 | return complete(treeMap.putAndGet(key, value)); | 218 | return complete(treeMap.putAndGet(key, value)); |
| 205 | } | 219 | } |
| 206 | 220 | ||
| 207 | @Override | 221 | @Override |
| 208 | - public Versioned<V> remove(K key) { | 222 | + public Versioned<V> remove(String key) { |
| 209 | return complete(treeMap.remove(key)); | 223 | return complete(treeMap.remove(key)); |
| 210 | } | 224 | } |
| 211 | 225 | ||
| ... | @@ -215,7 +229,7 @@ public class DefaultConsistentTreeMap<K, V> extends Synchronous<AsyncConsistentT | ... | @@ -215,7 +229,7 @@ public class DefaultConsistentTreeMap<K, V> extends Synchronous<AsyncConsistentT |
| 215 | } | 229 | } |
| 216 | 230 | ||
| 217 | @Override | 231 | @Override |
| 218 | - public Set<K> keySet() { | 232 | + public Set<String> keySet() { |
| 219 | return complete(treeMap.keySet()); | 233 | return complete(treeMap.keySet()); |
| 220 | } | 234 | } |
| 221 | 235 | ||
| ... | @@ -225,52 +239,53 @@ public class DefaultConsistentTreeMap<K, V> extends Synchronous<AsyncConsistentT | ... | @@ -225,52 +239,53 @@ public class DefaultConsistentTreeMap<K, V> extends Synchronous<AsyncConsistentT |
| 225 | } | 239 | } |
| 226 | 240 | ||
| 227 | @Override | 241 | @Override |
| 228 | - public Set<Map.Entry<K, Versioned<V>>> entrySet() { | 242 | + public Set<Map.Entry<String, Versioned<V>>> entrySet() { |
| 229 | return complete(treeMap.entrySet()); | 243 | return complete(treeMap.entrySet()); |
| 230 | } | 244 | } |
| 231 | 245 | ||
| 232 | @Override | 246 | @Override |
| 233 | - public Versioned<V> putIfAbsent(K key, V value) { | 247 | + public Versioned<V> putIfAbsent(String key, V value) { |
| 234 | return complete(treeMap.putIfAbsent(key, value)); | 248 | return complete(treeMap.putIfAbsent(key, value)); |
| 235 | } | 249 | } |
| 236 | 250 | ||
| 237 | @Override | 251 | @Override |
| 238 | - public boolean remove(K key, V value) { | 252 | + public boolean remove(String key, V value) { |
| 239 | return complete(treeMap.remove(key, value)); | 253 | return complete(treeMap.remove(key, value)); |
| 240 | } | 254 | } |
| 241 | 255 | ||
| 242 | @Override | 256 | @Override |
| 243 | - public boolean remove(K key, long version) { | 257 | + public boolean remove(String key, long version) { |
| 244 | return complete(treeMap.remove(key, version)); | 258 | return complete(treeMap.remove(key, version)); |
| 245 | } | 259 | } |
| 246 | 260 | ||
| 247 | @Override | 261 | @Override |
| 248 | - public Versioned<V> replace(K key, V value) { | 262 | + public Versioned<V> replace(String key, V value) { |
| 249 | return complete(treeMap.replace(key, value)); | 263 | return complete(treeMap.replace(key, value)); |
| 250 | } | 264 | } |
| 251 | 265 | ||
| 252 | @Override | 266 | @Override |
| 253 | - public boolean replace(K key, V oldValue, V newValue) { | 267 | + public boolean replace(String key, V oldValue, V newValue) { |
| 254 | return complete(treeMap.replace(key, oldValue, newValue)); | 268 | return complete(treeMap.replace(key, oldValue, newValue)); |
| 255 | } | 269 | } |
| 256 | 270 | ||
| 257 | @Override | 271 | @Override |
| 258 | - public boolean replace(K key, long oldVersion, V newValue) { | 272 | + public boolean replace(String key, long oldVersion, V newValue) { |
| 259 | return complete(treeMap.replace(key, oldVersion, newValue)); | 273 | return complete(treeMap.replace(key, oldVersion, newValue)); |
| 260 | } | 274 | } |
| 261 | 275 | ||
| 262 | @Override | 276 | @Override |
| 263 | - public void addListener(MapEventListener<K, V> listener, Executor executor) { | 277 | + public void addListener(MapEventListener<String, V> listener, |
| 278 | + Executor executor) { | ||
| 264 | complete(treeMap.addListener(listener, executor)); | 279 | complete(treeMap.addListener(listener, executor)); |
| 265 | } | 280 | } |
| 266 | 281 | ||
| 267 | @Override | 282 | @Override |
| 268 | - public void removeListener(MapEventListener<K, V> listener) { | 283 | + public void removeListener(MapEventListener<String, V> listener) { |
| 269 | complete(treeMap.removeListener(listener)); | 284 | complete(treeMap.removeListener(listener)); |
| 270 | } | 285 | } |
| 271 | 286 | ||
| 272 | @Override | 287 | @Override |
| 273 | - public Map<K, V> asJavaMap() { | 288 | + public Map<String, V> asJavaMap() { |
| 274 | synchronized (this) { | 289 | synchronized (this) { |
| 275 | if (javaMap == null) { | 290 | if (javaMap == null) { |
| 276 | javaMap = new ConsistentMapBackedJavaMap<>(this); | 291 | javaMap = new ConsistentMapBackedJavaMap<>(this); |
| ... | @@ -278,4 +293,13 @@ public class DefaultConsistentTreeMap<K, V> extends Synchronous<AsyncConsistentT | ... | @@ -278,4 +293,13 @@ public class DefaultConsistentTreeMap<K, V> extends Synchronous<AsyncConsistentT |
| 278 | } | 293 | } |
| 279 | return javaMap; | 294 | return javaMap; |
| 280 | } | 295 | } |
| 296 | + | ||
| 297 | + @Override | ||
| 298 | + public NavigableMap<String, V> subMap(String upperKey, | ||
| 299 | + String lowerKey, | ||
| 300 | + boolean inclusiveUpper, | ||
| 301 | + boolean inclusiveLower) { | ||
| 302 | + return complete(treeMap.subMap(upperKey, lowerKey, | ||
| 303 | + inclusiveUpper, inclusiveLower)); | ||
| 304 | + } | ||
| 281 | } | 305 | } | ... | ... |
| ... | @@ -23,24 +23,27 @@ import java.util.NavigableMap; | ... | @@ -23,24 +23,27 @@ import java.util.NavigableMap; |
| 23 | import java.util.NavigableSet; | 23 | import java.util.NavigableSet; |
| 24 | import java.util.concurrent.CompletableFuture; | 24 | import java.util.concurrent.CompletableFuture; |
| 25 | 25 | ||
| 26 | +import static org.onosproject.store.service.DistributedPrimitive.DEFAULT_OPERTATION_TIMEOUT_MILLIS; | ||
| 27 | + | ||
| 26 | /** | 28 | /** |
| 27 | * API for a distributed tree map implementation. | 29 | * API for a distributed tree map implementation. |
| 28 | */ | 30 | */ |
| 29 | -public interface AsyncConsistentTreeMap<K, V> extends AsyncConsistentMap<K, V> { | 31 | +public interface AsyncConsistentTreeMap<V> |
| 32 | + extends AsyncConsistentMap<String, V> { | ||
| 30 | 33 | ||
| 31 | /** | 34 | /** |
| 32 | * Return the lowest key in the map. | 35 | * Return the lowest key in the map. |
| 33 | * | 36 | * |
| 34 | * @return the key or null if none exist | 37 | * @return the key or null if none exist |
| 35 | */ | 38 | */ |
| 36 | - CompletableFuture<K> firstKey(); | 39 | + CompletableFuture<String> firstKey(); |
| 37 | 40 | ||
| 38 | /** | 41 | /** |
| 39 | * Return the highest key in the map. | 42 | * Return the highest key in the map. |
| 40 | * | 43 | * |
| 41 | * @return the key or null if none exist | 44 | * @return the key or null if none exist |
| 42 | */ | 45 | */ |
| 43 | - CompletableFuture<K> lastKey(); | 46 | + CompletableFuture<String> lastKey(); |
| 44 | 47 | ||
| 45 | /** | 48 | /** |
| 46 | * Returns the entry associated with the least key greater than or equal to | 49 | * Returns the entry associated with the least key greater than or equal to |
| ... | @@ -49,7 +52,8 @@ public interface AsyncConsistentTreeMap<K, V> extends AsyncConsistentMap<K, V> { | ... | @@ -49,7 +52,8 @@ public interface AsyncConsistentTreeMap<K, V> extends AsyncConsistentMap<K, V> { |
| 49 | * @param key the key | 52 | * @param key the key |
| 50 | * @return the entry or null if no suitable key exists | 53 | * @return the entry or null if no suitable key exists |
| 51 | */ | 54 | */ |
| 52 | - CompletableFuture<Map.Entry<K, Versioned<V>>> ceilingEntry(K key); | 55 | + CompletableFuture<Map.Entry<String, Versioned<V>>> ceilingEntry( |
| 56 | + String key); | ||
| 53 | 57 | ||
| 54 | /** | 58 | /** |
| 55 | * Returns the entry associated with the greatest key less than or equal | 59 | * Returns the entry associated with the greatest key less than or equal |
| ... | @@ -58,7 +62,7 @@ public interface AsyncConsistentTreeMap<K, V> extends AsyncConsistentMap<K, V> { | ... | @@ -58,7 +62,7 @@ public interface AsyncConsistentTreeMap<K, V> extends AsyncConsistentMap<K, V> { |
| 58 | * @param key the key | 62 | * @param key the key |
| 59 | * @return the entry or null if no suitable key exists | 63 | * @return the entry or null if no suitable key exists |
| 60 | */ | 64 | */ |
| 61 | - CompletableFuture<Map.Entry<K, Versioned<V>>> floorEntry(K key); | 65 | + CompletableFuture<Map.Entry<String, Versioned<V>>> floorEntry(String key); |
| 62 | 66 | ||
| 63 | /** | 67 | /** |
| 64 | * Returns the entry associated with the least key greater than key. | 68 | * Returns the entry associated with the least key greater than key. |
| ... | @@ -66,7 +70,7 @@ public interface AsyncConsistentTreeMap<K, V> extends AsyncConsistentMap<K, V> { | ... | @@ -66,7 +70,7 @@ public interface AsyncConsistentTreeMap<K, V> extends AsyncConsistentMap<K, V> { |
| 66 | * @param key the key | 70 | * @param key the key |
| 67 | * @return the entry or null if no suitable key exists | 71 | * @return the entry or null if no suitable key exists |
| 68 | */ | 72 | */ |
| 69 | - CompletableFuture<Map.Entry<K, Versioned<V>>> higherEntry(K key); | 73 | + CompletableFuture<Map.Entry<String, Versioned<V>>> higherEntry(String key); |
| 70 | 74 | ||
| 71 | /** | 75 | /** |
| 72 | * Returns the entry associated with the largest key less than key. | 76 | * Returns the entry associated with the largest key less than key. |
| ... | @@ -74,35 +78,35 @@ public interface AsyncConsistentTreeMap<K, V> extends AsyncConsistentMap<K, V> { | ... | @@ -74,35 +78,35 @@ public interface AsyncConsistentTreeMap<K, V> extends AsyncConsistentMap<K, V> { |
| 74 | * @param key the key | 78 | * @param key the key |
| 75 | * @return the entry or null if no suitable key exists | 79 | * @return the entry or null if no suitable key exists |
| 76 | */ | 80 | */ |
| 77 | - CompletableFuture<Map.Entry<K, Versioned<V>>> lowerEntry(K key); | 81 | + CompletableFuture<Map.Entry<String, Versioned<V>>> lowerEntry(String key); |
| 78 | 82 | ||
| 79 | /** | 83 | /** |
| 80 | * Return the entry associated with the lowest key in the map. | 84 | * Return the entry associated with the lowest key in the map. |
| 81 | * | 85 | * |
| 82 | * @return the entry or null if none exist | 86 | * @return the entry or null if none exist |
| 83 | */ | 87 | */ |
| 84 | - CompletableFuture<Map.Entry<K, Versioned<V>>> firstEntry(); | 88 | + CompletableFuture<Map.Entry<String, Versioned<V>>> firstEntry(); |
| 85 | 89 | ||
| 86 | /** | 90 | /** |
| 87 | * Return the entry associated with the highest key in the map. | 91 | * Return the entry associated with the highest key in the map. |
| 88 | * | 92 | * |
| 89 | * @return the entry or null if none exist | 93 | * @return the entry or null if none exist |
| 90 | */ | 94 | */ |
| 91 | - CompletableFuture<Map.Entry<K, Versioned<V>>> lastEntry(); | 95 | + CompletableFuture<Map.Entry<String, Versioned<V>>> lastEntry(); |
| 92 | 96 | ||
| 93 | /** | 97 | /** |
| 94 | * Return and remove the entry associated with the lowest key. | 98 | * Return and remove the entry associated with the lowest key. |
| 95 | * | 99 | * |
| 96 | * @return the entry or null if none exist | 100 | * @return the entry or null if none exist |
| 97 | */ | 101 | */ |
| 98 | - CompletableFuture<Map.Entry<K, Versioned<V>>> pollFirstEntry(); | 102 | + CompletableFuture<Map.Entry<String, Versioned<V>>> pollFirstEntry(); |
| 99 | 103 | ||
| 100 | /** | 104 | /** |
| 101 | * Return and remove the entry associated with the highest key. | 105 | * Return and remove the entry associated with the highest key. |
| 102 | * | 106 | * |
| 103 | * @return the entry or null if none exist | 107 | * @return the entry or null if none exist |
| 104 | */ | 108 | */ |
| 105 | - CompletableFuture<Map.Entry<K, Versioned<V>>> pollLastEntry(); | 109 | + CompletableFuture<Map.Entry<String, Versioned<V>>> pollLastEntry(); |
| 106 | 110 | ||
| 107 | /** | 111 | /** |
| 108 | * Return the entry associated with the greatest key less than key. | 112 | * Return the entry associated with the greatest key less than key. |
| ... | @@ -110,7 +114,7 @@ public interface AsyncConsistentTreeMap<K, V> extends AsyncConsistentMap<K, V> { | ... | @@ -110,7 +114,7 @@ public interface AsyncConsistentTreeMap<K, V> extends AsyncConsistentMap<K, V> { |
| 110 | * @param key the key | 114 | * @param key the key |
| 111 | * @return the entry or null if no suitable key exists | 115 | * @return the entry or null if no suitable key exists |
| 112 | */ | 116 | */ |
| 113 | - CompletableFuture<K> lowerKey(K key); | 117 | + CompletableFuture<String> lowerKey(String key); |
| 114 | 118 | ||
| 115 | /** | 119 | /** |
| 116 | * Return the highest key less than or equal to key. | 120 | * Return the highest key less than or equal to key. |
| ... | @@ -118,7 +122,7 @@ public interface AsyncConsistentTreeMap<K, V> extends AsyncConsistentMap<K, V> { | ... | @@ -118,7 +122,7 @@ public interface AsyncConsistentTreeMap<K, V> extends AsyncConsistentMap<K, V> { |
| 118 | * @param key the key | 122 | * @param key the key |
| 119 | * @return the entry or null if no suitable key exists | 123 | * @return the entry or null if no suitable key exists |
| 120 | */ | 124 | */ |
| 121 | - CompletableFuture<K> floorKey(K key); | 125 | + CompletableFuture<String> floorKey(String key); |
| 122 | 126 | ||
| 123 | /** | 127 | /** |
| 124 | * Return the lowest key greater than or equal to key. | 128 | * Return the lowest key greater than or equal to key. |
| ... | @@ -126,7 +130,7 @@ public interface AsyncConsistentTreeMap<K, V> extends AsyncConsistentMap<K, V> { | ... | @@ -126,7 +130,7 @@ public interface AsyncConsistentTreeMap<K, V> extends AsyncConsistentMap<K, V> { |
| 126 | * @param key the key | 130 | * @param key the key |
| 127 | * @return the entry or null if no suitable key exists | 131 | * @return the entry or null if no suitable key exists |
| 128 | */ | 132 | */ |
| 129 | - CompletableFuture<K> ceilingKey(K key); | 133 | + CompletableFuture<String> ceilingKey(String key); |
| 130 | 134 | ||
| 131 | /** | 135 | /** |
| 132 | * Return the lowest key greater than key. | 136 | * Return the lowest key greater than key. |
| ... | @@ -134,14 +138,14 @@ public interface AsyncConsistentTreeMap<K, V> extends AsyncConsistentMap<K, V> { | ... | @@ -134,14 +138,14 @@ public interface AsyncConsistentTreeMap<K, V> extends AsyncConsistentMap<K, V> { |
| 134 | * @param key the key | 138 | * @param key the key |
| 135 | * @return the entry or null if no suitable key exists | 139 | * @return the entry or null if no suitable key exists |
| 136 | */ | 140 | */ |
| 137 | - CompletableFuture<K> higherKey(K key); | 141 | + CompletableFuture<String> higherKey(String key); |
| 138 | 142 | ||
| 139 | /** | 143 | /** |
| 140 | * Returns a navigable set of the keys in this map. | 144 | * Returns a navigable set of the keys in this map. |
| 141 | * | 145 | * |
| 142 | * @return a navigable key set (this may be empty) | 146 | * @return a navigable key set (this may be empty) |
| 143 | */ | 147 | */ |
| 144 | - CompletableFuture<NavigableSet<K>> navigableKeySet(); | 148 | + CompletableFuture<NavigableSet<String>> navigableKeySet(); |
| 145 | 149 | ||
| 146 | /** | 150 | /** |
| 147 | * Returns a navigable map containing the entries from the original map | 151 | * Returns a navigable map containing the entries from the original map |
| ... | @@ -157,15 +161,16 @@ public interface AsyncConsistentTreeMap<K, V> extends AsyncConsistentMap<K, V> { | ... | @@ -157,15 +161,16 @@ public interface AsyncConsistentTreeMap<K, V> extends AsyncConsistentMap<K, V> { |
| 157 | * @return a navigable map containing entries in the specified range (this | 161 | * @return a navigable map containing entries in the specified range (this |
| 158 | * may be empty) | 162 | * may be empty) |
| 159 | */ | 163 | */ |
| 160 | - CompletableFuture<NavigableMap<K, V>> subMap(K upperKey, K lowerKey, | 164 | + CompletableFuture<NavigableMap<String, V>> subMap(String upperKey, |
| 161 | - boolean inclusiveUpper, | 165 | + String lowerKey, |
| 162 | - boolean inclusiveLower); | 166 | + boolean inclusiveUpper, |
| 167 | + boolean inclusiveLower); | ||
| 163 | 168 | ||
| 164 | - default ConsistentTreeMap<K, V> asTreeMap() { | 169 | + default ConsistentTreeMap<V> asTreeMap() { |
| 165 | - return asTreeMap(DistributedPrimitive.DEFAULT_OPERTATION_TIMEOUT_MILLIS); | 170 | + return asTreeMap(DEFAULT_OPERTATION_TIMEOUT_MILLIS); |
| 166 | } | 171 | } |
| 167 | 172 | ||
| 168 | - default ConsistentTreeMap<K, V> asTreeMap(long timeoutMillis) { | 173 | + default ConsistentTreeMap<V> asTreeMap(long timeoutMillis) { |
| 169 | return new DefaultConsistentTreeMap<>(this, timeoutMillis); | 174 | return new DefaultConsistentTreeMap<>(this, timeoutMillis); |
| 170 | } | 175 | } |
| 171 | 176 | ... | ... |
| ... | @@ -17,26 +17,27 @@ | ... | @@ -17,26 +17,27 @@ |
| 17 | package org.onosproject.store.service; | 17 | package org.onosproject.store.service; |
| 18 | 18 | ||
| 19 | import java.util.Map; | 19 | import java.util.Map; |
| 20 | +import java.util.NavigableMap; | ||
| 20 | import java.util.NavigableSet; | 21 | import java.util.NavigableSet; |
| 21 | 22 | ||
| 22 | /** | 23 | /** |
| 23 | * Tree map interface counterpart to {@link AsyncConsistentTreeMap}. | 24 | * Tree map interface counterpart to {@link AsyncConsistentTreeMap}. |
| 24 | */ | 25 | */ |
| 25 | - public interface ConsistentTreeMap<K, V> extends ConsistentMap<K, V> { | 26 | + public interface ConsistentTreeMap<V> extends ConsistentMap<String, V> { |
| 26 | 27 | ||
| 27 | /** | 28 | /** |
| 28 | * Returns the lowest key in the map. | 29 | * Returns the lowest key in the map. |
| 29 | * | 30 | * |
| 30 | * @return the key or null if none exist | 31 | * @return the key or null if none exist |
| 31 | */ | 32 | */ |
| 32 | - K firstKey(); | 33 | + String firstKey(); |
| 33 | 34 | ||
| 34 | /** | 35 | /** |
| 35 | * Returns the highest key in the map. | 36 | * Returns the highest key in the map. |
| 36 | * | 37 | * |
| 37 | * @return the key or null if none exist | 38 | * @return the key or null if none exist |
| 38 | */ | 39 | */ |
| 39 | - K lastKey(); | 40 | + String lastKey(); |
| 40 | 41 | ||
| 41 | /** | 42 | /** |
| 42 | * Returns the entry associated with the least key greater than or equal to the key. | 43 | * Returns the entry associated with the least key greater than or equal to the key. |
| ... | @@ -44,7 +45,7 @@ import java.util.NavigableSet; | ... | @@ -44,7 +45,7 @@ import java.util.NavigableSet; |
| 44 | * @param key the key | 45 | * @param key the key |
| 45 | * @return the entry or null | 46 | * @return the entry or null |
| 46 | */ | 47 | */ |
| 47 | - Map.Entry<K, Versioned<V>> ceilingEntry(K key); | 48 | + Map.Entry<String, Versioned<V>> ceilingEntry(String key); |
| 48 | 49 | ||
| 49 | /** | 50 | /** |
| 50 | * Returns the entry associated with the greatest key less than or equal to key. | 51 | * Returns the entry associated with the greatest key less than or equal to key. |
| ... | @@ -52,7 +53,7 @@ import java.util.NavigableSet; | ... | @@ -52,7 +53,7 @@ import java.util.NavigableSet; |
| 52 | * @param key the key | 53 | * @param key the key |
| 53 | * @return the entry or null | 54 | * @return the entry or null |
| 54 | */ | 55 | */ |
| 55 | - Map.Entry<K, Versioned<V>> floorEntry(K key); | 56 | + Map.Entry<String, Versioned<V>> floorEntry(String key); |
| 56 | 57 | ||
| 57 | /** | 58 | /** |
| 58 | * Returns the entry associated with the lest key greater than key. | 59 | * Returns the entry associated with the lest key greater than key. |
| ... | @@ -60,7 +61,7 @@ import java.util.NavigableSet; | ... | @@ -60,7 +61,7 @@ import java.util.NavigableSet; |
| 60 | * @param key the key | 61 | * @param key the key |
| 61 | * @return the entry or null | 62 | * @return the entry or null |
| 62 | */ | 63 | */ |
| 63 | - Map.Entry<K, Versioned<V>> higherEntry(K key); | 64 | + Map.Entry<String, Versioned<V>> higherEntry(String key); |
| 64 | 65 | ||
| 65 | /** | 66 | /** |
| 66 | * Returns the entry associated with the largest key less than key. | 67 | * Returns the entry associated with the largest key less than key. |
| ... | @@ -68,35 +69,35 @@ import java.util.NavigableSet; | ... | @@ -68,35 +69,35 @@ import java.util.NavigableSet; |
| 68 | * @param key the key | 69 | * @param key the key |
| 69 | * @return the entry or null | 70 | * @return the entry or null |
| 70 | */ | 71 | */ |
| 71 | - Map.Entry<K, Versioned<V>> lowerEntry(K key); | 72 | + Map.Entry<String, Versioned<V>> lowerEntry(String key); |
| 72 | 73 | ||
| 73 | /** | 74 | /** |
| 74 | * Returns the entry associated with the lowest key in the map. | 75 | * Returns the entry associated with the lowest key in the map. |
| 75 | * | 76 | * |
| 76 | * @return the entry or null | 77 | * @return the entry or null |
| 77 | */ | 78 | */ |
| 78 | - Map.Entry<K, Versioned<V>> firstEntry(); | 79 | + Map.Entry<String, Versioned<V>> firstEntry(); |
| 79 | 80 | ||
| 80 | /** | 81 | /** |
| 81 | * Returns the entry associated with the highest key in the map. | 82 | * Returns the entry associated with the highest key in the map. |
| 82 | * | 83 | * |
| 83 | * @return the entry or null | 84 | * @return the entry or null |
| 84 | */ | 85 | */ |
| 85 | - Map.Entry<K, Versioned<V>> lastEntry(); | 86 | + Map.Entry<String, Versioned<V>> lastEntry(); |
| 86 | 87 | ||
| 87 | /** | 88 | /** |
| 88 | * Returns and removes the entry associated with the lowest key. | 89 | * Returns and removes the entry associated with the lowest key. |
| 89 | * | 90 | * |
| 90 | * @return the entry or null | 91 | * @return the entry or null |
| 91 | */ | 92 | */ |
| 92 | - Map.Entry<K, Versioned<V>> pollFirstEntry(); | 93 | + Map.Entry<String, Versioned<V>> pollFirstEntry(); |
| 93 | 94 | ||
| 94 | /** | 95 | /** |
| 95 | * Returns and removes the entry associated with the highest key. | 96 | * Returns and removes the entry associated with the highest key. |
| 96 | * | 97 | * |
| 97 | * @return the entry or null | 98 | * @return the entry or null |
| 98 | */ | 99 | */ |
| 99 | - Map.Entry<K, Versioned<V>> pollLastEntry(); | 100 | + Map.Entry<String, Versioned<V>> pollLastEntry(); |
| 100 | 101 | ||
| 101 | /** | 102 | /** |
| 102 | * Returns the entry associated with the greatest key less than key. | 103 | * Returns the entry associated with the greatest key less than key. |
| ... | @@ -104,7 +105,7 @@ import java.util.NavigableSet; | ... | @@ -104,7 +105,7 @@ import java.util.NavigableSet; |
| 104 | * @param key the key | 105 | * @param key the key |
| 105 | * @return the entry or null | 106 | * @return the entry or null |
| 106 | */ | 107 | */ |
| 107 | - K lowerKey(K key); | 108 | + String lowerKey(String key); |
| 108 | 109 | ||
| 109 | /** | 110 | /** |
| 110 | * Returns the entry associated with the highest key less than or equal to key. | 111 | * Returns the entry associated with the highest key less than or equal to key. |
| ... | @@ -112,7 +113,7 @@ import java.util.NavigableSet; | ... | @@ -112,7 +113,7 @@ import java.util.NavigableSet; |
| 112 | * @param key the key | 113 | * @param key the key |
| 113 | * @return the entry or null | 114 | * @return the entry or null |
| 114 | */ | 115 | */ |
| 115 | - K floorKey(K key); | 116 | + String floorKey(String key); |
| 116 | 117 | ||
| 117 | /** | 118 | /** |
| 118 | * Returns the lowest key greater than or equal to key. | 119 | * Returns the lowest key greater than or equal to key. |
| ... | @@ -120,7 +121,7 @@ import java.util.NavigableSet; | ... | @@ -120,7 +121,7 @@ import java.util.NavigableSet; |
| 120 | * @param key the key | 121 | * @param key the key |
| 121 | * @return the key or null | 122 | * @return the key or null |
| 122 | */ | 123 | */ |
| 123 | - K ceilingKey(K key); | 124 | + String ceilingKey(String key); |
| 124 | 125 | ||
| 125 | /** | 126 | /** |
| 126 | * Returns the lowest key greater than key. | 127 | * Returns the lowest key greater than key. |
| ... | @@ -128,13 +129,32 @@ import java.util.NavigableSet; | ... | @@ -128,13 +129,32 @@ import java.util.NavigableSet; |
| 128 | * @param key the key | 129 | * @param key the key |
| 129 | * @return the key or null | 130 | * @return the key or null |
| 130 | */ | 131 | */ |
| 131 | - K higherKey(K key); | 132 | + String higherKey(String key); |
| 132 | 133 | ||
| 133 | /** | 134 | /** |
| 134 | * Returns a navigable set of the keys in this map. | 135 | * Returns a navigable set of the keys in this map. |
| 135 | * | 136 | * |
| 136 | * @return a navigable key set | 137 | * @return a navigable key set |
| 137 | */ | 138 | */ |
| 138 | - NavigableSet<K> navigableKeySet(); | 139 | + NavigableSet<String> navigableKeySet(); |
| 140 | + | ||
| 141 | + /** | ||
| 142 | + * Returns a navigable map containing the entries from the original map | ||
| 143 | + * which are larger than (or if specified equal to) {@code lowerKey} AND | ||
| 144 | + * less than (or if specified equal to) {@code upperKey}. | ||
| 145 | + * | ||
| 146 | + * @param upperKey the upper bound for the keys in this map | ||
| 147 | + * @param lowerKey the lower bound for the keys in this map | ||
| 148 | + * @param inclusiveUpper whether keys equal to the upperKey should be | ||
| 149 | + * included | ||
| 150 | + * @param inclusiveLower whether keys equal to the lowerKey should be | ||
| 151 | + * included | ||
| 152 | + * @return a navigable map containing entries in the specified range (this | ||
| 153 | + * may be empty) | ||
| 154 | + */ | ||
| 155 | + NavigableMap<String, V> subMap(String upperKey, | ||
| 156 | + String lowerKey, | ||
| 157 | + boolean inclusiveUpper, | ||
| 158 | + boolean inclusiveLower); | ||
| 139 | 159 | ||
| 140 | } | 160 | } | ... | ... |
| ... | @@ -74,7 +74,7 @@ import static org.onosproject.store.primitives.resources.impl.AtomixConsistentTr | ... | @@ -74,7 +74,7 @@ import static org.onosproject.store.primitives.resources.impl.AtomixConsistentTr |
| 74 | */ | 74 | */ |
| 75 | @ResourceTypeInfo(id = -155, factory = AtomixConsistentTreeMapFactory.class) | 75 | @ResourceTypeInfo(id = -155, factory = AtomixConsistentTreeMapFactory.class) |
| 76 | public class AtomixConsistentTreeMap extends AbstractResource<AtomixConsistentTreeMap> | 76 | public class AtomixConsistentTreeMap extends AbstractResource<AtomixConsistentTreeMap> |
| 77 | - implements AsyncConsistentTreeMap<String, byte[]> { | 77 | + implements AsyncConsistentTreeMap<byte[]> { |
| 78 | 78 | ||
| 79 | private final Map<MapEventListener<String, byte[]>, Executor> | 79 | private final Map<MapEventListener<String, byte[]>, Executor> |
| 80 | mapEventListeners = Maps.newConcurrentMap(); | 80 | mapEventListeners = Maps.newConcurrentMap(); | ... | ... |
-
Please register or login to post a comment