Interface UnsortedBag<T>
-
- All Superinterfaces:
Bag<T>,InternalIterable<T>,Iterable<T>,RichIterable<T>
- All Known Subinterfaces:
ImmutableBag<T>,MultiReaderBag<T>,MutableBag<T>
public interface UnsortedBag<T> extends Bag<T>
-
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Deprecated Methods Modifier and Type Method Description <V> UnsortedBag<V>collect(Function<? super T,? extends V> function)Returns a new collection with the results of applying the specified function on each element of the source collection.BooleanBagcollectBoolean(BooleanFunction<? super T> booleanFunction)Returns a new primitivebooleaniterable with the results of applying the specified function on each element of the source collection.ByteBagcollectByte(ByteFunction<? super T> byteFunction)Returns a new primitivebyteiterable with the results of applying the specified function on each element of the source collection.CharBagcollectChar(CharFunction<? super T> charFunction)Returns a new primitivechariterable with the results of applying the specified function on each element of the source collection.DoubleBagcollectDouble(DoubleFunction<? super T> doubleFunction)Returns a new primitivedoubleiterable with the results of applying the specified function on each element of the source collection.FloatBagcollectFloat(FloatFunction<? super T> floatFunction)Returns a new primitivefloatiterable with the results of applying the specified function on each element of the source collection.<V> UnsortedBag<V>collectIf(Predicate<? super T> predicate, Function<? super T,? extends V> function)Returns a new collection with the results of applying the specified function on each element of the source collection, but only for those elements which return true upon evaluation of the predicate.IntBagcollectInt(IntFunction<? super T> intFunction)Returns a new primitiveintiterable with the results of applying the specified function on each element of the source collection.LongBagcollectLong(LongFunction<? super T> longFunction)Returns a new primitivelongiterable with the results of applying the specified function on each element of the source collection.ShortBagcollectShort(ShortFunction<? super T> shortFunction)Returns a new primitiveshortiterable with the results of applying the specified function on each element of the source collection.<P,V>
UnsortedBag<V>collectWith(Function2<? super T,? super P,? extends V> function, P parameter)Same asRichIterable.collect(Function)with aFunction2and specified parameter which is passed to the block.<V> UnsortedBag<V>collectWithOccurrences(ObjectIntToObjectFunction<? super T,? extends V> function)Iterates over the unique elements and their occurrences and collects the results of applying the specified function.<V> UnsortedBag<V>flatCollect(Function<? super T,? extends Iterable<V>> function)flatCollectis a special case ofRichIterable.collect(Function).default <P,V>
UnsortedBag<V>flatCollectWith(Function2<? super T,? super P,? extends Iterable<V>> function, P parameter)<V> UnsortedBagMultimap<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> UnsortedBagMultimap<V,T>groupByEach(Function<? super T,? extends Iterable<V>> function)Similar toRichIterable.groupBy(Function), except the result of evaluating function will return a collection of keys for each value.PartitionUnsortedBag<T>partition(Predicate<? super T> predicate)Filters a collection into a PartitionedIterable based on the evaluation of the predicate.UnsortedBag<T>reject(Predicate<? super T> predicate)Returns all elements of the source collection that return false when evaluating of the predicate.<P> UnsortedBag<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.UnsortedBag<T>select(Predicate<? super T> predicate)Returns all elements of the source collection that return true when evaluating the predicate.UnsortedBag<T>selectByOccurrences(IntPredicate predicate)Returns all elements of the bag that have a number of occurrences that satisfy the predicate.default UnsortedBag<T>selectDuplicates()Returns all elements of the bag that have more than one occurrence.<S> UnsortedBag<S>selectInstancesOf(Class<S> clazz)Returns all elements of the source collection that are instances of the Classclazz.UnsortedSetIterable<T>selectUnique()Returns a set containing all elements of the bag that have exactly one occurrence.<P> UnsortedBag<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.UnsortedBag<T>tap(Procedure<? super T> procedure)Executes the Procedure for each element in the iterable and returnsthis.<S> UnsortedBag<Pair<T,S>>zip(Iterable<S> that)Deprecated.in 6.0.UnsortedSetIterable<Pair<T,Integer>>zipWithIndex()Deprecated.in 6.0.-
Methods inherited from interface org.eclipse.collections.api.bag.Bag
aggregateBy, allSatisfyWithOccurrences, anySatisfyWithOccurrences, bottomOccurrences, collectWithOccurrences, detectWithOccurrences, distinctView, equals, forEachWithOccurrences, hashCode, noneSatisfyWithOccurrences, occurrencesOf, partitionWith, reduceInPlace, reduceInPlace, sizeDistinct, summarizeDouble, summarizeFloat, summarizeInt, summarizeLong, toImmutable, toMapOfItemToCount, topOccurrences, toStringOfItemToCount
-
Methods inherited from interface org.eclipse.collections.api.InternalIterable
forEach, forEachWith, forEachWithIndex
-
Methods inherited from interface java.lang.Iterable
iterator, spliterator
-
Methods inherited from interface org.eclipse.collections.api.RichIterable
aggregateBy, aggregateInPlaceBy, allSatisfy, allSatisfyWith, anySatisfy, anySatisfyWith, appendString, appendString, appendString, asLazy, chunk, collect, collectBoolean, collectByte, collectChar, collectDouble, collectFloat, collectIf, collectInt, collectLong, collectShort, collectWith, contains, containsAll, containsAllArguments, containsAllIterable, containsAny, containsAnyIterable, containsBy, containsNone, containsNoneIterable, count, countBy, countBy, countByEach, countByEach, countByWith, countByWith, countWith, detect, detectIfNone, detectOptional, detectWith, detectWithIfNone, detectWithOptional, each, flatCollect, flatCollectBoolean, flatCollectByte, flatCollectChar, flatCollectDouble, flatCollectFloat, flatCollectInt, flatCollectLong, flatCollectShort, flatCollectWith, forEach, getAny, getFirst, getLast, getOnly, groupBy, groupByAndCollect, groupByEach, groupByUniqueKey, 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, noneSatisfy, noneSatisfyWith, notEmpty, reduce, reject, rejectWith, select, selectWith, size, sumByDouble, sumByFloat, sumByInt, sumByLong, sumOfDouble, sumOfFloat, sumOfInt, sumOfLong, toArray, toArray, toBag, toBiMap, toImmutableBag, toImmutableBiMap, toImmutableList, toImmutableMap, toImmutableSet, 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
-
-
-
-
Method Detail
-
tap
UnsortedBag<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 interfaceBag<T>- Specified by:
tapin interfaceRichIterable<T>- See Also:
RichIterable.each(Procedure),RichIterable.forEach(Procedure)
-
selectByOccurrences
UnsortedBag<T> selectByOccurrences(IntPredicate predicate)
Description copied from interface:BagReturns all elements of the bag that have a number of occurrences that satisfy the predicate.- Specified by:
selectByOccurrencesin interfaceBag<T>
-
selectDuplicates
default UnsortedBag<T> selectDuplicates()
Description copied from interface:BagReturns all elements of the bag that have more than one occurrence.- Specified by:
selectDuplicatesin interfaceBag<T>- Since:
- 9.2
-
selectUnique
UnsortedSetIterable<T> selectUnique()
Description copied from interface:BagReturns a set containing all elements of the bag that have exactly one occurrence.- Specified by:
selectUniquein interfaceBag<T>- Since:
- 9.2
-
select
UnsortedBag<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"));
-
selectWith
<P> UnsortedBag<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 interfaceBag<T>- Specified by:
selectWithin interfaceRichIterable<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
UnsortedBag<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 interfaceBag<T>- Specified by:
rejectin interfaceRichIterable<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
<P> UnsortedBag<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 interfaceBag<T>- Specified by:
rejectWithin interfaceRichIterable<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)
-
selectInstancesOf
<S> UnsortedBag<S> selectInstancesOf(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 interfaceBag<T>- Specified by:
selectInstancesOfin interfaceRichIterable<T>
-
partition
PartitionUnsortedBag<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"));
-
collect
<V> UnsortedBag<V> collect(Function<? super T,? extends V> function)
Description copied from interface:RichIterableReturns a new collection with the results of applying the specified function on each element of the source collection. This method is also commonly called transform or map.Example using a Java 8 lambda expression:
RichIterable<String> names = people.collect(person -> person.getFirstName() + " " + person.getLastName());- Specified by:
collectin interfaceRichIterable<T>
-
collectBoolean
BooleanBag collectBoolean(BooleanFunction<? super T> booleanFunction)
Description copied from interface:RichIterableReturns a new primitivebooleaniterable with the results of applying the specified function on each element of the source collection. This method is also commonly called transform or map.Example using a Java 8 lambda expression:
BooleanIterable licenses = people.collectBoolean(person -> person.hasDrivingLicense());- Specified by:
collectBooleanin interfaceRichIterable<T>
-
collectByte
ByteBag collectByte(ByteFunction<? super T> byteFunction)
Description copied from interface:RichIterableReturns a new primitivebyteiterable with the results of applying the specified function on each element of the source collection. This method is also commonly called transform or map.Example using a Java 8 lambda expression:
ByteIterable bytes = people.collectByte(person -> person.getCode());- Specified by:
collectBytein interfaceRichIterable<T>
-
collectChar
CharBag collectChar(CharFunction<? super T> charFunction)
Description copied from interface:RichIterableReturns a new primitivechariterable with the results of applying the specified function on each element of the source collection. This method is also commonly called transform or map.Example using a Java 8 lambda expression:
CharIterable chars = people.collectChar(person -> person.getMiddleInitial());- Specified by:
collectCharin interfaceRichIterable<T>
-
collectDouble
DoubleBag collectDouble(DoubleFunction<? super T> doubleFunction)
Description copied from interface:RichIterableReturns a new primitivedoubleiterable with the results of applying the specified function on each element of the source collection. This method is also commonly called transform or map.Example using a Java 8 lambda expression:
DoubleIterable doubles = people.collectDouble(person -> person.getMilesFromNorthPole());- Specified by:
collectDoublein interfaceRichIterable<T>
-
collectFloat
FloatBag collectFloat(FloatFunction<? super T> floatFunction)
Description copied from interface:RichIterableReturns a new primitivefloatiterable with the results of applying the specified function on each element of the source collection. This method is also commonly called transform or map.Example using a Java 8 lambda expression:
FloatIterable floats = people.collectFloat(person -> person.getHeightInInches());- Specified by:
collectFloatin interfaceRichIterable<T>
-
collectInt
IntBag collectInt(IntFunction<? super T> intFunction)
Description copied from interface:RichIterableReturns a new primitiveintiterable with the results of applying the specified function on each element of the source collection. This method is also commonly called transform or map.Example using a Java 8 lambda expression:
IntIterable ints = people.collectInt(person -> person.getAge());- Specified by:
collectIntin interfaceRichIterable<T>
-
collectLong
LongBag collectLong(LongFunction<? super T> longFunction)
Description copied from interface:RichIterableReturns a new primitivelongiterable with the results of applying the specified function on each element of the source collection. This method is also commonly called transform or map.Example using a Java 8 lambda expression:
LongIterable longs = people.collectLong(person -> person.getGuid());- Specified by:
collectLongin interfaceRichIterable<T>
-
collectShort
ShortBag collectShort(ShortFunction<? super T> shortFunction)
Description copied from interface:RichIterableReturns a new primitiveshortiterable with the results of applying the specified function on each element of the source collection. This method is also commonly called transform or map.Example using a Java 8 lambda expression:
ShortIterable shorts = people.collectShort(person -> person.getNumberOfJunkMailItemsReceivedPerMonth());- Specified by:
collectShortin interfaceRichIterable<T>
-
collectWith
<P,V> UnsortedBag<V> collectWith(Function2<? super T,? super P,? extends V> function, P parameter)
Description copied from interface:RichIterableSame asRichIterable.collect(Function)with aFunction2and specified parameter which is passed to the block.Example using a Java 8 lambda expression:
RichIterable<Integer> integers = Lists.mutable.with(1, 2, 3).collectWith((each, parameter) -> each + parameter, Integer.valueOf(1));- Specified by:
collectWithin interfaceRichIterable<T>- Parameters:
function- AFunction2to use as the collect transformation functionparameter- A parameter to pass in for evaluation of the second argumentPinfunction- Returns:
- A new
RichIterablethat contains the transformed elements returned byFunction2.value(Object, Object) - See Also:
RichIterable.collect(Function)
-
collectIf
<V> UnsortedBag<V> collectIf(Predicate<? super T> predicate, Function<? super T,? extends V> function)
Description copied from interface:RichIterableReturns a new collection with the results of applying the specified function on each element of the source collection, but only for those elements which return true upon evaluation of the predicate. This is the optimized equivalent of calling iterable.select(predicate).collect(function).Example using a Java 8 lambda and method reference:
RichIterable<String> strings = Lists.mutable.with(1, 2, 3).collectIf(e -> e != null, Object::toString);
Example using Predicates factory:
RichIterable<String> strings = Lists.mutable.with(1, 2, 3).collectIf(Predicates.notNull(), Functions.getToString());
- Specified by:
collectIfin interfaceRichIterable<T>
-
collectWithOccurrences
<V> UnsortedBag<V> collectWithOccurrences(ObjectIntToObjectFunction<? super T,? extends V> function)
Description copied from interface:BagIterates over the unique elements and their occurrences and collects the results of applying the specified function.- Specified by:
collectWithOccurrencesin interfaceBag<T>
-
flatCollect
<V> UnsortedBag<V> flatCollect(Function<? super T,? extends Iterable<V>> function)
Description copied from interface:RichIterableflatCollectis a special case ofRichIterable.collect(Function). Withcollect, when theFunctionreturns a collection, the result is a collection of collections.flatCollectoutputs a single "flattened" collection instead. This method is commonly called flatMap.Consider the following example where we have a
Personclass, and eachPersonhas a list ofAddressobjects. Take the followingFunction:Function<Person, List<Address>> addressFunction = Person::getAddresses; RichIterable<Person> people = ...;
Usingcollectreturns a collection of collections of addresses.RichIterable<List<Address>> addresses = people.collect(addressFunction);
UsingflatCollectreturns a single flattened list of addresses.RichIterable<Address> addresses = people.flatCollect(addressFunction);
- Specified by:
flatCollectin interfaceRichIterable<T>- Parameters:
function- TheFunctionto apply- Returns:
- a new flattened collection produced by applying the given
function
-
flatCollectWith
default <P,V> UnsortedBag<V> flatCollectWith(Function2<? super T,? super P,? extends Iterable<V>> function, P parameter)
- Specified by:
flatCollectWithin interfaceRichIterable<T>- Since:
- 9.2
-
zip
@Deprecated <S> UnsortedBag<Pair<T,S>> zip(Iterable<S> that)
Deprecated.in 6.0. UseOrderedIterable.zip(Iterable)instead.Description copied from interface:RichIterableReturns aRichIterableformed from thisRichIterableand anotherRichIterableby combining corresponding elements in pairs. If one of the twoRichIterables is longer than the other, its remaining elements are ignored.- Specified by:
zipin interfaceRichIterable<T>- Type Parameters:
S- the type of the second half of the returned pairs- Parameters:
that- TheRichIterableproviding the second half of each result pair- Returns:
- A new
RichIterablecontaining pairs consisting of corresponding elements of thisRichIterableand that. The length of the returnedRichIterableis the minimum of the lengths of thisRichIterableand that.
-
zipWithIndex
@Deprecated UnsortedSetIterable<Pair<T,Integer>> zipWithIndex()
Deprecated.in 6.0. UseOrderedIterable.zipWithIndex()instead.Description copied from interface:RichIterableZips thisRichIterablewith its indices.- Specified by:
zipWithIndexin interfaceBag<T>- Specified by:
zipWithIndexin interfaceRichIterable<T>- Returns:
- A new
RichIterablecontaining pairs consisting of all elements of thisRichIterablepaired with their index. Indices start at 0. - See Also:
RichIterable.zip(Iterable)
-
groupBy
<V> UnsortedBagMultimap<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);
-
groupByEach
<V> UnsortedBagMultimap<V,T> groupByEach(Function<? super T,? extends 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 interfaceBag<T>- Specified by:
groupByEachin interfaceRichIterable<T>
-
-