Interface ICommonsIterable<ELEMENTTYPE>
- Type Parameters:
ELEMENTTYPE- The data type to iterate
- All Superinterfaces:
Iterable<ELEMENTTYPE>
- All Known Subinterfaces:
ICallbackList<CALLBACKTYPE>,ICommonsCollection<ELEMENTTYPE>,ICommonsList<ELEMENTTYPE>,ICommonsNavigableSet<ELEMENTTYPE>,ICommonsOrderedSet<ELEMENTTYPE>,ICommonsSet<ELEMENTTYPE>,ICommonsSortedSet<ELEMENTTYPE>,IErrorList,IHasErrorLevels<IMPLTYPE>,IIterableIterator<ELEMENTTYPE>
- All Known Implementing Classes:
ArrayIterator,CallbackList,CombinationGenerator,CommonsArrayList,CommonsCopyOnWriteArrayList,CommonsCopyOnWriteArraySet,CommonsHashSet,CommonsLinkedHashSet,CommonsLinkedList,CommonsTreeSet,CommonsVector,CSVReader,ErrorList,FileSystemIterator,FileSystemRecursiveIterator,FilterIterator,HttpHeaderMap,InMemoryLogger,IterableIterator,IterableIteratorFromEnumeration,LRUSet,MapperIterator,NonBlockingStack,URLParameterList
Extended version of
Iterable with some additional default methods.- Author:
- Philip Helger
-
Method Summary
Modifier and TypeMethodDescriptiondefault booleancontainsAny(Predicate<? super ELEMENTTYPE> aFilter) Check if this collection contains any (=at least one) element matching the provided filter.default booleancontainsNone(Predicate<? super ELEMENTTYPE> aFilter) Check if this collection contains no (=zero) element matching the provided filter.default booleancontainsOnly(Predicate<? super ELEMENTTYPE> aFilter) Check if this collection contains only (=all) elements matching the provided filter.default voidfindAll(Predicate<? super ELEMENTTYPE> aFilter, Consumer<? super ELEMENTTYPE> aConsumer) Find all elements matching the supplied filter and invoke the provided consumer for each matching element.default <DSTTYPE extends ELEMENTTYPE>
voidfindAllInstanceOf(Class<DSTTYPE> aDstClass, Consumer<? super DSTTYPE> aConsumer) Find all elements that areinstanceOfthe provided class and invoke the provided consumer for all matching elements.default <DSTTYPE> voidfindAllMapped(Function<? super ELEMENTTYPE, DSTTYPE> aMapper, Consumer<? super DSTTYPE> aConsumer) Convert all elements using the provided function and invoke the provided consumer for all mapped elements.default <DSTTYPE> voidfindAllMapped(Function<? super ELEMENTTYPE, DSTTYPE> aMapper, Predicate<? super DSTTYPE> aFilter, Consumer<? super DSTTYPE> aConsumer) Convert all elements using the provided function, find all mapped elements matching the provided filter and invoke the provided consumer for all matching elements.default <DSTTYPE> voidfindAllMapped(Predicate<? super ELEMENTTYPE> aFilter, Function<? super ELEMENTTYPE, DSTTYPE> aMapper, Consumer<? super DSTTYPE> aConsumer) Find all elements matching the provided filter, convert the matching elements using the provided function and invoke the provided consumer for all mapped elements.default ELEMENTTYPEfindFirst(Predicate<? super ELEMENTTYPE> aFilter) Find the first element that matches the provided filter.default ELEMENTTYPEfindFirst(Predicate<? super ELEMENTTYPE> aFilter, ELEMENTTYPE aDefault) Find the first element that matches the provided filter.default intfindFirstIndex(Predicate<? super ELEMENTTYPE> aFilter) Find the first index where the provided filter matches.default <DSTTYPE> DSTTYPEfindFirstMapped(Predicate<? super ELEMENTTYPE> aFilter, Function<? super ELEMENTTYPE, DSTTYPE> aMapper) Find the first element that matches the provided filter and convert it using the provided mapper.default <DSTTYPE> DSTTYPEfindFirstMapped(Predicate<? super ELEMENTTYPE> aFilter, Function<? super ELEMENTTYPE, DSTTYPE> aMapper, DSTTYPE aDefault) Find the first element that matches the provided filter and convert it using the provided mapper.default intfindLastIndex(Predicate<? super ELEMENTTYPE> aFilter) Find the last index where the provided filter matches.default EContinueforEachBreakable(Function<? super ELEMENTTYPE, EContinue> aConsumer) A special version ofIterable.forEach(Consumer)that can break iteration if a certain requirement is fulfilled.default voidforEachByIndex(ObjIntConsumer<? super ELEMENTTYPE> aConsumer) Special forEach that takes anObjIntConsumerwhich is provided the value AND the index.default <EXTYPE extends Throwable>
voidforEachThrowing(IThrowingConsumer<? super ELEMENTTYPE, EXTYPE> aConsumer) A special version ofIterable.forEach(Consumer)where a consumer can throw an exception.default intgetCount()Retrieve the size of thisIterable.default intgetCount(Predicate<? super ELEMENTTYPE> aFilter) Count the number of elements in this iterable matching the provided filter.Methods inherited from interface java.lang.Iterable
forEach, iterator, spliterator
-
Method Details
-
forEachByIndex
Special forEach that takes anObjIntConsumerwhich is provided the value AND the index.- Parameters:
aConsumer- The consumer to use. May not benull.
-
forEachBreakable
@Nonnull default EContinue forEachBreakable(@Nonnull Function<? super ELEMENTTYPE, EContinue> aConsumer) A special version ofIterable.forEach(Consumer)that can break iteration if a certain requirement is fulfilled.- Parameters:
aConsumer- The consumer to be invoked. May not benull.- Returns:
EContinue.BREAKif iteration was stopped,EContinue.CONTINUEotherwise.
-
forEachThrowing
default <EXTYPE extends Throwable> void forEachThrowing(@Nonnull IThrowingConsumer<? super ELEMENTTYPE, EXTYPE> aConsumer) throws EXTYPEA special version ofIterable.forEach(Consumer)where a consumer can throw an exception.- Type Parameters:
EXTYPE- the type of Exception to be thrown- Parameters:
aConsumer- The consumer to be invoked. May not benull.- Throws:
EXTYPE- If one of the consumer throws this exception- Since:
- 10.0.0
-
findAll
default void findAll(@Nullable Predicate<? super ELEMENTTYPE> aFilter, @Nonnull Consumer<? super ELEMENTTYPE> aConsumer) Find all elements matching the supplied filter and invoke the provided consumer for each matching element.- Parameters:
aFilter- The filter to be applied. May benull.aConsumer- The consumer to be invoked for all matching elements. May not benull.
-
findAllMapped
default <DSTTYPE> void findAllMapped(@Nonnull Function<? super ELEMENTTYPE, DSTTYPE> aMapper, @Nonnull Consumer<? super DSTTYPE> aConsumer) Convert all elements using the provided function and invoke the provided consumer for all mapped elements.- Type Parameters:
DSTTYPE- The destination type to be mapped to- Parameters:
aMapper- The mapping function to be executed for all elements. May not benull.aConsumer- The consumer to be invoked for all mapped elements. May not benull.
-
findAllMapped
default <DSTTYPE> void findAllMapped(@Nullable Predicate<? super ELEMENTTYPE> aFilter, @Nonnull Function<? super ELEMENTTYPE, DSTTYPE> aMapper, @Nonnull Consumer<? super DSTTYPE> aConsumer) Find all elements matching the provided filter, convert the matching elements using the provided function and invoke the provided consumer for all mapped elements.- Type Parameters:
DSTTYPE- The destination type to be mapped to- Parameters:
aFilter- The filter to be applied. May benull.aMapper- The mapping function to be executed for all matching elements. May not benull.aConsumer- The consumer to be invoked for all matching mapped elements. May not benull.
-
findAllMapped
default <DSTTYPE> void findAllMapped(@Nonnull Function<? super ELEMENTTYPE, DSTTYPE> aMapper, @Nullable Predicate<? super DSTTYPE> aFilter, @Nonnull Consumer<? super DSTTYPE> aConsumer) Convert all elements using the provided function, find all mapped elements matching the provided filter and invoke the provided consumer for all matching elements.- Type Parameters:
DSTTYPE- The destination type to be mapped to- Parameters:
aMapper- The mapping function to be executed for all matching elements. May not benull.aFilter- The filter to be applied. May benull.aConsumer- The consumer to be invoked for all matching mapped elements. May not benull.- Since:
- 8.5.2
-
findAllInstanceOf
default <DSTTYPE extends ELEMENTTYPE> void findAllInstanceOf(@Nonnull Class<DSTTYPE> aDstClass, @Nonnull Consumer<? super DSTTYPE> aConsumer) Find all elements that areinstanceOfthe provided class and invoke the provided consumer for all matching elements. This is a special implementation offindAllMapped(Predicate, Function, Consumer).- Type Parameters:
DSTTYPE- The destination type to be casted to- Parameters:
aDstClass- The class of which all elements should be find. May not benull.aConsumer- The consumer to be invoked for all instances of the provided class. May not benull.
-
findFirst
Find the first element that matches the provided filter. If no element matches the provided filter or if the collection is empty,nullis returned by default. If this collection does not maintain order (like Set) it is undefined which value is returned.- Parameters:
aFilter- The filter to be applied. May benull.- Returns:
nullif no element matches the filter or if the collection is empty, the first matching element otherwise.- See Also:
-
findFirst
@Nullable default ELEMENTTYPE findFirst(@Nullable Predicate<? super ELEMENTTYPE> aFilter, @Nullable ELEMENTTYPE aDefault) Find the first element that matches the provided filter. If no element matches the provided filter or if the collection is empty, the provided default value is returned. If this collection does not maintain order (like Set) it is undefined which value is returned.- Parameters:
aFilter- The filter to be applied. May benull.aDefault- The default value to be returned if no element matches. May benull.- Returns:
- The provided default value if no element matches the filter or if the collection is empty, the first matching element otherwise.
- See Also:
-
findFirstMapped
@Nullable default <DSTTYPE> DSTTYPE findFirstMapped(@Nullable Predicate<? super ELEMENTTYPE> aFilter, @Nonnull Function<? super ELEMENTTYPE, DSTTYPE> aMapper) Find the first element that matches the provided filter and convert it using the provided mapper. If no element matches the provided filter or if the collection is empty,nullis returned by default. If this collection does not maintain order (like Set) it is undefined which value is returned.- Type Parameters:
DSTTYPE- The destination type to be mapped to- Parameters:
aFilter- The filter to be applied. May benull.aMapper- The mapping function to be executed for the first matching element. May not benull.- Returns:
nullif no element matches the filter or if the collection is empty, the first matching element otherwise.- See Also:
-
findFirstMapped
@Nullable default <DSTTYPE> DSTTYPE findFirstMapped(@Nullable Predicate<? super ELEMENTTYPE> aFilter, @Nonnull Function<? super ELEMENTTYPE, DSTTYPE> aMapper, @Nullable DSTTYPE aDefault) Find the first element that matches the provided filter and convert it using the provided mapper. If no element matches the provided filter or if the collection is empty, the provided default value is returned. If this collection does not maintain order (like Set) it is undefined which value is returned.- Type Parameters:
DSTTYPE- The destination type to be mapped to- Parameters:
aFilter- The filter to be applied. May benull.aMapper- The mapping function to be executed for the first matching element. May not benull.aDefault- The default value to be returned if no element matches. May benull.- Returns:
- The provided default value if no element matches the filter or if the collection is empty, the first matching element otherwise.
- See Also:
-
containsAny
Check if this collection contains any (=at least one) element matching the provided filter.- Parameters:
aFilter- The filter to be applied. May benull.- Returns:
trueif the container is not empty and at least one element matches the provided filter,falseotherwise. If no filter is provided the response is the same asIHasSize.isNotEmpty().
-
containsNone
Check if this collection contains no (=zero) element matching the provided filter.- Parameters:
aFilter- The filter to be applied. May benull.- Returns:
trueif the container is empty or if no element matches the provided filter,falseotherwise. If no filter is provided, this is the same asCollection.isEmpty().
-
containsOnly
Check if this collection contains only (=all) elements matching the provided filter. If this collection is empty, it does not fulfill this requirement! If no filter is provided the return value is identical toIHasSize.isNotEmpty().- Parameters:
aFilter- The filter to be applied. May benull.- Returns:
trueif this collection is not empty and all elements matching the filter or if no filter is provided and this collection is not empty,falseotherwise. If no filter is supplied the return value is identical toIHasSize.isNotEmpty().
-
getCount
Retrieve the size of thisIterable. This method does by default iterate all elements. Please provide a more efficient solution. If this is a collection, consider usingsize()instead.- Returns:
- The number objects contained. Always ≥ 0.
-
getCount
Count the number of elements in this iterable matching the provided filter.- Parameters:
aFilter- The filter to be applied. May benull.- Returns:
- The number of matching elements. Always ≥ 0. If no filter is
provided this is the same as
getCount().
-
findFirstIndex
Find the first index where the provided filter matches.- Parameters:
aFilter- The filter to use. May not benull.- Returns:
- -1 if no element matches the filter, the 0-based index otherwise.
- Since:
- 9.3.3
-
findLastIndex
Find the last index where the provided filter matches.- Parameters:
aFilter- The filter to use. May not benull.- Returns:
- -1 if no element matches the filter, the 0-based index otherwise.
- Since:
- 9.3.3
-