Top Description Inners Fields Constructors Methods
com.google.common.collect

public abstract Class ImmutableSet<E>

extends ImmutableCollection<E>
implements Set<E>
Class Inheritance
All Implemented Interfaces
java.util.Set, java.util.Collection, java.lang.Iterable
Known Direct Subclasses
com.google.common.collect.ImmutableSet.CachingAsList, com.google.common.collect.ImmutableSetMultimap.EntrySet, com.google.common.collect.SingletonImmutableSet, com.google.common.collect.ImmutableEnumSet
Annotations
@GwtCompatible
serializable:true
emulated:true
@SuppressWarnings:serial
@ElementTypesAreNonnullByDefault
Static Imports
com.google.common.base.Preconditions.checkArgument, .Preconditions.checkNotNull, com.google.common.collect.CollectPreconditions.checkNonnegative, java.util.Objects.requireNonNull

A Set whose contents will never change, with many other important properties detailed at ImmutableCollection.
Since
2.0

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static class
ImmutableSet.Builder<E>

A builder for creating ImmutableSet instances.

pack-priv abstract static class
private static class
pack-priv abstract static class
private static class
ImmutableSet.JdkBackedSetBuilderImpl<E>

SetBuilderImpl version that uses a JDK HashSet, which has built in hash flooding protection.

private static class
ImmutableSet.RegularSetBuilderImpl<E>

Default implementation of the guts of ImmutableSet.Builder, creating an open-addressed hash table and deduplicating elements as they come, so it only allocates O(max(distinct, expectedCapacity)) rather than O(calls to add).

private static class
private abstract static class
ImmutableSet.SetBuilderImpl<E>

Swappable internal implementation of an ImmutableSet.Builder.

Field Summary

Modifier and TypeField and Description
private static final int
private static final double
pack-priv static final int
private static final long
pack-priv static final int

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
public static <E> ImmutableSet.Builder<E>
builder()

Returns a new builder.

public static <E> ImmutableSet.Builder<E>
builderWithExpectedSize(int expectedSize)

Returns a new builder, expecting the specified number of distinct elements to be added.

pack-priv static int
chooseTableSize(int setSize)

Returns an array size suitable for the backing array of a hash table that uses open addressing with linear probing in its implementation.

public static <E> ImmutableSet<E>
copyOf(Collection<? extends E>
a Collection from which elements are drawn, must be non-null
elements
)

Hides java.util.Set.copyOf.

Returns an immutable set containing each of elements, minus duplicates, in the order each appears first in the source collection.
public static <E> ImmutableSet<E>
copyOf(Iterable<? extends E> elements)

Returns an immutable set containing each of elements, minus duplicates, in the order each appears first in the source iterable.

public static <E> ImmutableSet<E>
copyOf(Iterator<? extends E> elements)

Returns an immutable set containing each of elements, minus duplicates, in the order each appears first in the source iterator.

public static <E> ImmutableSet<E>
copyOf(E[] elements)

Returns an immutable set containing each of elements, minus duplicates, in the order each appears first in the source array.

private static ImmutableSet<E>
copyOfEnumSet(EnumSet<?> enumSet)

public boolean
equals(Object
object to be compared for equality with this set
object
)

Overrides java.lang.Object.equals.

Implements java.util.Set.equals, java.util.Collection.equals.

Compares the specified object with this set for equality.
private static int
estimatedSizeForUnknownDuplication(int inputElementsIncludingAnyDuplicates)

private static <E> ImmutableSet<E>
fromArrayWithExpectedSize(E[] elements, int expectedSize)

public int
hashCode()

Overrides java.lang.Object.hashCode.

Implements java.util.Set.hashCode, java.util.Collection.hashCode.

Returns the hash code value for this set.
pack-priv boolean
isHashCodeFast()

Returns true if the hashCode() method runs quickly.

public abstract UnmodifiableIterator<E>
iterator()

Redeclares java.util.Set.iterator, java.util.Collection.iterator.

Implements abstract com.google.common.collect.ImmutableCollection.iterator.

Returns an iterator over the elements in this set.
public static <E> ImmutableSet<E>
of()

Hides java.util.Set.of.

Returns the empty immutable set.
public static <E> ImmutableSet<E>
of(E
the single element
element
)

Hides java.util.Set.of.

Returns an immutable set containing element.
public static <E> ImmutableSet<E>
of(E
the first element
e1
,
E
the second element
e2
)

Hides java.util.Set.of.

Returns an immutable set containing the given elements, minus duplicates, in the order each was first specified.
public static <E> ImmutableSet<E>
of(E
the first element
e1
,
E
the second element
e2
,
E
the third element
e3
)

Hides java.util.Set.of.

Returns an immutable set containing the given elements, minus duplicates, in the order each was first specified.
public static <E> ImmutableSet<E>
of(E
the first element
e1
,
E
the second element
e2
,
E
the third element
e3
,
E
the fourth element
e4
)

Hides java.util.Set.of.

Returns an immutable set containing the given elements, minus duplicates, in the order each was first specified.
public static <E> ImmutableSet<E>
of(E
the first element
e1
,
E
the second element
e2
,
E
the third element
e3
,
E
the fourth element
e4
,
E
the fifth element
e5
)

Hides java.util.Set.of.

Returns an immutable set containing the given elements, minus duplicates, in the order each was first specified.
public static <E> ImmutableSet<E>
of(E
the first element
e1
,
E
the second element
e2
,
E
the third element
e3
,
E
the fourth element
e4
,
E
the fifth element
e5
,
E
the sixth element
e6
,
E...
the seventh element
others
)

Hides java.util.Set.of.

Returns an immutable set containing the given elements, minus duplicates, in the order each was first specified.
private void
public static <E> Collector<E, ?, ImmutableSet<E>>
toImmutableSet()

Returns a Collector that accumulates the input elements into a new ImmutableSet.

pack-priv Object
Inherited from com.google.common.collect.ImmutableCollection:
addaddAllasListclearcontainscopyIntoArrayinternalArrayinternalArrayEndinternalArrayStartisPartialViewremoveremoveAllremoveIfretainAllspliteratortoArraytoArray