Interface ReplicatedSet<E>
- Type Parameters:
E
- The type of elements.
- All Superinterfaces:
Iterable<E>
,kalix.replicatedentity.ReplicatedData
A removal can only be done if all of the additions that added the key have been seen by this node. This means that, for example if node 1 adds element A, and node 2 also adds element A, then node 1's addition is replicated to node 3, and node 3 deletes it before node 2's addition is replicated, then the element will still be in the map because node 2's addition had not yet been observed by node 3, and will cause the element to be re-added when node 3 receives it. However, if both * additions had been replicated to node 3, then the element will be removed.
Care needs to be taken to ensure that the serialized value of elements in the set is stable. For example, if using protobufs, the serialized value of any maps contained in the protobuf is not stable, and can yield a different set of bytes for the same logically equal element. Hence maps should be avoided. Additionally, some changes in protobuf schemas which are backwards compatible from a protobuf perspective, such as changing from sint32 to int32, do result in different serialized bytes, and so must be avoided.
-
Method Summary
Modifier and TypeMethodDescriptionAdd an element to this set if it is not already present.addAll
(Collection<E> elements) Add elements to this set if they're not already present.clear()
Remove all elements from this set.boolean
Check whether this set contains the given element.boolean
containsAll
(Collection<E> elements) Check whether this set contains all the given elements.elements()
Elements of this set as a regularSet
.boolean
isEmpty()
Check whether this set is empty.Remove an element from this set if it is present.removeAll
(Collection<E> elements) Remove elements from this set if they're present.retainAll
(Collection<E> elements) Retain only the elements that are contained in the given collection.int
size()
Get the number of elements in this set (its cardinality).Methods inherited from interface java.lang.Iterable
forEach, iterator, spliterator
-
Method Details
-
size
int size()Get the number of elements in this set (its cardinality).- Returns:
- the number of elements in the set
-
isEmpty
boolean isEmpty()Check whether this set is empty.- Returns:
true
if this set contains no elements
-
elements
Elements of this set as a regularSet
.- Returns:
- elements as
Set
-
contains
Check whether this set contains the given element.- Parameters:
element
- element whose presence in this set is to be tested- Returns:
true
if this set contains the specified element
-
add
Add an element to this set if it is not already present.- Parameters:
element
- element to be added to this set- Returns:
- a new set with the additional element, or this unchanged set
-
remove
Remove an element from this set if it is present.- Parameters:
element
- element to be removed from this set- Returns:
- a new set without the removed element, or this unchanged set
-
containsAll
Check whether this set contains all the given elements.- Parameters:
elements
- collection to be checked for containment in this set- Returns:
true
if this set contains all the given elements
-
addAll
Add elements to this set if they're not already present.Effectively the union of two sets.
- Parameters:
elements
- collection containing elements to be added to this set- Returns:
- a new set with the additional elements, or this unchanged set
-
retainAll
Retain only the elements that are contained in the given collection.Effectively the intersection of two sets.
- Parameters:
elements
- collection containing elements to be retained in this set- Returns:
- a new set with the retained elements, or this unchanged set
-
removeAll
Remove elements from this set if they're present.Effectively the asymmetric set difference of two sets.
- Parameters:
elements
- collection containing elements to be removed from this set- Returns:
- a new set without the removed elements, or this unchanged set
-
clear
ReplicatedSet<E> clear()Remove all elements from this set.- Returns:
- a new empty set
-