Interface ImmutableSet<E>

Type Parameters:
E - the type of content of this Set
All Superinterfaces:
ImmutableCollection<E>, Iterable<E>, Serializable
All Known Subinterfaces:
ImmutableNavigableSet<E>, ImmutableSortedSet<E>
All Known Implementing Classes:
ImmutableAbstractSet, ImmutableHashSet, ImmutableLinkedHashSet, ImmutableTreeSet

public interface ImmutableSet<E> extends ImmutableCollection<E>
A Set interface without the methods that can change it. The constructor of the ImmutableSet needs to be given an initial Set.

Copyright (c) 2016-2024 Delft University of Technology, Jaffalaan 5, 2628 BX Delft, the Netherlands. All rights reserved. See for project information https://djutils.org. The DJUTILS project is distributed under a three-clause BSD-style license, which can be found at https://djutils.org/docs/license.html.

Author:
Alexander Verbraeck, Peter Knoppers
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    Force to redefine equals for the implementations of immutable collection classes.
    int
    Force to redefine hashCode for the implementations of immutable collection classes.
    static <E> ImmutableSet<E>
    of()
    Return an empty ImmutableSet, backed by a LinkedHashSet.
    static <E> ImmutableSet<E>
    of(E v1)
    Return an ImmutableSet with 1 entry, backed by a LinkedHashSet.
    static <E> ImmutableSet<E>
    of(E v1, E v2)
    Return an ImmutableSet with 2 entries, backed by a LinkedHashSet.
    static <E> ImmutableSet<E>
    of(E v1, E v2, E v3)
    Return an ImmutableSet with 3 entries, backed by a LinkedHashSet.
    static <E> ImmutableSet<E>
    of(E v1, E v2, E v3, E v4)
    Return an ImmutableSet with 4 entries, backed by a LinkedHashSet.
    static <E> ImmutableSet<E>
    of(E v1, E v2, E v3, E v4, E v5, E... vn)
    Return an ImmutableSet with 5 or more entries, backed by a LinkedHashSet.
    Returns a modifiable copy of this immutable set.
    Force to redefine toString.

    Methods inherited from interface org.djutils.immutablecollections.ImmutableCollection

    contains, containsAll, containsAll, isCopy, isEmpty, isWrap, iterator, parallelStream, size, spliterator, stream, toArray, toArray, toCollection

    Methods inherited from interface java.lang.Iterable

    forEach
  • Method Details

    • toSet

      Set<E> toSet()
      Returns a modifiable copy of this immutable set.
      Returns:
      a modifiable copy of this immutable set.
    • equals

      boolean equals(Object obj)
      Force to redefine equals for the implementations of immutable collection classes.
      Specified by:
      equals in interface ImmutableCollection<E>
      Overrides:
      equals in class Object
      Parameters:
      obj - Object; the object to compare this collection with
      Returns:
      whether the objects are equal
    • hashCode

      int hashCode()
      Force to redefine hashCode for the implementations of immutable collection classes.
      Specified by:
      hashCode in interface ImmutableCollection<E>
      Overrides:
      hashCode in class Object
      Returns:
      the calculated hashCode
    • toString

      String toString()
      Force to redefine toString.
      Overrides:
      toString in class Object
      Returns:
      String; a description of this immutable set
    • of

      static <E> ImmutableSet<E> of()
      Return an empty ImmutableSet, backed by a LinkedHashSet.
      Type Parameters:
      E - the value type
      Returns:
      ImmutableSet<K, V>; an empty ImmutableSet
    • of

      static <E> ImmutableSet<E> of(E v1)
      Return an ImmutableSet with 1 entry, backed by a LinkedHashSet.
      Type Parameters:
      E - the value type
      Parameters:
      v1 - E; value 1
      Returns:
      ImmutableSet<K, V>; an ImmutableSet with 1 entry, backed by a LinkedHashSet
    • of

      static <E> ImmutableSet<E> of(E v1, E v2)
      Return an ImmutableSet with 2 entries, backed by a LinkedHashSet.
      Type Parameters:
      E - the value type
      Parameters:
      v1 - E; value 1
      v2 - E; value 2
      Returns:
      ImmutableSet<K, V>; an ImmutableSet with 2 entries, backed by a LinkedHashSet
    • of

      static <E> ImmutableSet<E> of(E v1, E v2, E v3)
      Return an ImmutableSet with 3 entries, backed by a LinkedHashSet.
      Type Parameters:
      E - the value type
      Parameters:
      v1 - E; value 1
      v2 - E; value 2
      v3 - E; value 3
      Returns:
      ImmutableSet<K, V>; an ImmutableSet with 3 entries, backed by a LinkedHashSet
    • of

      static <E> ImmutableSet<E> of(E v1, E v2, E v3, E v4)
      Return an ImmutableSet with 4 entries, backed by a LinkedHashSet.
      Type Parameters:
      E - the value type
      Parameters:
      v1 - E; value 1
      v2 - E; value 2
      v3 - E; value 3
      v4 - E; value 4
      Returns:
      ImmutableSet<K, V>; an ImmutableSet with 4 entries, backed by a LinkedHashSet
    • of

      static <E> ImmutableSet<E> of(E v1, E v2, E v3, E v4, E v5, E... vn)
      Return an ImmutableSet with 5 or more entries, backed by a LinkedHashSet.
      Type Parameters:
      E - the value type
      Parameters:
      v1 - E; value 1
      v2 - E; value 2
      v3 - E; value 3
      v4 - E; value 4
      v5 - E; value 5
      vn - E...; values 6 and beyond
      Returns:
      ImmutableSet<K, V>; an ImmutableSet with 5 or more entries, backed by a LinkedHashSet