Interface ImmutableSet<A>

  • Type Parameters:
    A - the element type
    All Superinterfaces:
    software.kes.enhancediterables.EnhancedIterable<A>, software.kes.enhancediterables.FiniteIterable<A>, com.jnape.palatable.lambda.functor.Functor<A,​software.kes.enhancediterables.EnhancedIterable<?>>, Immutable, software.kes.enhancediterables.ImmutableFiniteIterable<A>, software.kes.enhancediterables.ImmutableIterable<A>, java.lang.Iterable<A>, Set<A>
    All Known Subinterfaces:
    ImmutableNonEmptySet<A>

    public interface ImmutableSet<A>
    extends Set<A>, software.kes.enhancediterables.ImmutableFiniteIterable<A>, Immutable
    A Set that is guaranteed at compile-time to be safe from mutation anywhere. In other words, it owns the sole reference to the underlying collection.

    In addition to guarantees of Set, an ImmutableSet provides the following benefits:

    • Method Summary

      All Methods Static Methods Instance Methods Default Methods 
      Modifier and Type Method Description
      default ImmutableSet<A> distinct()
      Since an ImmutableSet already contains only distinct values, this method always returns itself.
      static <A> ImmutableNonEmptySet<A> of​(A first, A... more)
      Creates a ImmutableNonEmptySet with the given elements.
      default ImmutableSet<A> toImmutable()
      Returns an ImmutableSet containing the same elements as this one.
      default com.jnape.palatable.lambda.adt.Maybe<? extends ImmutableNonEmptySet<A>> toNonEmpty()
      Attempts to convert this ImmutableSet to an ImmutableNonEmptySet.
      default ImmutableNonEmptySet<A> toNonEmptyOrThrow()
      Attempts to convert this ImmutableSet to an ImmutableNonEmptySet.
      • Methods inherited from interface software.kes.enhancediterables.EnhancedIterable

        concat, concat, toArray, toCollection, zipWith, zipWith
      • Methods inherited from interface software.kes.enhancediterables.FiniteIterable

        append, concat, concat, concat, cross, cross, drop, dropWhile, filter, fmap, foldLeft, foldRight, intersperse, magnetizeBy, partition, prepend, prependAll, slide, span, tails, takeWhile, toFinite, zipWith
      • Methods inherited from interface com.jnape.palatable.lambda.functor.Functor

        coerce
      • Methods inherited from interface software.kes.enhancediterables.ImmutableFiniteIterable

        append, concat, concat, cross, cycle, drop, dropWhile, filter, fmap, inits, intersperse, magnetizeBy, partition, prepend, prependAll, reverse, slide, span, tails, takeWhile, toFinite, zipWith
      • Methods inherited from interface software.kes.enhancediterables.ImmutableIterable

        concat, concat, take, zipWith
      • Methods inherited from interface java.lang.Iterable

        forEach, iterator, spliterator
    • Method Detail

      • distinct

        default ImmutableSet<A> distinct()
        Since an ImmutableSet already contains only distinct values, this method always returns itself.
        Specified by:
        distinct in interface software.kes.enhancediterables.FiniteIterable<A>
        Specified by:
        distinct in interface software.kes.enhancediterables.ImmutableFiniteIterable<A>
        Specified by:
        distinct in interface Set<A>
        Returns:
        itself
      • toImmutable

        default ImmutableSet<A> toImmutable()
        Returns an ImmutableSet containing the same elements as this one.

        Since this is an ImmutableSet already, this method simply returns itself.

        Specified by:
        toImmutable in interface Set<A>
        Returns:
        itself
      • toNonEmpty

        default com.jnape.palatable.lambda.adt.Maybe<? extends ImmutableNonEmptySet<A>> toNonEmpty()
        Attempts to convert this ImmutableSet to an ImmutableNonEmptySet.

        If successful, returns a ImmutableNonEmptySet containing the same elements as this one, wrapped in a Maybe.just(A).

        If this ImmutableSet is empty, returns Maybe.nothing().

        Does not make copies of any underlying data structures.

        Specified by:
        toNonEmpty in interface software.kes.enhancediterables.EnhancedIterable<A>
        Specified by:
        toNonEmpty in interface software.kes.enhancediterables.FiniteIterable<A>
        Specified by:
        toNonEmpty in interface software.kes.enhancediterables.ImmutableFiniteIterable<A>
        Specified by:
        toNonEmpty in interface software.kes.enhancediterables.ImmutableIterable<A>
        Specified by:
        toNonEmpty in interface Set<A>
        Returns:
        a Maybe<ImmutableNonEmptySet<A>>
      • toNonEmptyOrThrow

        default ImmutableNonEmptySet<A> toNonEmptyOrThrow()
        Attempts to convert this ImmutableSet to an ImmutableNonEmptySet.

        If successful, returns a ImmutableNonEmptySet containing the same elements as this one. Use this if you are confident that this ImmutableSet is not empty.

        If this ImmutableSet is empty, throws an IllegalArgumentException.

        Does not make copies of any underlying data structures.

        Specified by:
        toNonEmptyOrThrow in interface Set<A>
        Returns:
        an ImmutableNonEmptySet<A>
        Throws:
        java.lang.IllegalArgumentException - if this ImmutableSet is empty
      • of

        @SafeVarargs
        static <A> ImmutableNonEmptySet<A> of​(A first,
                                              A... more)
        Creates a ImmutableNonEmptySet with the given elements.
        Type Parameters:
        A - the element type
        Parameters:
        first - the first element
        more - the remaining elements
        Returns:
        an ImmutableNonEmptySet<A>