Class UnifiedSet<T>
- java.lang.Object
-
- org.eclipse.collections.impl.AbstractRichIterable<T>
-
- org.eclipse.collections.impl.collection.mutable.AbstractMutableCollection<T>
-
- org.eclipse.collections.impl.set.AbstractUnifiedSet<T>
-
- org.eclipse.collections.impl.set.mutable.UnifiedSet<T>
-
- All Implemented Interfaces:
java.io.Externalizable,java.io.Serializable,java.lang.Cloneable,java.lang.Iterable<T>,java.util.Collection<T>,java.util.Set<T>,MutableCollection<T>,InternalIterable<T>,RichIterable<T>,MutableSet<T>,MutableSetIterable<T>,Pool<T>,SetIterable<T>,UnsortedSetIterable<T>,BatchIterable<T>
public class UnifiedSet<T> extends AbstractUnifiedSet<T> implements java.io.Externalizable
- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static classUnifiedSet.ChainedBucketprotected classUnifiedSet.PositionalIteratorprivate classUnifiedSet.UnifiedSetParallelUnsortedIterableprivate classUnifiedSet.UnifiedUnsortedSetBatch
-
Field Summary
Fields Modifier and Type Field Description protected static java.lang.ObjectNULL_KEYprotected intoccupiedprivate static longserialVersionUIDprotected java.lang.Object[]table-
Fields inherited from class org.eclipse.collections.impl.set.AbstractUnifiedSet
DEFAULT_INITIAL_CAPACITY, DEFAULT_LOAD_FACTOR, loadFactor, maxSize
-
-
Constructor Summary
Constructors Constructor Description UnifiedSet()UnifiedSet(int initialCapacity)UnifiedSet(int initialCapacity, float loadFactor)UnifiedSet(java.util.Collection<? extends T> collection)UnifiedSet(UnifiedSet<T> set)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanadd(T key)booleanaddAllIterable(java.lang.Iterable<? extends T> iterable)private voidaddForTrim(java.lang.Object key, int oldIndex, int mask)private voidaddIfFound(T key, UnifiedSet<T> other)private voidaddIfFoundFromChain(UnifiedSet.ChainedBucket bucket, T key, UnifiedSet<T> other)protected voidallocateTable(int sizeToAllocate)ParallelUnsortedSetIterable<T>asParallel(java.util.concurrent.ExecutorService executorService, int batchSize)Returns a parallel iterable of this SetIterable.voidbatchForEach(Procedure<? super T> procedure, int sectionIndex, int sectionCount)private booleanchainContains(UnifiedSet.ChainedBucket bucket, T key)private booleanchainedAdd(T key, int index)private voidchainedAddForTrim(java.lang.Object key, int index)private java.lang.ObjectchainedDetect(UnifiedSet.ChainedBucket bucket, Predicate<? super T> predicate)private voidchainedForEach(UnifiedSet.ChainedBucket bucket, Procedure<? super T> procedure)private <P> voidchainedForEachWith(UnifiedSet.ChainedBucket bucket, Procedure2<? super T,? super P> procedure, P parameter)private intchainedForEachWithIndex(UnifiedSet.ChainedBucket bucket, ObjectIntProcedure<? super T> procedure, int count)private TchainedGet(T key, UnifiedSet.ChainedBucket bucket)private intchainedHashCode(UnifiedSet.ChainedBucket bucket)private TchainedPut(T key, int index)private booleanchainedShortCircuit(UnifiedSet.ChainedBucket bucket, Predicate<? super T> predicate, boolean expected)private <P> booleanchainedShortCircuitWith(UnifiedSet.ChainedBucket bucket, Predicate2<? super T,? super P> predicate, P parameter, boolean expected)private voidchainedTrimToSize(UnifiedSet.ChainedBucket bucket, int oldIndex, int mask)voidclear()UnifiedSet<T>clone()booleancontains(java.lang.Object key)Returns true if the iterable has an element which responds true to element.equals(object).private intcopyBucketToArray(java.lang.Object[] result, UnifiedSet.ChainedBucket bucket, int count)private booleancopyChain(UnifiedSet.ChainedBucket bucket)protected booleancopySet(UnifiedSet<?> unifiedset)private voidcopyToArray(java.lang.Object[] result)protected Tdetect(Predicate<? super T> predicate, int start, int end)protected java.util.Optional<T>detectOptional(Predicate<? super T> predicate, int start, int end)voideach(Procedure<? super T> procedure)The procedure is executed for each element in the iterable.protected voideach(Procedure<? super T> procedure, int start, int end)private voidensureCapacity(int size)booleanequals(java.lang.Object object)Follows the same general contract asSet.equals(Object).private intfastCeil(float v)<P> voidforEachWith(Procedure2<? super T,? super P> procedure, P parameter)The procedure2 is evaluated for each element in the iterable with the specified parameter provided as the second argument.voidforEachWithIndex(ObjectIntProcedure<? super T> objectIntProcedure)Iterates over the iterable passing each element and the current relative int index to the specified instance of ObjectIntProcedure.Tget(T key)Locates an object in the pool which is equal tokey.TgetFirst()Returns the first element of an iterable.TgetLast()Returns the last element of an iterable.private TgetLast(UnifiedSet.ChainedBucket bucket)protected java.lang.Object[]getTable()<V> UnifiedSetMultimap<V,T>groupBy(Function<? super T,? extends V> function)For each element of the iterable, the function is evaluated and the results of these evaluations are collected into a new multimap, where the transformed value is the key and the original values are added to the same (or similar) species of collection as the source iterable.<V> UnifiedSetMultimap<V,T>groupByEach(Function<? super T,? extends java.lang.Iterable<V>> function)Similar toRichIterable.groupBy(Function), except the result of evaluating function will return a collection of keys for each value.inthashCode()Follows the same general contract asSet.hashCode().protected intindex(java.lang.Object key)java.util.Iterator<T>iterator()UnifiedSet<T>newEmpty()Creates a new empty mutable version of the same collection type.UnifiedSet<T>newEmpty(int size)static <K> UnifiedSet<K>newSet()static <K> UnifiedSet<K>newSet(int size)static <K> UnifiedSet<K>newSet(int size, float loadFactor)static <K> UnifiedSet<K>newSet(java.lang.Iterable<? extends K> source)static <K> UnifiedSet<K>newSetWith(K... elements)private booleannonNullTableObjectEquals(java.lang.Object cur, T key)private TnonSentinel(java.lang.Object key)PartitionMutableSet<T>partition(Predicate<? super T> predicate)Filters a collection into a PartitionedIterable based on the evaluation of the predicate.<P> PartitionMutableSet<T>partitionWith(Predicate2<? super T,? super P> predicate, P parameter)Filters a collection into a PartitionIterable based on the evaluation of the predicate.Tput(T key)Putskeyinto the pool.voidreadExternal(java.io.ObjectInput in)protected voidrehash(int newCapacity)UnifiedSet<T>reject(Predicate<? super T> predicate)Returns all elements of the source collection that return false when evaluating of the predicate.<P> UnifiedSet<T>rejectWith(Predicate2<? super T,? super P> predicate, P parameter)Similar toRichIterable.reject(Predicate), except with an evaluation parameter for the second generic argument inPredicate2.booleanremove(java.lang.Object key)private booleanremoveDeepChain(UnifiedSet.ChainedBucket oldBucket, T key)private TremoveDeepChainForPool(UnifiedSet.ChainedBucket oldBucket, T key)private booleanremoveFromChain(UnifiedSet.ChainedBucket bucket, T key, int index)private TremoveFromChainForPool(UnifiedSet.ChainedBucket bucket, T key, int index)TremoveFromPool(T key)Locates an object in the pool which is equal tokeyand removes it.private booleanretainAllFromNonSet(java.lang.Iterable<?> iterable)private booleanretainAllFromSet(java.util.Set<?> collection)booleanretainAllIterable(java.lang.Iterable<?> iterable)UnifiedSet<T>select(Predicate<? super T> predicate)Returns all elements of the source collection that return true when evaluating the predicate.<P> Twin<MutableList<T>>selectAndRejectWith(Predicate2<? super T,? super P> predicate, P parameter)Filters a collection into two separate collections based on a predicate returned via a Pair.<S> UnifiedSet<S>selectInstancesOf(java.lang.Class<S> clazz)Returns all elements of the source collection that are instances of the Classclazz.<P> UnifiedSet<T>selectWith(Predicate2<? super T,? super P> predicate, P parameter)Similar toRichIterable.select(Predicate), except with an evaluation parameter for the second generic argument inPredicate2.protected booleanshortCircuit(Predicate<? super T> predicate, boolean expected, boolean onShortCircuit, boolean atEnd, int start, int end)protected <P> booleanshortCircuitWith(Predicate2<? super T,? super P> predicate2, P parameter, boolean expected, boolean onShortCircuit, boolean atEnd)intsize()Returns the number of items in this iterable.MutableSet<T>tap(Procedure<? super T> procedure)Executes the Procedure for each element in the iterable and returnsthis.java.lang.Object[]toArray()Converts this iterable to an array.<T> T[]toArray(T[] array)Converts this iterable to an array using the specified target array, assuming the target array is as long or longer than the iterable.ImmutableSet<T>toImmutable()Returns an immutable copy of this set.private static java.lang.ObjecttoSentinelIfNull(java.lang.Object key)booleantrimToSize()UnifiedSet<T>with(T element)This method allows mutable and fixed size collections the ability to add elements to their existing elements.UnifiedSet<T>with(T... elements)UnifiedSet<T>with(T element1, T element2)UnifiedSet<T>with(T element1, T element2, T element3)UnifiedSet<T>withAll(java.lang.Iterable<? extends T> iterable)This method allows mutable and fixed size collections the ability to add multiple elements to their existing elements.UnifiedSet<T>without(T element)This method allows mutable and fixed size collections the ability to remove elements from their existing elements.UnifiedSet<T>withoutAll(java.lang.Iterable<? extends T> elements)This method allows mutable and fixed size collections the ability to remove multiple elements from their existing elements.voidwriteExternal(java.io.ObjectOutput out)private voidwriteExternalChain(java.io.ObjectOutput out, UnifiedSet.ChainedBucket bucket)-
Methods inherited from class org.eclipse.collections.impl.set.AbstractUnifiedSet
allocate, allSatisfy, allSatisfyWith, anySatisfy, anySatisfyWith, asSynchronized, asUnmodifiable, cartesianProduct, chunk, collect, collectIf, collectWith, computeMaxSize, detect, detectOptional, difference, differenceInto, flatCollect, getBatchCount, groupByUniqueKey, init, injectIntoWith, intersect, intersectInto, isProperSubsetOf, isSubsetOf, noneSatisfy, noneSatisfyWith, powerSet, rehash, removeAllIterable, retainAll, shortCircuit, symmetricDifference, symmetricDifferenceInto, union, unionInto, zip, zipWithIndex
-
Methods inherited from class org.eclipse.collections.impl.collection.mutable.AbstractMutableCollection
addAll, countBy, countByEach, countByWith, reduce, removeAll, removeIf, removeIfWith, sumByDouble, sumByFloat, sumByInt, sumByLong
-
Methods inherited from class org.eclipse.collections.impl.AbstractRichIterable
appendString, appendString, asLazy, collect, collectIf, collectWith, containsAll, containsAllArguments, containsAllIterable, count, countWith, detectWith, detectWithIfNone, detectWithOptional, flatCollect, forEach, groupBy, groupByEach, groupByUniqueKey, injectInto, injectInto, injectInto, injectInto, injectInto, into, isEmpty, max, max, maxBy, min, min, minBy, reject, rejectWith, select, selectWith, sumOfDouble, sumOfFloat, sumOfInt, sumOfLong, toBag, toBiMap, toList, toMap, toSet, toSortedBag, toSortedBag, toSortedBagBy, toSortedListBy, toSortedMap, toSortedMap, toSortedMapBy, toSortedSet, toSortedSet, toSortedSetBy, toString, zip, zipWithIndex
-
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.eclipse.collections.impl.parallel.BatchIterable
forEach
-
Methods inherited from interface org.eclipse.collections.api.InternalIterable
forEach
-
Methods inherited from interface org.eclipse.collections.api.collection.MutableCollection
aggregateBy, aggregateInPlaceBy, collectBoolean, collectByte, collectChar, collectDouble, collectFloat, collectInt, collectLong, collectShort, countBy, countByEach, countByWith, flatCollectWith, removeIf, removeIfWith, sumByDouble, sumByFloat, sumByInt, sumByLong
-
Methods inherited from interface org.eclipse.collections.api.set.MutableSet
collectBoolean, collectByte, collectChar, collectDouble, collectFloat, collectInt, collectLong, collectShort, flatCollectWith, toImmutableSet
-
Methods inherited from interface org.eclipse.collections.api.RichIterable
aggregateBy, appendString, appendString, appendString, asLazy, collect, collectBoolean, collectByte, collectChar, collectDouble, collectFloat, collectIf, collectInt, collectLong, collectShort, collectWith, containsAll, containsAllArguments, containsAllIterable, containsAny, containsAnyIterable, containsBy, containsNone, containsNoneIterable, count, countBy, countByEach, countByWith, countWith, detectIfNone, detectWith, detectWithIfNone, detectWithOptional, flatCollect, flatCollectBoolean, flatCollectByte, flatCollectChar, flatCollectDouble, flatCollectFloat, flatCollectInt, flatCollectLong, flatCollectShort, flatCollectWith, forEach, getAny, getOnly, groupBy, groupByAndCollect, groupByEach, groupByUniqueKey, injectInto, injectInto, injectInto, injectInto, injectInto, injectIntoDouble, injectIntoFloat, injectIntoInt, injectIntoLong, into, isEmpty, makeString, makeString, makeString, makeString, max, max, maxBy, maxByOptional, maxOptional, maxOptional, min, min, minBy, minByOptional, minOptional, minOptional, notEmpty, reduce, reduceBy, reduceBy, reduceInPlace, reduceInPlace, reject, rejectWith, select, selectWith, summarizeDouble, summarizeFloat, summarizeInt, summarizeLong, sumOfDouble, sumOfFloat, sumOfInt, sumOfLong, toBag, toBiMap, toImmutableBag, toImmutableBiMap, toImmutableList, toImmutableMap, toImmutableSortedBag, toImmutableSortedBag, toImmutableSortedBagBy, toImmutableSortedList, toImmutableSortedList, toImmutableSortedListBy, toImmutableSortedSet, toImmutableSortedSet, toImmutableSortedSetBy, toList, toMap, toMap, toSet, toSortedBag, toSortedBag, toSortedBagBy, toSortedList, toSortedList, toSortedListBy, toSortedMap, toSortedMap, toSortedMapBy, toSortedSet, toSortedSet, toSortedSetBy, toString, zip, zipWithIndex
-
-
-
-
Field Detail
-
NULL_KEY
protected static final java.lang.Object NULL_KEY
-
serialVersionUID
private static final long serialVersionUID
- See Also:
- Constant Field Values
-
table
protected transient java.lang.Object[] table
-
occupied
protected transient int occupied
-
-
Constructor Detail
-
UnifiedSet
public UnifiedSet()
-
UnifiedSet
public UnifiedSet(int initialCapacity)
-
UnifiedSet
public UnifiedSet(int initialCapacity, float loadFactor)
-
UnifiedSet
public UnifiedSet(java.util.Collection<? extends T> collection)
-
UnifiedSet
public UnifiedSet(UnifiedSet<T> set)
-
-
Method Detail
-
newSet
public static <K> UnifiedSet<K> newSet()
-
newSet
public static <K> UnifiedSet<K> newSet(int size)
-
newSet
public static <K> UnifiedSet<K> newSet(java.lang.Iterable<? extends K> source)
-
newSet
public static <K> UnifiedSet<K> newSet(int size, float loadFactor)
-
newSetWith
public static <K> UnifiedSet<K> newSetWith(K... elements)
-
fastCeil
private int fastCeil(float v)
-
getTable
protected java.lang.Object[] getTable()
- Specified by:
getTablein classAbstractUnifiedSet<T>
-
allocateTable
protected void allocateTable(int sizeToAllocate)
- Specified by:
allocateTablein classAbstractUnifiedSet<T>
-
index
protected int index(java.lang.Object key)
-
clear
public void clear()
-
add
public boolean add(T key)
- Specified by:
addin interfacejava.util.Collection<T>- Specified by:
addin interfacejava.util.Set<T>- Overrides:
addin classAbstractMutableCollection<T>
-
chainedAdd
private boolean chainedAdd(T key, int index)
-
rehash
protected void rehash(int newCapacity)
- Specified by:
rehashin classAbstractUnifiedSet<T>
-
contains
public boolean contains(java.lang.Object key)
Description copied from interface:RichIterableReturns true if the iterable has an element which responds true to element.equals(object).- Specified by:
containsin interfacejava.util.Collection<T>- Specified by:
containsin interfaceRichIterable<T>- Specified by:
containsin interfacejava.util.Set<T>- Overrides:
containsin classAbstractRichIterable<T>
-
chainContains
private boolean chainContains(UnifiedSet.ChainedBucket bucket, T key)
-
batchForEach
public void batchForEach(Procedure<? super T> procedure, int sectionIndex, int sectionCount)
- Specified by:
batchForEachin interfaceBatchIterable<T>
-
tap
public MutableSet<T> tap(Procedure<? super T> procedure)
Description copied from interface:RichIterableExecutes the Procedure for each element in the iterable and returnsthis.Example using a Java 8 lambda expression:
RichIterable<Person> tapped = people.tap(person -> LOGGER.info(person.getName()));- Specified by:
tapin interfaceMutableCollection<T>- Specified by:
tapin interfaceMutableSet<T>- Specified by:
tapin interfaceMutableSetIterable<T>- Specified by:
tapin interfaceRichIterable<T>- Specified by:
tapin interfaceSetIterable<T>- Specified by:
tapin interfaceUnsortedSetIterable<T>- See Also:
RichIterable.each(Procedure),RichIterable.forEach(Procedure)
-
each
public void each(Procedure<? super T> procedure)
Description copied from interface:RichIterableThe procedure is executed for each element in the iterable.Example using a Java 8 lambda expression:
people.each(person -> LOGGER.info(person.getName()));
This method is a variant ofInternalIterable.forEach(Procedure)that has a signature conflict withIterable.forEach(java.util.function.Consumer).- Specified by:
eachin interfaceRichIterable<T>- See Also:
InternalIterable.forEach(Procedure),Iterable.forEach(java.util.function.Consumer)
-
chainedForEach
private void chainedForEach(UnifiedSet.ChainedBucket bucket, Procedure<? super T> procedure)
-
forEachWith
public <P> void forEachWith(Procedure2<? super T,? super P> procedure, P parameter)
Description copied from interface:InternalIterableThe procedure2 is evaluated for each element in the iterable with the specified parameter provided as the second argument.Example using a Java 8 lambda:
people.forEachWith((Person person, Person other) -> { if (person.isRelatedTo(other)) { LOGGER.info(person.getName()); } }, fred);Example using an anonymous inner class:
people.forEachWith(new Procedure2<Person, Person>() { public void value(Person person, Person other) { if (person.isRelatedTo(other)) { LOGGER.info(person.getName()); } } }, fred);- Specified by:
forEachWithin interfaceInternalIterable<T>- Overrides:
forEachWithin classAbstractRichIterable<T>
-
chainedForEachWith
private <P> void chainedForEachWith(UnifiedSet.ChainedBucket bucket, Procedure2<? super T,? super P> procedure, P parameter)
-
forEachWithIndex
public void forEachWithIndex(ObjectIntProcedure<? super T> objectIntProcedure)
Description copied from interface:InternalIterableIterates over the iterable passing each element and the current relative int index to the specified instance of ObjectIntProcedure.Example using a Java 8 lambda:
people.forEachWithIndex((Person person, int index) -> LOGGER.info("Index: " + index + " person: " + person.getName()));Example using an anonymous inner class:
people.forEachWithIndex(new ObjectIntProcedure<Person>() { public void value(Person person, int index) { LOGGER.info("Index: " + index + " person: " + person.getName()); } });- Specified by:
forEachWithIndexin interfaceInternalIterable<T>- Overrides:
forEachWithIndexin classAbstractRichIterable<T>
-
chainedForEachWithIndex
private int chainedForEachWithIndex(UnifiedSet.ChainedBucket bucket, ObjectIntProcedure<? super T> procedure, int count)
-
newEmpty
public UnifiedSet<T> newEmpty()
Description copied from interface:MutableCollectionCreates a new empty mutable version of the same collection type. For example, if this instance is a FastList, this method will return a new empty FastList. If the class of this instance is immutable or fixed size (i.e. SingletonList) then a mutable alternative to the class will be provided.- Specified by:
newEmptyin interfaceMutableCollection<T>- Specified by:
newEmptyin interfaceMutableSet<T>
-
newEmpty
public UnifiedSet<T> newEmpty(int size)
- Specified by:
newEmptyin classAbstractUnifiedSet<T>
-
getFirst
public T getFirst()
Description copied from interface:RichIterableReturns the first element of an iterable. In the case of a List it is the element at the first index. In the case of any other Collection, it is the first element that would be returned during an iteration. If the iterable is empty, null is returned. If null is a valid element of the container, then a developer would need to check to see if the iterable is empty to validate that a null result was not due to the container being empty.The order of Sets are not guaranteed (except for TreeSets and other Ordered Set implementations), so if you use this method, the first element could be any element from the Set.
- Specified by:
getFirstin interfaceRichIterable<T>
-
getLast
public T getLast()
Description copied from interface:RichIterableReturns the last element of an iterable. In the case of a List it is the element at the last index. In the case of any other Collection, it is the last element that would be returned during an iteration. If the iterable is empty, null is returned. If null is a valid element of the container, then a developer would need to check to see if the iterable is empty to validate that a null result was not due to the container being empty.The order of Sets are not guaranteed (except for TreeSets and other Ordered Set implementations), so if you use this method, the last element could be any element from the Set.
- Specified by:
getLastin interfaceRichIterable<T>
-
getLast
private T getLast(UnifiedSet.ChainedBucket bucket)
-
select
public UnifiedSet<T> select(Predicate<? super T> predicate)
Description copied from interface:RichIterableReturns all elements of the source collection that return true when evaluating the predicate. This method is also commonly called filter.Example using a Java 8 lambda expression:
RichIterable<Person> selected = people.select(person -> person.getAddress().getCity().equals("London"));- Specified by:
selectin interfaceMutableCollection<T>- Specified by:
selectin interfaceMutableSet<T>- Specified by:
selectin interfaceMutableSetIterable<T>- Specified by:
selectin interfaceRichIterable<T>- Specified by:
selectin interfaceSetIterable<T>- Specified by:
selectin interfaceUnsortedSetIterable<T>
-
selectWith
public <P> UnifiedSet<T> selectWith(Predicate2<? super T,? super P> predicate, P parameter)
Description copied from interface:RichIterableSimilar toRichIterable.select(Predicate), except with an evaluation parameter for the second generic argument inPredicate2.E.g. return a
Collectionof Person elements where the person has an age greater than or equal to 18 yearsExample using a Java 8 lambda expression:
RichIterable<Person> selected = people.selectWith((Person person, Integer age) -> person.getAge()>= age, Integer.valueOf(18));- Specified by:
selectWithin interfaceMutableCollection<T>- Specified by:
selectWithin interfaceMutableSet<T>- Specified by:
selectWithin interfaceMutableSetIterable<T>- Specified by:
selectWithin interfaceRichIterable<T>- Specified by:
selectWithin interfaceSetIterable<T>- Specified by:
selectWithin interfaceUnsortedSetIterable<T>- Parameters:
predicate- aPredicate2to use as the select criteriaparameter- a parameter to pass in for evaluation of the second argumentPinpredicate- See Also:
RichIterable.select(Predicate)
-
reject
public UnifiedSet<T> reject(Predicate<? super T> predicate)
Description copied from interface:RichIterableReturns all elements of the source collection that return false when evaluating of the predicate. This method is also sometimes called filterNot and is the equivalent of calling iterable.select(Predicates.not(predicate)).Example using a Java 8 lambda expression:
RichIterable<Person> rejected = people.reject(person -> person.person.getLastName().equals("Smith"));- Specified by:
rejectin interfaceMutableCollection<T>- Specified by:
rejectin interfaceMutableSet<T>- Specified by:
rejectin interfaceMutableSetIterable<T>- Specified by:
rejectin interfaceRichIterable<T>- Specified by:
rejectin interfaceSetIterable<T>- Specified by:
rejectin interfaceUnsortedSetIterable<T>- Parameters:
predicate- aPredicateto use as the reject criteria- Returns:
- a RichIterable that contains elements that cause
Predicate.accept(Object)method to evaluate to false
-
rejectWith
public <P> UnifiedSet<T> rejectWith(Predicate2<? super T,? super P> predicate, P parameter)
Description copied from interface:RichIterableSimilar toRichIterable.reject(Predicate), except with an evaluation parameter for the second generic argument inPredicate2.E.g. return a
Collectionof Person elements where the person has an age greater than or equal to 18 yearsExample using a Java 8 lambda expression:
RichIterable<Person> rejected = people.rejectWith((Person person, Integer age) -> person.getAge() < age, Integer.valueOf(18));- Specified by:
rejectWithin interfaceMutableCollection<T>- Specified by:
rejectWithin interfaceMutableSet<T>- Specified by:
rejectWithin interfaceMutableSetIterable<T>- Specified by:
rejectWithin interfaceRichIterable<T>- Specified by:
rejectWithin interfaceSetIterable<T>- Specified by:
rejectWithin interfaceUnsortedSetIterable<T>- Parameters:
predicate- aPredicate2to use as the select criteriaparameter- a parameter to pass in for evaluation of the second argumentPinpredicate- See Also:
RichIterable.select(Predicate)
-
selectAndRejectWith
public <P> Twin<MutableList<T>> selectAndRejectWith(Predicate2<? super T,? super P> predicate, P parameter)
Description copied from interface:MutableCollectionFilters a collection into two separate collections based on a predicate returned via a Pair.e.g. return lastNames.selectAndRejectWith(Predicates2.lessThan(), "Mason");
- Specified by:
selectAndRejectWithin interfaceMutableCollection<T>- Overrides:
selectAndRejectWithin classAbstractMutableCollection<T>
-
partition
public PartitionMutableSet<T> partition(Predicate<? super T> predicate)
Description copied from interface:RichIterableFilters a collection into a PartitionedIterable based on the evaluation of the predicate.Example using a Java 8 lambda expression:
PartitionIterable<Person> newYorkersAndNonNewYorkers = people.partition(person -> person.getAddress().getState().getName().equals("New York"));- Specified by:
partitionin interfaceMutableCollection<T>- Specified by:
partitionin interfaceMutableSet<T>- Specified by:
partitionin interfaceMutableSetIterable<T>- Specified by:
partitionin interfaceRichIterable<T>- Specified by:
partitionin interfaceSetIterable<T>
-
partitionWith
public <P> PartitionMutableSet<T> partitionWith(Predicate2<? super T,? super P> predicate, P parameter)
Description copied from interface:RichIterableFilters a collection into a PartitionIterable based on the evaluation of the predicate.Example using a Java 8 lambda expression:
PartitionIterable<Person> newYorkersAndNonNewYorkers = people.partitionWith((Person person, String state) -> person.getAddress().getState().getName().equals(state), "New York");- Specified by:
partitionWithin interfaceMutableCollection<T>- Specified by:
partitionWithin interfaceMutableSet<T>- Specified by:
partitionWithin interfaceMutableSetIterable<T>- Specified by:
partitionWithin interfaceRichIterable<T>- Specified by:
partitionWithin interfaceSetIterable<T>
-
selectInstancesOf
public <S> UnifiedSet<S> selectInstancesOf(java.lang.Class<S> clazz)
Description copied from interface:RichIterableReturns all elements of the source collection that are instances of the Classclazz.RichIterable<Integer> integers = List.mutable.with(new Integer(0), new Long(0L), new Double(0.0)).selectInstancesOf(Integer.class);- Specified by:
selectInstancesOfin interfaceMutableCollection<T>- Specified by:
selectInstancesOfin interfaceMutableSet<T>- Specified by:
selectInstancesOfin interfaceMutableSetIterable<T>- Specified by:
selectInstancesOfin interfaceRichIterable<T>- Specified by:
selectInstancesOfin interfaceSetIterable<T>- Specified by:
selectInstancesOfin interfaceUnsortedSetIterable<T>
-
detect
protected T detect(Predicate<? super T> predicate, int start, int end)
- Specified by:
detectin classAbstractUnifiedSet<T>
-
detectOptional
protected java.util.Optional<T> detectOptional(Predicate<? super T> predicate, int start, int end)
- Specified by:
detectOptionalin classAbstractUnifiedSet<T>
-
chainedDetect
private java.lang.Object chainedDetect(UnifiedSet.ChainedBucket bucket, Predicate<? super T> predicate)
-
shortCircuit
protected boolean shortCircuit(Predicate<? super T> predicate, boolean expected, boolean onShortCircuit, boolean atEnd, int start, int end)
- Specified by:
shortCircuitin classAbstractUnifiedSet<T>
-
chainedShortCircuit
private boolean chainedShortCircuit(UnifiedSet.ChainedBucket bucket, Predicate<? super T> predicate, boolean expected)
-
shortCircuitWith
protected <P> boolean shortCircuitWith(Predicate2<? super T,? super P> predicate2, P parameter, boolean expected, boolean onShortCircuit, boolean atEnd)
- Specified by:
shortCircuitWithin classAbstractUnifiedSet<T>
-
chainedShortCircuitWith
private <P> boolean chainedShortCircuitWith(UnifiedSet.ChainedBucket bucket, Predicate2<? super T,? super P> predicate, P parameter, boolean expected)
-
toImmutable
public ImmutableSet<T> toImmutable()
Description copied from interface:MutableSetReturns an immutable copy of this set. If the set is immutable, it returns itself.- Specified by:
toImmutablein interfaceMutableCollection<T>- Specified by:
toImmutablein interfaceMutableSet<T>- Specified by:
toImmutablein interfaceSetIterable<T>- Specified by:
toImmutablein interfaceUnsortedSetIterable<T>
-
with
public UnifiedSet<T> with(T element)
Description copied from interface:MutableCollectionThis method allows mutable and fixed size collections the ability to add elements to their existing elements. In order to support fixed size a new instance of a collection would have to be returned taking the elements of the original collection and appending the new element to form the new collection. In the case of mutable collections, the original collection is modified, and is returned. In order to use this method properly with mutable and fixed size collections the following approach must be taken:MutableCollection<String> list = list.with("1"); list = list.with("2"); return list;In the case ofFixedSizeCollectiona new instance of MutableCollection will be returned by with, and any variables that previously referenced the original collection will need to be redirected to reference the new instance. For other MutableCollection types you will replace the reference to collection with the same collection, since the instance will return "this" after calling add on itself.- Specified by:
within interfaceMutableCollection<T>- Specified by:
within interfaceMutableSet<T>- Specified by:
within interfaceMutableSetIterable<T>- See Also:
Collection.add(Object)
-
with
public UnifiedSet<T> with(T element1, T element2)
-
with
public UnifiedSet<T> with(T element1, T element2, T element3)
-
with
public UnifiedSet<T> with(T... elements)
-
withAll
public UnifiedSet<T> withAll(java.lang.Iterable<? extends T> iterable)
Description copied from interface:MutableCollectionThis method allows mutable and fixed size collections the ability to add multiple elements to their existing elements. In order to support fixed size a new instance of a collection would have to be returned taking the elements of the original collection and appending the new elements to form the new collection. In the case of mutable collections, the original collection is modified, and is returned. In order to use this method properly with mutable and fixed size collections the following approach must be taken:MutableCollection<String> list = list.withAll(FastList.newListWith("1", "2"));In the case ofFixedSizeCollectiona new instance of MutableCollection will be returned by withAll, and any variables that previously referenced the original collection will need to be redirected to reference the new instance. For other MutableCollection types you will replace the reference to collection with the same collection, since the instance will return "this" after calling addAll on itself.- Specified by:
withAllin interfaceMutableCollection<T>- Specified by:
withAllin interfaceMutableSet<T>- Specified by:
withAllin interfaceMutableSetIterable<T>- See Also:
Collection.addAll(Collection)
-
without
public UnifiedSet<T> without(T element)
Description copied from interface:MutableCollectionThis method allows mutable and fixed size collections the ability to remove elements from their existing elements. In order to support fixed size a new instance of a collection would have to be returned containing the elements that would be left from the original collection after calling remove. In the case of mutable collections, the original collection is modified, and is returned. In order to use this method properly with mutable and fixed size collections the following approach must be taken:MutableCollection<String> list = list.without("1"); list = list.without("2"); return list;In the case ofFixedSizeCollectiona new instance of MutableCollection will be returned by without, and any variables that previously referenced the original collection will need to be redirected to reference the new instance. For other MutableCollection types you will replace the reference to collection with the same collection, since the instance will return "this" after calling remove on itself.- Specified by:
withoutin interfaceMutableCollection<T>- Specified by:
withoutin interfaceMutableSet<T>- Specified by:
withoutin interfaceMutableSetIterable<T>- See Also:
Collection.remove(Object)
-
withoutAll
public UnifiedSet<T> withoutAll(java.lang.Iterable<? extends T> elements)
Description copied from interface:MutableCollectionThis method allows mutable and fixed size collections the ability to remove multiple elements from their existing elements. In order to support fixed size a new instance of a collection would have to be returned containing the elements that would be left from the original collection after calling removeAll. In the case of mutable collections, the original collection is modified, and is returned. In order to use this method properly with mutable and fixed size collections the following approach must be taken:MutableCollection<String> list = list.withoutAll(FastList.newListWith("1", "2"));In the case ofFixedSizeCollectiona new instance of MutableCollection will be returned by withoutAll, and any variables that previously referenced the original collection will need to be redirected to reference the new instance. For other MutableCollection types you will replace the reference to collection with the same collection, since the instance will return "this" after calling removeAll on itself.- Specified by:
withoutAllin interfaceMutableCollection<T>- Specified by:
withoutAllin interfaceMutableSet<T>- Specified by:
withoutAllin interfaceMutableSetIterable<T>- See Also:
Collection.removeAll(Collection)
-
addAllIterable
public boolean addAllIterable(java.lang.Iterable<? extends T> iterable)
- Specified by:
addAllIterablein interfaceMutableCollection<T>- Overrides:
addAllIterablein classAbstractMutableCollection<T>- See Also:
Collection.addAll(Collection)
-
ensureCapacity
private void ensureCapacity(int size)
-
copySet
protected boolean copySet(UnifiedSet<?> unifiedset)
-
copyChain
private boolean copyChain(UnifiedSet.ChainedBucket bucket)
-
remove
public boolean remove(java.lang.Object key)
- Specified by:
removein interfacejava.util.Collection<T>- Specified by:
removein interfacejava.util.Set<T>- Overrides:
removein classAbstractMutableCollection<T>
-
removeFromChain
private boolean removeFromChain(UnifiedSet.ChainedBucket bucket, T key, int index)
-
removeDeepChain
private boolean removeDeepChain(UnifiedSet.ChainedBucket oldBucket, T key)
-
size
public int size()
Description copied from interface:RichIterableReturns the number of items in this iterable.
-
equals
public boolean equals(java.lang.Object object)
Description copied from interface:SetIterableFollows the same general contract asSet.equals(Object).- Specified by:
equalsin interfacejava.util.Collection<T>- Specified by:
equalsin interfacejava.util.Set<T>- Specified by:
equalsin interfaceSetIterable<T>- Overrides:
equalsin classjava.lang.Object
-
hashCode
public int hashCode()
Description copied from interface:SetIterableFollows the same general contract asSet.hashCode().- Specified by:
hashCodein interfacejava.util.Collection<T>- Specified by:
hashCodein interfacejava.util.Set<T>- Specified by:
hashCodein interfaceSetIterable<T>- Overrides:
hashCodein classjava.lang.Object
-
chainedHashCode
private int chainedHashCode(UnifiedSet.ChainedBucket bucket)
-
trimToSize
public boolean trimToSize()
-
chainedTrimToSize
private void chainedTrimToSize(UnifiedSet.ChainedBucket bucket, int oldIndex, int mask)
-
addForTrim
private void addForTrim(java.lang.Object key, int oldIndex, int mask)
-
chainedAddForTrim
private void chainedAddForTrim(java.lang.Object key, int index)
-
readExternal
public void readExternal(java.io.ObjectInput in) throws java.io.IOException, java.lang.ClassNotFoundException- Specified by:
readExternalin interfacejava.io.Externalizable- Throws:
java.io.IOExceptionjava.lang.ClassNotFoundException
-
writeExternal
public void writeExternal(java.io.ObjectOutput out) throws java.io.IOException- Specified by:
writeExternalin interfacejava.io.Externalizable- Throws:
java.io.IOException
-
writeExternalChain
private void writeExternalChain(java.io.ObjectOutput out, UnifiedSet.ChainedBucket bucket) throws java.io.IOException- Throws:
java.io.IOException
-
addIfFound
private void addIfFound(T key, UnifiedSet<T> other)
-
addIfFoundFromChain
private void addIfFoundFromChain(UnifiedSet.ChainedBucket bucket, T key, UnifiedSet<T> other)
-
retainAllIterable
public boolean retainAllIterable(java.lang.Iterable<?> iterable)
- Specified by:
retainAllIterablein interfaceMutableCollection<T>- Overrides:
retainAllIterablein classAbstractMutableCollection<T>- See Also:
Collection.retainAll(Collection)
-
retainAllFromNonSet
private boolean retainAllFromNonSet(java.lang.Iterable<?> iterable)
-
retainAllFromSet
private boolean retainAllFromSet(java.util.Set<?> collection)
-
clone
public UnifiedSet<T> clone()
- Specified by:
clonein interfaceMutableSet<T>- Specified by:
clonein classAbstractUnifiedSet<T>
-
toArray
public java.lang.Object[] toArray()
Description copied from interface:RichIterableConverts this iterable to an array.- Specified by:
toArrayin interfacejava.util.Collection<T>- Specified by:
toArrayin interfaceMutableCollection<T>- Specified by:
toArrayin interfaceMutableSetIterable<T>- Specified by:
toArrayin interfaceRichIterable<T>- Specified by:
toArrayin interfacejava.util.Set<T>- See Also:
Collection.toArray()
-
copyToArray
private void copyToArray(java.lang.Object[] result)
-
copyBucketToArray
private int copyBucketToArray(java.lang.Object[] result, UnifiedSet.ChainedBucket bucket, int count)
-
toArray
public <T> T[] toArray(T[] array)
Description copied from interface:RichIterableConverts this iterable to an array using the specified target array, assuming the target array is as long or longer than the iterable.- Specified by:
toArrayin interfacejava.util.Collection<T>- Specified by:
toArrayin interfaceMutableCollection<T>- Specified by:
toArrayin interfaceMutableSetIterable<T>- Specified by:
toArrayin interfaceRichIterable<T>- Specified by:
toArrayin interfacejava.util.Set<T>- See Also:
Collection.toArray(Object[])
-
iterator
public java.util.Iterator<T> iterator()
-
groupBy
public <V> UnifiedSetMultimap<V,T> groupBy(Function<? super T,? extends V> function)
Description copied from interface:RichIterableFor each element of the iterable, the function is evaluated and the results of these evaluations are collected into a new multimap, where the transformed value is the key and the original values are added to the same (or similar) species of collection as the source iterable.Example using a Java 8 method reference:
Multimap<String, Person> peopleByLastName = people.groupBy(Person::getLastName);- Specified by:
groupByin interfaceMutableCollection<T>- Specified by:
groupByin interfaceMutableSet<T>- Specified by:
groupByin interfaceMutableSetIterable<T>- Specified by:
groupByin interfaceRichIterable<T>- Specified by:
groupByin interfaceUnsortedSetIterable<T>
-
groupByEach
public <V> UnifiedSetMultimap<V,T> groupByEach(Function<? super T,? extends java.lang.Iterable<V>> function)
Description copied from interface:RichIterableSimilar toRichIterable.groupBy(Function), except the result of evaluating function will return a collection of keys for each value.- Specified by:
groupByEachin interfaceMutableCollection<T>- Specified by:
groupByEachin interfaceMutableSet<T>- Specified by:
groupByEachin interfaceMutableSetIterable<T>- Specified by:
groupByEachin interfaceRichIterable<T>- Specified by:
groupByEachin interfaceUnsortedSetIterable<T>
-
get
public T get(T key)
Description copied from interface:PoolLocates an object in the pool which is equal tokey.
-
chainedGet
private T chainedGet(T key, UnifiedSet.ChainedBucket bucket)
-
put
public T put(T key)
Description copied from interface:PoolPutskeyinto the pool. If there is no existing object that is equal to key, key will be added to the pool and the return value will be the same instance. If there is an existing object in the pool that is equal tokey, the pool will remain unchanged and the pooled instance will be is returned.
-
removeFromPool
public T removeFromPool(T key)
Description copied from interface:PoolLocates an object in the pool which is equal tokeyand removes it.- Specified by:
removeFromPoolin interfacePool<T>- Parameters:
key- object to remove- Returns:
- The object reference in the pool equal to key or null.
-
removeFromChainForPool
private T removeFromChainForPool(UnifiedSet.ChainedBucket bucket, T key, int index)
-
removeDeepChainForPool
private T removeDeepChainForPool(UnifiedSet.ChainedBucket oldBucket, T key)
-
nonSentinel
private T nonSentinel(java.lang.Object key)
-
toSentinelIfNull
private static java.lang.Object toSentinelIfNull(java.lang.Object key)
-
nonNullTableObjectEquals
private boolean nonNullTableObjectEquals(java.lang.Object cur, T key)
-
asParallel
public ParallelUnsortedSetIterable<T> asParallel(java.util.concurrent.ExecutorService executorService, int batchSize)
Description copied from interface:SetIterableReturns a parallel iterable of this SetIterable.- Specified by:
asParallelin interfaceSetIterable<T>- Specified by:
asParallelin interfaceUnsortedSetIterable<T>
-
-