Interface ICommonsCollection<ELEMENTTYPE>
- Type Parameters:
ELEMENTTYPE- The data type stored in the collection
- All Superinterfaces:
Collection<ELEMENTTYPE>,ICommonsIterable<ELEMENTTYPE>,IHasSize,Iterable<ELEMENTTYPE>
- All Known Subinterfaces:
ICommonsList<ELEMENTTYPE>,ICommonsNavigableSet<ELEMENTTYPE>,ICommonsOrderedSet<ELEMENTTYPE>,ICommonsSet<ELEMENTTYPE>,ICommonsSortedSet<ELEMENTTYPE>,IErrorList
- All Known Implementing Classes:
CommonsArrayList,CommonsCopyOnWriteArrayList,CommonsCopyOnWriteArraySet,CommonsHashSet,CommonsLinkedHashSet,CommonsLinkedList,CommonsTreeSet,CommonsVector,ErrorList,LRUSet,NonBlockingStack,URLParameterList
public interface ICommonsCollection<ELEMENTTYPE>
extends Collection<ELEMENTTYPE>, ICommonsIterable<ELEMENTTYPE>, IHasSize
Case collection interface for my extended collection classes.
- Author:
- Philip Helger
-
Method Summary
Modifier and TypeMethodDescriptiondefault EChangeaddAll(ELEMENTTYPE... aElements) Add an array of elements to this collection.default EChangeaddAll(ELEMENTTYPE[] aElements, Predicate<? super ELEMENTTYPE> aFilter) Add all matching elements of an array this collection.default EChangeaddAll(Iterable<? extends ELEMENTTYPE> aElements) Add all elements of the passed iterable to this collection.default EChangeaddAll(Iterable<? extends ELEMENTTYPE> aElements, Predicate<? super ELEMENTTYPE> aFilter) Add all elements of the passed iterable to this collection.default EChangeaddAll(Enumeration<? extends ELEMENTTYPE> aEnum) Add all elements of the passed enumeration to this collection.default EChangeaddAll(Enumeration<? extends ELEMENTTYPE> aEnum, Predicate<? super ELEMENTTYPE> aFilter) Add all elements of the passed enumeration to this collection.default EChangeaddAll(Iterator<? extends ELEMENTTYPE> aIter) Add all elements of the passed iterator to this collection.default EChangeaddAll(Iterator<? extends ELEMENTTYPE> aIter, Predicate<? super ELEMENTTYPE> aFilter) Add all elements of the passed iterator to this collection.default <SRCTYPE> EChangeaddAllMapped(Iterable<? extends SRCTYPE> aElements, Function<? super SRCTYPE, ? extends ELEMENTTYPE> aMapper) Add all passed elements after performing a mapping using the provided function.default <SRCTYPE> EChangeaddAllMapped(Iterable<? extends SRCTYPE> aElements, Function<? super SRCTYPE, ? extends ELEMENTTYPE> aMapper, Predicate<? super ELEMENTTYPE> aFilter) Add all passed elements matching the provided filter after performing a mapping using the provided function.default <SRCTYPE> EChangeaddAllMapped(Iterable<? extends SRCTYPE> aElements, Predicate<? super SRCTYPE> aFilter, Function<? super SRCTYPE, ? extends ELEMENTTYPE> aMapper) Add all passed elements matching the provided filter after performing a mapping using the provided function.default <SRCTYPE> EChangeaddAllMapped(SRCTYPE[] aElements, Function<? super SRCTYPE, ? extends ELEMENTTYPE> aMapper) Add all passed elements after performing a mapping using the provided function.default <SRCTYPE> EChangeaddAllMapped(SRCTYPE[] aElements, Function<? super SRCTYPE, ? extends ELEMENTTYPE> aMapper, Predicate<? super ELEMENTTYPE> aFilter) Add all passed elements matching the provided filter after performing a mapping using the provided function.default <SRCTYPE> EChangeaddAllMapped(SRCTYPE[] aElements, Predicate<? super SRCTYPE> aFilter, Function<? super SRCTYPE, ? extends ELEMENTTYPE> aMapper) Add all passed elements matching the provided filter after performing a mapping using the provided function.default EChangeaddIf(ELEMENTTYPE aElement, Predicate<? super ELEMENTTYPE> aFilter) Add the passed element to this collection if passed predicate is fulfilleddefault EChangeaddIfNotNull(ELEMENTTYPE aElement) Add the passed element to this collection if it is non-null.default EChangeaddObject(ELEMENTTYPE aElement) add the provided element to the collection usingCollection.add(Object)but returning a more structured return value.default Collection<ELEMENTTYPE> default ELEMENTTYPEgetAtIndex(int nIndex) Get the element at the specified index or returnnullupon invalid index.default ELEMENTTYPEgetAtIndex(int nIndex, ELEMENTTYPE aDefault) Get the element at the specified index or return the provided default value upon invalid index.default ELEMENTTYPEgetAtIndex(Predicate<? super ELEMENTTYPE> aFilter, int nIndex) Get the element at the specified index counting only elements matching the specified filter.default ELEMENTTYPEgetAtIndex(Predicate<? super ELEMENTTYPE> aFilter, int nIndex, ELEMENTTYPE aDefault) Get the element at the specified index counting only elements matching the specified filter or return the provided default value upon invalid index.default <DSTTYPE> DSTTYPEgetAtIndexMapped(int nIndex, Function<? super ELEMENTTYPE, ? extends DSTTYPE> aMapper) Get the element at the specified index or returnnullupon invalid index.default <DSTTYPE> DSTTYPEgetAtIndexMapped(int nIndex, Function<? super ELEMENTTYPE, ? extends DSTTYPE> aMapper, DSTTYPE aDefault) Get the element at the specified index or return the provided default value upon invalid index.default <DSTTYPE> DSTTYPEgetAtIndexMapped(Predicate<? super ELEMENTTYPE> aFilter, int nIndex, Function<? super ELEMENTTYPE, ? extends DSTTYPE> aMapper) Get the element at the specified index, counting only elements matching the provided filter and map the resulting element using the provided mapper.default <DSTTYPE> DSTTYPEgetAtIndexMapped(Predicate<? super ELEMENTTYPE> aFilter, int nIndex, Function<? super ELEMENTTYPE, ? extends DSTTYPE> aMapper, DSTTYPE aDefault) Get the element at the specified index, counting only elements matching the provided filter and map the resulting element using the provided mapper.default ICommonsList<ELEMENTTYPE> default intgetCount(Predicate<? super ELEMENTTYPE> aFilter) Count the number of elements matching the provided filter.default ICommonsList<ELEMENTTYPE> getSorted(Comparator<? super ELEMENTTYPE> aComparator) Return a sorted version of this collection.default IIterableIterator<ELEMENTTYPE> default EChangeRemove all elements from this collection.default EChangeremoveObject(ELEMENTTYPE aElement) Remove the provided element from the collection usingCollection.remove(Object)but returning a more structured return value.default EChangeset(ELEMENTTYPE aValue) Clear all elements and add only the passed value.default EChangesetAll(ELEMENTTYPE... aValues) Clear all elements and add all provided values.default EChangesetAll(Iterable<? extends ELEMENTTYPE> aValues) Clear all elements and add all provided values.default <SRCTYPE> EChangesetAllMapped(Iterable<? extends SRCTYPE> aValues, Function<? super SRCTYPE, ? extends ELEMENTTYPE> aMapper) Clear all elements and add all provided values.default <SRCTYPE> EChangesetAllMapped(SRCTYPE[] aValues, Function<? super SRCTYPE, ? extends ELEMENTTYPE> aMapper) Clear all elements and add all provided values.Methods inherited from interface java.util.Collection
add, addAll, clear, contains, containsAll, equals, hashCode, isEmpty, iterator, parallelStream, remove, removeAll, removeIf, retainAll, size, spliterator, stream, toArray, toArray, toArrayMethods inherited from interface com.helger.commons.collection.impl.ICommonsIterable
containsAny, containsNone, containsOnly, findAll, findAllInstanceOf, findAllMapped, findAllMapped, findAllMapped, findFirst, findFirst, findFirstIndex, findFirstMapped, findFirstMapped, findLastIndex, forEachBreakable, forEachByIndex, forEachThrowing, getCountMethods inherited from interface com.helger.commons.lang.IHasSize
isEmpty, isNotEmpty, size
-
Method Details
-
getCopyAsList
-
getCount
Count the number of elements matching the provided filter.- Specified by:
getCountin interfaceICommonsIterable<ELEMENTTYPE>- Parameters:
aFilter- The filter to be applied. May benull.- Returns:
- The number of elements matching the provided filter or the total number of elements if no filter is provided. Always ≥ 0.
-
getAtIndex
Get the element at the specified index or returnnullupon invalid index.- Parameters:
nIndex- The index to access. Should be ≥ 0.- Returns:
nullif the element cannot be accessed.- See Also:
-
getAtIndex
Get the element at the specified index or return the provided default value upon invalid index.- Parameters:
nIndex- The index to access. Should be ≥ 0.aDefault- The value to be returned, if the index is out of bounds. May benull.- Returns:
- The default parameter if the element cannot be accessed
- See Also:
-
getAtIndex
@Nullable default ELEMENTTYPE getAtIndex(@Nullable Predicate<? super ELEMENTTYPE> aFilter, @Nonnegative int nIndex) Get the element at the specified index counting only elements matching the specified filter. If no filter is provided this call is identical togetAtIndex(int).- Parameters:
aFilter- The filter to be applied. May benull.nIndex- The index to be retrieved. Should be ≥ 0.- Returns:
nullif no matching element could be accessed.- See Also:
-
getAtIndex
@Nullable default ELEMENTTYPE getAtIndex(@Nullable Predicate<? super ELEMENTTYPE> aFilter, @Nonnegative int nIndex, @Nullable ELEMENTTYPE aDefault) Get the element at the specified index counting only elements matching the specified filter or return the provided default value upon invalid index. If no filter is provided this call is identical togetAtIndex(int, Object).- Parameters:
aFilter- The filter to be applied. May benull.nIndex- The index to access. Should be ≥ 0.aDefault- The value to be returned, if the index is out of bounds. May benull.- Returns:
- The default parameter if the element cannot be accessed
- See Also:
-
getAtIndexMapped
@Nullable default <DSTTYPE> DSTTYPE getAtIndexMapped(@Nonnegative int nIndex, @Nonnull Function<? super ELEMENTTYPE, ? extends DSTTYPE> aMapper) Get the element at the specified index or returnnullupon invalid index.- Type Parameters:
DSTTYPE- The destination type to be mapped to- Parameters:
nIndex- The index to access. Should be ≥ 0.aMapper- The mapping function to be executed for the matching element. May not benull.- Returns:
nullif the element cannot be accessed.- See Also:
-
getAtIndexMapped
@Nullable default <DSTTYPE> DSTTYPE getAtIndexMapped(@Nonnegative int nIndex, @Nonnull Function<? super ELEMENTTYPE, ? extends DSTTYPE> aMapper, @Nullable DSTTYPE aDefault) Get the element at the specified index or return the provided default value upon invalid index.- Type Parameters:
DSTTYPE- The destination type to be mapped to- Parameters:
nIndex- The index to access. Should be ≥ 0.aMapper- The mapping function to be executed for the matching element. May not benull.aDefault- The value to be returned, if the index is out of bounds. May benull.- Returns:
- The default parameter if the element cannot be accessed
- See Also:
-
getAtIndexMapped
@Nullable default <DSTTYPE> DSTTYPE getAtIndexMapped(@Nonnull Predicate<? super ELEMENTTYPE> aFilter, @Nonnegative int nIndex, @Nonnull Function<? super ELEMENTTYPE, ? extends DSTTYPE> aMapper) Get the element at the specified index, counting only elements matching the provided filter and map the resulting element using the provided mapper.- Type Parameters:
DSTTYPE- The destination type to be mapped to- Parameters:
aFilter- The filter to be applied. May benull.nIndex- The index to be accessed. Should be ≥ 0.aMapper- The mapping function to be executed for the matching element. May not benull.- Returns:
nullif no such element at the specified index was found.- See Also:
-
getAtIndexMapped
@Nullable default <DSTTYPE> DSTTYPE getAtIndexMapped(@Nonnull Predicate<? super ELEMENTTYPE> aFilter, @Nonnegative int nIndex, @Nonnull Function<? super ELEMENTTYPE, ? extends DSTTYPE> aMapper, @Nullable DSTTYPE aDefault) Get the element at the specified index, counting only elements matching the provided filter and map the resulting element using the provided mapper.- Type Parameters:
DSTTYPE- The destination type to be mapped to- Parameters:
aFilter- The filter to be applied. May benull.nIndex- The index to be accessed. Should be ≥ 0.aMapper- The mapping function to be executed for the matching element. May not benull.aDefault- The default value to be returned if no matching element could be found.- Returns:
- The provided default value if no such element at the specified index was found.
- See Also:
-
getSorted
@Nonnull default ICommonsList<ELEMENTTYPE> getSorted(@Nonnull Comparator<? super ELEMENTTYPE> aComparator) Return a sorted version of this collection. The default implementation returns a copy of this collection as aCommonsArrayListand sort this list.- Parameters:
aComparator- The comparator used for sorting. May not benull.- Returns:
- A non-
nulllist of element. Nevernull.
-
addObject
add the provided element to the collection usingCollection.add(Object)but returning a more structured return value.- Parameters:
aElement- The element to be add. May benull.- Returns:
EChange.CHANGEDif the element was added successfully,EChange.UNCHANGEDotherwise (e.g. because if is already contained).- See Also:
-
addIf
@Nonnull default EChange addIf(@Nullable ELEMENTTYPE aElement, @Nullable Predicate<? super ELEMENTTYPE> aFilter) Add the passed element to this collection if passed predicate is fulfilled- Parameters:
aElement- The element to be added. May benull.aFilter- The predicate to be executed. May not benull.- Returns:
EChange.CHANGEDif the element was added,EChange.UNCHANGEDotherwise.- See Also:
-
addIfNotNull
Add the passed element to this collection if it is non-null. This is an optimized version foraddIf(Object, Predicate)with the fixed predicate of!= null.- Parameters:
aElement- The element to be added if non-null.- Returns:
EChange.CHANGEDif the element was added,EChange.UNCHANGEDotherwise.- See Also:
-
addAll
Add an array of elements to this collection.- Parameters:
aElements- The elements to be added. May benull.- Returns:
EChange.CHANGEDif at least one element was added,EChange.UNCHANGED. Nevernull.
-
addAll
Add all elements of the passed iterable to this collection.- Parameters:
aElements- The elements to be added. May benull.- Returns:
EChange.CHANGEDif at least one element was added,EChange.UNCHANGED. Nevernull.
-
addAll
Add all elements of the passed enumeration to this collection.- Parameters:
aEnum- The enumeration to be iterated and the elements to be added. May benull.- Returns:
EChange.CHANGEDif at least one element was added,EChange.UNCHANGED. Nevernull.
-
addAll
Add all elements of the passed iterator to this collection.- Parameters:
aIter- The iterator to be iterated and the elements to be added. May benull.- Returns:
EChange.CHANGEDif at least one element was added,EChange.UNCHANGED. Nevernull.
-
addAll
@Nonnull default EChange addAll(@Nullable ELEMENTTYPE[] aElements, @Nullable Predicate<? super ELEMENTTYPE> aFilter) Add all matching elements of an array this collection.- Parameters:
aElements- The elements to be added. May benull.aFilter- The filter to be applied. May benull.- Returns:
EChange.CHANGEDif at least one element was added,EChange.UNCHANGED. Nevernull.- Since:
- 8.5.2
-
addAll
@Nonnull default EChange addAll(@Nullable Iterable<? extends ELEMENTTYPE> aElements, @Nullable Predicate<? super ELEMENTTYPE> aFilter) Add all elements of the passed iterable to this collection.- Parameters:
aElements- The elements to be added. May benull.aFilter- The filter to be applied. May benull.- Returns:
EChange.CHANGEDif at least one element was added,EChange.UNCHANGED. Nevernull.- Since:
- 8.5.2
-
addAll
@Nonnull default EChange addAll(@Nullable Enumeration<? extends ELEMENTTYPE> aEnum, @Nullable Predicate<? super ELEMENTTYPE> aFilter) Add all elements of the passed enumeration to this collection.- Parameters:
aEnum- The enumeration to be iterated and the elements to be added. May benull.aFilter- The filter to be applied. May benull.- Returns:
EChange.CHANGEDif at least one element was added,EChange.UNCHANGED. Nevernull.- Since:
- 8.5.2
-
addAll
@Nonnull default EChange addAll(@Nullable Iterator<? extends ELEMENTTYPE> aIter, @Nullable Predicate<? super ELEMENTTYPE> aFilter) Add all elements of the passed iterator to this collection.- Parameters:
aIter- The iterator to be iterated and the elements to be added. May benull.aFilter- The filter to be applied. May benull.- Returns:
EChange.CHANGEDif at least one element was added,EChange.UNCHANGED. Nevernull.- Since:
- 8.5.2
-
addAllMapped
@Nonnull default <SRCTYPE> EChange addAllMapped(@Nullable Iterable<? extends SRCTYPE> aElements, @Nonnull Function<? super SRCTYPE, ? extends ELEMENTTYPE> aMapper) Add all passed elements after performing a mapping using the provided function.- Type Parameters:
SRCTYPE- The source type to be mapped from- Parameters:
aElements- The elements to be added after mapping. May benull.aMapper- The mapping function to be executed for all provided elements. May not benull.- Returns:
EChange.CHANGEDif at least one element was added,EChange.UNCHANGED. Nevernull.
-
addAllMapped
@Nonnull default <SRCTYPE> EChange addAllMapped(@Nullable SRCTYPE[] aElements, @Nonnull Function<? super SRCTYPE, ? extends ELEMENTTYPE> aMapper) Add all passed elements after performing a mapping using the provided function.- Type Parameters:
SRCTYPE- The source type to be mapped from- Parameters:
aElements- The elements to be added after mapping. May benull.aMapper- The mapping function to be executed for all provided elements. May not benull.- Returns:
EChange.CHANGEDif at least one element was added,EChange.UNCHANGED. Nevernull.
-
addAllMapped
@Nonnull default <SRCTYPE> EChange addAllMapped(@Nullable Iterable<? extends SRCTYPE> aElements, @Nullable Predicate<? super SRCTYPE> aFilter, @Nonnull Function<? super SRCTYPE, ? extends ELEMENTTYPE> aMapper) Add all passed elements matching the provided filter after performing a mapping using the provided function.- Type Parameters:
SRCTYPE- The source type to be mapped from- Parameters:
aElements- The elements to be added after mapping. May benull.aFilter- The filter to be applied. May benull.aMapper- The mapping function to be executed for all provided elements. May not benull.- Returns:
EChange.CHANGEDif at least one element was added,EChange.UNCHANGED. Nevernull.
-
addAllMapped
@Nonnull default <SRCTYPE> EChange addAllMapped(@Nullable SRCTYPE[] aElements, @Nullable Predicate<? super SRCTYPE> aFilter, @Nonnull Function<? super SRCTYPE, ? extends ELEMENTTYPE> aMapper) Add all passed elements matching the provided filter after performing a mapping using the provided function.- Type Parameters:
SRCTYPE- The source type to be mapped from- Parameters:
aElements- The elements to be added after mapping. May benull.aFilter- The filter to be applied. May benull.aMapper- The mapping function to be executed for all provided elements. May not benull.- Returns:
EChange.CHANGEDif at least one element was added,EChange.UNCHANGED. Nevernull.
-
addAllMapped
@Nonnull default <SRCTYPE> EChange addAllMapped(@Nullable Iterable<? extends SRCTYPE> aElements, @Nonnull Function<? super SRCTYPE, ? extends ELEMENTTYPE> aMapper, @Nullable Predicate<? super ELEMENTTYPE> aFilter) Add all passed elements matching the provided filter after performing a mapping using the provided function.- Type Parameters:
SRCTYPE- The source type to be mapped from- Parameters:
aElements- The elements to be added after mapping. May benull.aMapper- The mapping function to be executed for all provided elements. May not benull.aFilter- The filter to be applied on the mapped element. May benull.- Returns:
EChange.CHANGEDif at least one element was added,EChange.UNCHANGED. Nevernull.- Since:
- 8.5.2
-
addAllMapped
@Nonnull default <SRCTYPE> EChange addAllMapped(@Nullable SRCTYPE[] aElements, @Nonnull Function<? super SRCTYPE, ? extends ELEMENTTYPE> aMapper, @Nullable Predicate<? super ELEMENTTYPE> aFilter) Add all passed elements matching the provided filter after performing a mapping using the provided function.- Type Parameters:
SRCTYPE- The source type to be mapped from- Parameters:
aElements- The elements to be added after mapping. May benull.aMapper- The mapping function to be executed for all provided elements. May not benull.aFilter- The filter to be applied on the mapped element. May benull.- Returns:
EChange.CHANGEDif at least one element was added,EChange.UNCHANGED. Nevernull.- Since:
- 8.5.2
-
set
Clear all elements and add only the passed value.- Parameters:
aValue- The value to be added. May benull.- Returns:
EChange.CHANGEDif something was changed,EChange.UNCHANGEDotherwise.- See Also:
-
setAll
Clear all elements and add all provided values. If no value is provided, the collection is empty afterwards.- Parameters:
aValues- The values to be added. May benull.- Returns:
EChange.CHANGEDif something was changed,EChange.UNCHANGEDotherwise.- See Also:
-
setAll
Clear all elements and add all provided values. If no value is provided, the collection is empty afterwards.- Parameters:
aValues- The values to be added. May benull.- Returns:
EChange.CHANGEDif something was changed,EChange.UNCHANGEDotherwise.- See Also:
-
setAllMapped
@Nonnull default <SRCTYPE> EChange setAllMapped(@Nullable Iterable<? extends SRCTYPE> aValues, @Nonnull Function<? super SRCTYPE, ? extends ELEMENTTYPE> aMapper) Clear all elements and add all provided values. If no value is provided, the collection is empty afterwards.- Type Parameters:
SRCTYPE- The source type to be mapped from- Parameters:
aValues- The values to be added. May benull.aMapper- The mapping function to be executed for all provided elements. May not benull.- Returns:
EChange.CHANGEDif something was changed,EChange.UNCHANGEDotherwise.- Since:
- 9.1.0
- See Also:
-
setAllMapped
@Nonnull default <SRCTYPE> EChange setAllMapped(@Nullable SRCTYPE[] aValues, @Nonnull Function<? super SRCTYPE, ? extends ELEMENTTYPE> aMapper) Clear all elements and add all provided values. If no value is provided, the collection is empty afterwards.- Type Parameters:
SRCTYPE- The source type to be mapped from- Parameters:
aValues- The values to be added. May benull.aMapper- The mapping function to be executed for all provided elements. May not benull.- Returns:
EChange.CHANGEDif something was changed,EChange.UNCHANGEDotherwise.- Since:
- 9.1.0
- See Also:
-
removeAll
Remove all elements from this collection. This is similar toCollection.clear()but it returns a different value whether something was cleared or not.- Returns:
EChange.CHANGEDif the collection was not empty and something was removed,EChange.UNCHANGEDotherwise.- See Also:
-
removeObject
Remove the provided element from the collection usingCollection.remove(Object)but returning a more structured return value.- Parameters:
aElement- The element to be removed. May benull.- Returns:
EChange.CHANGEDif the element was removed successfully,EChange.UNCHANGEDotherwise.- See Also:
-
getAsUnmodifiable
- Returns:
- An unmodifiable version of this collection. Never
null. - See Also:
-
iterator2
- Returns:
- An iterable iterator on this collection. This is similar to
Collection.iterator()but the returned type is more flexible. Nevernull. - See Also:
-