Interface ReplicatedSet<E>

  • Type Parameters:
    E - The type of elements.
    All Superinterfaces:
    Iterable<E>, ReplicatedData

    public interface ReplicatedSet<E>
    extends ReplicatedData, Iterable<E>
    A Replicated Set that allows both the addition and removal of elements in a set.

    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

      All Methods Instance Methods Abstract Methods 
      Modifier and Type Method Description
      ReplicatedSet<E> add​(E element)
      Add an element to this set if it is not already present.
      ReplicatedSet<E> addAll​(java.util.Collection<E> elements)
      Add elements to this set if they're not already present.
      ReplicatedSet<E> clear()
      Remove all elements from this set.
      boolean contains​(E element)
      Check whether this set contains the given element.
      boolean containsAll​(java.util.Collection<E> elements)
      Check whether this set contains all the given elements.
      java.util.Set<E> elements()
      Elements of this set as a regular Set.
      boolean isEmpty()
      Check whether this set is empty.
      ReplicatedSet<E> remove​(E element)
      Remove an element from this set if it is present.
      ReplicatedSet<E> removeAll​(java.util.Collection<E> elements)
      Remove elements from this set if they're present.
      ReplicatedSet<E> retainAll​(java.util.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 Detail

      • 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

        java.util.Set<E> elements()
        Elements of this set as a regular Set.
        Returns:
        elements as Set
      • contains

        boolean contains​(E element)
        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

        ReplicatedSet<E> add​(E element)
        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

        ReplicatedSet<E> remove​(E element)
        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

        boolean containsAll​(java.util.Collection<E> elements)
        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

        ReplicatedSet<E> addAll​(java.util.Collection<E> elements)
        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

        ReplicatedSet<E> retainAll​(java.util.Collection<E> elements)
        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

        ReplicatedSet<E> removeAll​(java.util.Collection<E> elements)
        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