blob: 251ee14a7f3f443d65d16e458617e29e71672f95 [file] [log] [blame]
Madan Jampania090a112016-01-18 16:38:17 -08001/*
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 */
16package org.onosproject.store.service;
17
18import java.util.Collection;
19import java.util.Set;
20import 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 */
31public 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
Jian Lidfba7392016-01-22 16:46:58 -080043 * @return CompletableFuture that is completed when the operation completes
Madan Jampania090a112016-01-18 16:38:17 -080044 */
45 CompletableFuture<Void> addListener(SetEventListener<E> listener);
46
47 /**
48 * Unregisters the specified listener.
49 *
50 * @param listener listener to unregister.
51 * @return CompletableFuture that is completed when the operation completes
52 */
53 CompletableFuture<Void> removeListener(SetEventListener<E> listener);
54
55 /**
56 * Adds the specified element to this set if it is not already present (optional operation).
57 * @param element element to add
58 * @return {@code true} if this set did not already contain the specified element.
59 */
60 CompletableFuture<Boolean> add(E element);
61
62 /**
63 * Removes the specified element to this set if it is present (optional operation).
64 * @param element element to remove
65 * @return {@code true} if this set contained the specified element
66 */
67 CompletableFuture<Boolean> remove(E element);
68
69 /**
70 * Returns the number of elements in the set.
71 * @return size of the set
72 */
73 CompletableFuture<Integer> size();
74
75 /**
76 * Returns if the set is empty.
77 * @return {@code true} if this set is empty
78 */
79 CompletableFuture<Boolean> isEmpty();
80
81 /**
82 * Removes all elements from the set.
Jian Lidfba7392016-01-22 16:46:58 -080083 * @return CompletableFuture that is completed when the operation completes
Madan Jampania090a112016-01-18 16:38:17 -080084 */
85 CompletableFuture<Void> clear();
86
87 /**
88 * Returns if this set contains the specified element.
89 * @param element element to check
90 * @return {@code true} if this set contains the specified element
91 */
92 CompletableFuture<Boolean> contains(E element);
93
94 /**
95 * Adds all of the elements in the specified collection to this set if they're not
96 * already present (optional operation).
97 * @param c collection containing elements to be added to this set
98 * @return {@code true} if this set contains all elements in the collection
99 */
100 CompletableFuture<Boolean> addAll(Collection<? extends E> c);
101
102 /**
103 * Returns if this set contains all the elements in specified collection.
104 * @param c collection
105 * @return {@code true} if this set contains all elements in the collection
106 */
107 CompletableFuture<Boolean> containsAll(Collection<? extends E> c);
108
109 /**
110 * Retains only the elements in this set that are contained in the specified collection (optional operation).
111 * @param c collection containing elements to be retained in this set
112 * @return {@code true} if this set changed as a result of the call
113 */
114 CompletableFuture<Boolean> retainAll(Collection<? extends E> c);
115
116 /**
117 * Removes from this set all of its elements that are contained in the specified collection (optional operation).
118 * If the specified collection is also a set, this operation effectively modifies this set so that its
119 * value is the asymmetric set difference of the two sets.
120 * @param c collection containing elements to be removed from this set
121 * @return {@code true} if this set changed as a result of the call
122 */
123 CompletableFuture<Boolean> removeAll(Collection<? extends E> c);
124
125 /**
126 * Returns the entries as a immutable set. The returned set is a snapshot and will not reflect new changes made to
127 * this AsyncDistributedSet
128 * @return immutable set copy
129 */
130 CompletableFuture<? extends Set<E>> getAsImmutableSet();
131}