Class Set<T>

java.lang.Object
me.sbasalaev.collection.Collection<T>
me.sbasalaev.collection.Set<T>
All Implemented Interfaces:
Cloneable, Iterable<T>, Traversable<T>
Direct Known Subclasses:
MutableSet

public abstract class Set<@Out T> extends Collection<T>
A collection of distinct elements.
  • Constructor Details

    • Set

      public Set()
      Constructor for subclasses.
  • Method Details

    • empty

      public static <T> Set<T> empty()
      Empty set.
    • of

      @SafeVarargs public static <T> Set<T> of(T... elements)
      Set containing given elements. When there are duplicate elements according to equals(), only the first of them is put in the resulting set.
    • union

      @SafeVarargs public static <T> Set<T> union(Set<? extends T>... sets)
      Set containing elements of all given sets. This method returns immutable set unaffected by changes to the original sets.
    • union

      public static <T> Set<T> union(Traversable<? extends Set<? extends T>> sets)
      Set containing elements of all given sets. This method returns immutable set unaffected by the changes to the original sets.
    • fromJava

      public static <T> Set<T> fromJava(Set<T> javaSet)
      Set view of given java set.
    • contains

      public abstract boolean contains(Object element)
      Whether given element is in this set.
    • isSuperset

      public boolean isSuperset(Set<?> other)
      Whether all elements of given set are also in this set.
    • isSubset

      public boolean isSubset(Set<?> other)
      Whether all elements of this set are also in the given set.
    • intersects

      public boolean intersects(Set<?> other)
      Whether any element of this set is also in the given set.
    • unite

      public Set<?> unite(Set<?> other)
      Set containing elements of both this and the other set. This method returns immutable set unaffected by changes to the original sets.
    • intersect

      public Set<T> intersect(Set<?> other)
      Set containing only elements of this set that are also in another set. This method returns immutable set unaffected by changes to the original sets.
    • without

      public Set<T> without(Set<?> other)
      Set containing only elements of this set that are not in another set. This method returns immutable set unaffected by changes to the original sets.
    • mapped

      public <R> Set<R> mapped(Function<? super @Out T,? extends R> mapping)
      Returns set with given mapping applied to all elements of this set. This method returns immutable set unaffected by changes to this set.
      Specified by:
      mapped in class Collection<T>
    • filtered

      public Set<T> filtered(Predicate<? super @Out T> condition)
      Returns set that contains only elements of this set satisfying given condition. This method returns immutable set unaffected by changes to this set.
      Specified by:
      filtered in class Collection<T>
    • toJava

      public Set<T> toJava()
      Returns view of this set as Java set.
    • clone

      public final Set<T> clone()
      Returns shallow immutable copy of this set. May return itself if this set is immutable.
      Specified by:
      clone in class Collection<T>
    • spliterator

      public Spliterator<T> spliterator()
      Description copied from class: Collection
      Creates a Spliterator over elements of this collection. The spliterator reports Spliterator.NONNULL and Spliterator.SIZED.
      Specified by:
      spliterator in interface Iterable<T>
      Specified by:
      spliterator in class Collection<T>
    • equals

      public boolean equals(@Nullable Object obj)
      Whether given object is equal to this set. Two sets are equal if they contain the same elements, i.e.
      this.isSuperset(other) && this.isSubset(other)
      Specified by:
      equals in class Collection<T>
    • hashCode

      public int hashCode()
      Hash code of the set. The hash code of the set is a sum of hash codes of its elements.
      Specified by:
      hashCode in class Collection<T>