- Type Parameters:
E- type of the elements in this set
- All Implemented Interfaces:
BaseCollection<E>,Joinable,MutableCollection<E>,br.com.objectos.core.object.ToStringObject,Iterable<E>,Collection<E>,Set<E>
Set and MutableCollection
interfaces.- Since:
- 2
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionfinal booleanAdds the specified element to this set if it is not already present.final booleanaddAll(Collection<? extends E> c) Adds all of the elements in the specified collection to this set if they are not already present.final booleanaddAllIterable(Iterable<? extends E> iterable) Adds all of the elements returned by the specified iterable's iterator to this set if they are not already present.final booleanaddWithNullMessage(E e, Object nullMessage) Adds the specified elementeto this set if it is not already present.final booleanaddWithNullMessage(E e, Object nullMessageStart, int index, Object nullMessageEnd) Adds the specified elementeto this set if it is not already present.final voidclear()Removes all of the elements from this set.final booleanReturnstrueif this set contains the specified element.final booleanfinal booleancontainsAll(Collection<?> arg0) static <E> MutableSet<E>create()Creates and returns a newMutableSetinstance.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()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 ImmutableSet<E>Returns anImmutableSetcopy of this set.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
-
Constructor Details
-
MutableSet
public MutableSet()Creates a newMutableSetinstance.
-
-
Method Details
-
create
Creates and returns a newMutableSetinstance.This method is mainly provided as a convenience for Java Multi-Release codebases. In particular codebases that must support versions prior to Java 7 and, therefore, cannot use the diamond operator.
- Type Parameters:
E- type of the elements in this set- Returns:
- a new
MutableSetinstance
-
add
Adds the specified element to this set if it is not already present.- Specified by:
addin interfaceBaseCollection<E>- Specified by:
addin interfaceCollection<E>- Specified by:
addin interfaceSet<E>- Parameters:
e- an element to be added to this set- Returns:
trueif this set was modified as a result of this operation.falseif the element was already present in this set- Throws:
NullPointerException- if the specified element isnull
-
addAll
Adds all of the elements in the specified collection to this set if they are not already present.The behavior of this operation is undefined if the specified collection is modified while the operation is in progress. (This implies that the behavior of this call is undefined if the specified collection is this set, and this set is nonempty.)
- Specified by:
addAllin interfaceBaseCollection<E>- Specified by:
addAllin interfaceCollection<E>- Specified by:
addAllin interfaceSet<E>- Parameters:
c- a collection containing the elements to be added to this set- Returns:
trueif this set was modified as a result of this operation.falseif all of the elements were already present in this set- Throws:
NullPointerException- if the specified collection isnullor if it contains any element that isnull
-
addAllIterable
Adds all of the elements returned by the specified iterable's iterator to this set if they are not already present.The behavior of this operation is undefined if the specified iterable is modified while the operation is in progress. (This implies that the behavior of this call is undefined if the specified iterable is this list, and this list is nonempty.)
- Specified by:
addAllIterablein interfaceMutableCollection<E>- Parameters:
iterable-Iterablecontaining elements to be added to this set- Returns:
trueif this set was modified as a result of this operation.falseif all of the elements were already present in this set- Throws:
NullPointerException- if the specified iterable isnullor if it provides any element that isnull
-
addWithNullMessage
Adds the specified elementeto this set if it is not already present.If a
NullPointerExceptionis to be thrown, thenullMessagevalue is used as the exception's message.Typical usage:
set.addWithNullMessage(value, "value == null");
- Specified by:
addWithNullMessagein interfaceMutableCollection<E>- Parameters:
e- an element to be added to this set (if it not null)nullMessage- theNullPointerExceptionmessage- Returns:
trueif this set was modified as a result of this operation.falseif the element was already present in this set- Throws:
NullPointerException- if the specified element isnull- See Also:
-
Checks.checkNotNull(Object, Object)
-
addWithNullMessage
public final boolean addWithNullMessage(E e, Object nullMessageStart, int index, Object nullMessageEnd) Adds the specified elementeto this set if it is not already present.If a
NullPointerExceptionis to be thrown, the concatenation ofnullMessageStart,indexandnullMessageEndis used as the exception's message.Typical usage:
set.addWithNullMessage(element, "elements[", index, "] == null");
- Specified by:
addWithNullMessagein interfaceMutableCollection<E>- Parameters:
e- an element to be added to this set (if it not null)nullMessageStart- the first part of theNullPointerExceptionmessageindex- the second part of theNullPointerExceptionmessagenullMessageEnd- the third part of theNullPointerExceptionmessage- Returns:
trueif this set was modified as a result of this operation.falseif the element was already present in this set- See Also:
-
Checks.checkNotNull(Object, Object, int, Object)
-
clear
public final void clear()Removes all of the elements from this set. -
toImmutableSet
Returns anImmutableSetcopy of this set.The returned
ImmutableSetwill contain all of the elements from this set.The returned set will be a copy in the sense that, after this method returns, modifying this set will have no effect on the returned (copied) one.
Note, however, that the behaviour of this method is undefined if this set is modified while the copy is being made.
- Returns:
- an
ImmutableSetcopy of this set
-
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()
-