Madan Jampani | a090a11 | 2016-01-18 16:38:17 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2015-2016 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 | package org.onosproject.store.service; |
| 17 | |
| 18 | import java.util.Collection; |
| 19 | import java.util.Set; |
| 20 | import java.util.concurrent.CompletableFuture; |
| 21 | |
| 22 | /** |
| 23 | * A distributed collection designed for holding unique elements. |
| 24 | * <p> |
| 25 | * All methods of {@code AsyncDistributedSet} immediately return a {@link CompletableFuture future}. |
| 26 | * The returned future will be {@link CompletableFuture#complete completed} when the operation |
| 27 | * completes. |
| 28 | * |
| 29 | * @param <E> set entry type |
| 30 | */ |
| 31 | public interface AsyncDistributedSet<E> extends DistributedPrimitive { |
| 32 | |
| 33 | @Override |
| 34 | default DistributedPrimitive.Type type() { |
| 35 | return DistributedPrimitive.Type.SET; |
| 36 | } |
| 37 | |
| 38 | /** |
| 39 | * Registers the specified listener to be notified whenever |
| 40 | * the set is updated. |
| 41 | * |
| 42 | * @param listener listener to notify about set update events |
| 43 | */ |
| 44 | CompletableFuture<Void> addListener(SetEventListener<E> listener); |
| 45 | |
| 46 | /** |
| 47 | * Unregisters the specified listener. |
| 48 | * |
| 49 | * @param listener listener to unregister. |
| 50 | * @return CompletableFuture that is completed when the operation completes |
| 51 | */ |
| 52 | CompletableFuture<Void> removeListener(SetEventListener<E> listener); |
| 53 | |
| 54 | /** |
| 55 | * Adds the specified element to this set if it is not already present (optional operation). |
| 56 | * @param element element to add |
| 57 | * @return {@code true} if this set did not already contain the specified element. |
| 58 | */ |
| 59 | CompletableFuture<Boolean> add(E element); |
| 60 | |
| 61 | /** |
| 62 | * Removes the specified element to this set if it is present (optional operation). |
| 63 | * @param element element to remove |
| 64 | * @return {@code true} if this set contained the specified element |
| 65 | */ |
| 66 | CompletableFuture<Boolean> remove(E element); |
| 67 | |
| 68 | /** |
| 69 | * Returns the number of elements in the set. |
| 70 | * @return size of the set |
| 71 | */ |
| 72 | CompletableFuture<Integer> size(); |
| 73 | |
| 74 | /** |
| 75 | * Returns if the set is empty. |
| 76 | * @return {@code true} if this set is empty |
| 77 | */ |
| 78 | CompletableFuture<Boolean> isEmpty(); |
| 79 | |
| 80 | /** |
| 81 | * Removes all elements from the set. |
| 82 | */ |
| 83 | CompletableFuture<Void> clear(); |
| 84 | |
| 85 | /** |
| 86 | * Returns if this set contains the specified element. |
| 87 | * @param element element to check |
| 88 | * @return {@code true} if this set contains the specified element |
| 89 | */ |
| 90 | CompletableFuture<Boolean> contains(E element); |
| 91 | |
| 92 | /** |
| 93 | * Adds all of the elements in the specified collection to this set if they're not |
| 94 | * already present (optional operation). |
| 95 | * @param c collection containing elements to be added to this set |
| 96 | * @return {@code true} if this set contains all elements in the collection |
| 97 | */ |
| 98 | CompletableFuture<Boolean> addAll(Collection<? extends E> c); |
| 99 | |
| 100 | /** |
| 101 | * Returns if this set contains all the elements in specified collection. |
| 102 | * @param c collection |
| 103 | * @return {@code true} if this set contains all elements in the collection |
| 104 | */ |
| 105 | CompletableFuture<Boolean> containsAll(Collection<? extends E> c); |
| 106 | |
| 107 | /** |
| 108 | * Retains only the elements in this set that are contained in the specified collection (optional operation). |
| 109 | * @param c collection containing elements to be retained in this set |
| 110 | * @return {@code true} if this set changed as a result of the call |
| 111 | */ |
| 112 | CompletableFuture<Boolean> retainAll(Collection<? extends E> c); |
| 113 | |
| 114 | /** |
| 115 | * Removes from this set all of its elements that are contained in the specified collection (optional operation). |
| 116 | * If the specified collection is also a set, this operation effectively modifies this set so that its |
| 117 | * value is the asymmetric set difference of the two sets. |
| 118 | * @param c collection containing elements to be removed from this set |
| 119 | * @return {@code true} if this set changed as a result of the call |
| 120 | */ |
| 121 | CompletableFuture<Boolean> removeAll(Collection<? extends E> c); |
| 122 | |
| 123 | /** |
| 124 | * Returns the entries as a immutable set. The returned set is a snapshot and will not reflect new changes made to |
| 125 | * this AsyncDistributedSet |
| 126 | * @return immutable set copy |
| 127 | */ |
| 128 | CompletableFuture<? extends Set<E>> getAsImmutableSet(); |
| 129 | } |