Class ImmutableSet<E>
- Type Parameters:
E- type of the elements in this set
- All Implemented Interfaces:
BaseCollection<E>,ImmutableCollection<E>,Joinable,br.com.objectos.core.object.ToStringObject,Iterable<E>,Collection<E>,Set<E>
Set and
ImmutableCollection interfaces.
After creation, instances of this class do not permit adding nor removing of
elements. Any mutator method will throw an
UnsupportedOperationException when called. This is true for mutator
methods present in this class and for mutator methods present in the returned
iterators.
- Since:
- 2
-
Method Summary
Modifier and TypeMethodDescriptionfinal booleanThis operation is not supported.final booleanaddAll(Collection<? extends E> c) This operation is not supported.final voidclear()This operation is not supported.final booleanReturnstrueif this set contains the specified element.final booleanfinal booleancontainsAll(Collection<?> arg0) static <E> ImmutableSet<E>copyOf(E[] array) Returns a newImmutableSetcontaining all of the distinct elements in the specified array.static <E> ImmutableSet<E>Returns the specified iterable if it is anImmutableSet; returns a newImmutableSetcontaining all of the distinct elements returned by the specified iterable's iterator.static <E> ImmutableSet<E>Returns a newImmutableSetinstance containing all of the distinct elements returned by the specified iterator.final booleanCompares the specified object with this set for equality.voidformatToString(StringBuilder arg0, int arg1) final EgetOnly()protected final EReturns the only element in this set.protected final StringindexName(int arg0, int arg1) final booleanisEmpty()final UnmodifiableIterator<E>iterator()Returns an iterator over the elements in this set.join()static <E> ImmutableSet<E>of()Returns the emptyImmutableSet.static <E> ImmutableSet<E>of(E element) Returns a newImmutableSetcontaining one element.static <E> ImmutableSet<E>of(E first, E... more) Returns a newImmutableSetcontaining all of the distinct specified elements.final booleanfinal booleanremoveAll(Collection<?> arg0) final booleanfinal booleanretainAll(Collection<?> arg0) final intsize()Returns the size of this set.protected final intObject[]toArray()<T extends Object>
T[]toArray(T[] arg0) final StringtoString()Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface br.com.objectos.collections.base.BaseCollection
contains, getOnly, iterator, remove, removeAll, removeIf, retainAllMethods inherited from interface java.util.Collection
parallelStream, stream, toArrayMethods inherited from interface java.util.Set
containsAll, hashCode, isEmpty, remove, removeAll, retainAll, spliterator, toArray, toArrayMethods inherited from interface br.com.objectos.core.object.ToStringObject
formatToString
-
Method Details
-
copyOf
Returns a newImmutableSetcontaining all of the distinct elements in the specified array.Two non-null elements
e1ande2are distinct if the expressione1.equals(e2)evaluates tofalse.This method returns a copy in the sense that modifications in the specified array are not propagated to the returned set.
- Type Parameters:
E- type of the elements in this set- Parameters:
array- an array for which an immutable set copy will be created- Returns:
- a new
ImmutableSetcontaining all of the distinct elements in the specified array - Throws:
NullPointerException- if the array isnullor any element in the array isnull
-
copyOf
Returns the specified iterable if it is anImmutableSet; returns a newImmutableSetcontaining all of the distinct elements returned by the specified iterable's iterator.Two non-null elements
e1ande2are distinct if the expressione1.equals(e2)evaluates tofalse.- Type Parameters:
E- type of the elements in this set- Parameters:
elements- anIterablefor which an immutable set copy will be created- Returns:
- the specified iterable if it is an
ImmutableSetor a newImmutableSetcontaining all of the elements returned by the specified iterable's iterator - Throws:
NullPointerException- if the iterable isnullor if any element returned by the iterable's iterator isnull
-
copyOf
Returns a newImmutableSetinstance containing all of the distinct elements returned by the specified iterator.Two non-null elements
e1ande2are distinct if the expressione1.equals(e2)evaluates tofalse.- Type Parameters:
E- type of the elements in this set- Parameters:
iterator- anIteratorfor which an immutable set copy will be created- Returns:
- a new
ImmutableSetinstance containing all of the distinct elements produced by the specified iterator - Throws:
NullPointerException- if the iterator isnullor any element produced by the iterator isnull
-
of
Returns the emptyImmutableSet.- Type Parameters:
E- type of the elements in this set- Returns:
- the empty
ImmutableSet
-
of
Returns a newImmutableSetcontaining one element.- Type Parameters:
E- type of the elements in this set- Parameters:
element- the single element- Returns:
- a new
ImmutableSetcontaining one element - Throws:
NullPointerException- if the specified element isnull
-
of
Returns a newImmutableSetcontaining all of the distinct specified elements.Two non-null elements
e1ande2are distinct if the expressione1.equals(e2)evaluates tofalse.- Type Parameters:
E- type of the elements in this set- Parameters:
first- the first elementmore- the additional elements- Returns:
- a new
ImmutableSetcontaining all of the distinct specified elements - Throws:
NullPointerException- if any of the specified elements isnull
-
add
This operation is not supported.This method performs no operation other than throw an
UnsupportedOperationException.- Specified by:
addin interfaceBaseCollection<E>- Specified by:
addin interfaceCollection<E>- Specified by:
addin interfaceImmutableCollection<E>- Specified by:
addin interfaceSet<E>- Parameters:
e- ignored (the operation is not supported)- Returns:
- this method does not return as it always throw an exception
- Throws:
UnsupportedOperationException- always
-
addAll
This operation is not supported.This method performs no operation other than throw an
UnsupportedOperationException.- Specified by:
addAllin interfaceBaseCollection<E>- Specified by:
addAllin interfaceCollection<E>- Specified by:
addAllin interfaceImmutableCollection<E>- Specified by:
addAllin interfaceSet<E>- Parameters:
c- ignored (the operation is not supported)- Returns:
- this method does not return as it always throw an exception
- Throws:
UnsupportedOperationException- always
-
clear
public final void clear()This operation is not supported.This method performs no operation other than throw an
UnsupportedOperationException.- Specified by:
clearin interfaceCollection<E>- Specified by:
clearin interfaceImmutableCollection<E>- Specified by:
clearin interfaceSet<E>- Throws:
UnsupportedOperationException- always
-
contains
Returnstrueif this set contains the specified element. More formally, returnstrueif and only if this set contains at least one elementesuch thate.equals(o).- Specified by:
containsin interfaceCollection<E>- Specified by:
containsin interfaceSet<E>- Parameters:
o- an element to check for presence in this set- Returns:
trueif this set contains the specified value
-
equals
Compares the specified object with this set for equality. Returns
trueif and only if- the specified object is also a
Set; - both sets have same size; and
- each element in this set is also present in the specified set.
- the specified object is also a
-
iterator
Returns an iterator over the elements in this set. The elements are returned in no particular order.- Specified by:
iteratorin interfaceBaseCollection<E>- Specified by:
iteratorin interfaceCollection<E>- Specified by:
iteratorin interfaceIterable<E>- Specified by:
iteratorin interfaceSet<E>- Returns:
- an iterator over the elements in this set
-
size
public final int size()Returns the size of this set. The size of a set is equal to the number of elements it contains.- Specified by:
sizein interfaceCollection<E>- Specified by:
sizein interfaceSet<E>- Returns:
- the size of this set
-
getOnlyImpl
Returns the only element in this set.- Returns:
- the only element in this set
-
removeIf
-
contains
- Specified by:
containsin interfaceBaseCollection<E extends Object>
-
containsAll
- Specified by:
containsAllin interfaceCollection<E extends Object>
-
formatToString
- Specified by:
formatToStringin interfacebr.com.objectos.core.object.ToStringObject
-
getOnly
- Specified by:
getOnlyin interfaceBaseCollection<E extends Object>
-
isEmpty
public final boolean isEmpty()- Specified by:
isEmptyin interfaceCollection<E extends Object>
-
join
-
join
-
join
-
remove
- Specified by:
removein interfaceBaseCollection<E extends Object>- Specified by:
removein interfaceCollection<E extends Object>
-
removeAll
- Specified by:
removeAllin interfaceBaseCollection<E extends Object>- Specified by:
removeAllin interfaceCollection<E extends Object>
-
retainAll
- Specified by:
retainAllin interfaceBaseCollection<E extends Object>- Specified by:
retainAllin interfaceCollection<E extends Object>
-
toArray
- Specified by:
toArrayin interfaceCollection<E extends Object>
-
toArray
- Specified by:
toArrayin interfaceCollection<E extends Object>
-
toString
-
indexName
-
sizeDigits
protected final int sizeDigits()
-