Interface ICommonsList<ELEMENTTYPE>
- Type Parameters:
ELEMENTTYPE- The data type of the elements in the list.
- All Superinterfaces:
Collection<ELEMENTTYPE>,ICloneable<ICommonsList<ELEMENTTYPE>>,ICommonsCollection<ELEMENTTYPE>,ICommonsIterable<ELEMENTTYPE>,IHasSize,Iterable<ELEMENTTYPE>,List<ELEMENTTYPE>,SequencedCollection<ELEMENTTYPE>
- All Known Subinterfaces:
IErrorList
- All Known Implementing Classes:
CommonsArrayList,CommonsCopyOnWriteArrayList,CommonsLinkedList,CommonsVector,ErrorList,NonBlockingStack,URLParameterList
public interface ICommonsList<ELEMENTTYPE>
extends List<ELEMENTTYPE>, ICommonsCollection<ELEMENTTYPE>, ICloneable<ICommonsList<ELEMENTTYPE>>
A special
List interface with extended functionality based on
ICommonsCollection.- Author:
- Philip Helger
-
Method Summary
Modifier and TypeMethodDescriptiondefault <T> ICommonsList<T> Create a new empty list.default ICommonsList<ELEMENTTYPE> getAll(Predicate<? super ELEMENTTYPE> aFilter) Get all elements matching the provided filter.default <DSTTYPE extends ELEMENTTYPE>
ICommonsList<DSTTYPE> getAllInstanceOf(Class<DSTTYPE> aDstClass) Get all instances of the provided class that are contained in this list.default <DSTTYPE> ICommonsList<DSTTYPE> getAllMapped(Function<? super ELEMENTTYPE, DSTTYPE> aMapper) Create a new list where all existing elements are mapped with the provided function.default <DSTTYPE> ICommonsList<DSTTYPE> getAllMapped(Predicate<? super ELEMENTTYPE> aFilter, Function<? super ELEMENTTYPE, DSTTYPE> aMapper) Create a new list where all elements matching the filter are mapped with the provided function.default List<ELEMENTTYPE> default ELEMENTTYPEgetAtIndex(int nIndex, ELEMENTTYPE aDefault) Get the element at the specified index or return the provided default value upon invalid index.default ELEMENTTYPEgetFirst()Deprecated, for removal: This API element is subject to removal in a future version.default ELEMENTTYPEgetFirst(ELEMENTTYPE aDefault) default ELEMENTTYPEdefault ELEMENTTYPEgetLast()Deprecated, for removal: This API element is subject to removal in a future version.UsegetLastOrNull()insteaddefault ELEMENTTYPEgetLast(ELEMENTTYPE aDefault) default ELEMENTTYPEdefault ICommonsList<ELEMENTTYPE> getSortedInline(Comparator<? super ELEMENTTYPE> aComparator) Sort this line without creating a copy.default ELEMENTTYPEremoveAndReturnElementAtIndex(int nIndex) Remove the element at the specified index from the passed list.default EChangeremoveAtIndex(int nIndex) Remove the element at the specified index from the passed list.default ELEMENTTYPEDeprecated, for removal: This API element is subject to removal in a future version.UseremoveFirstOrNull()insteaddefault ELEMENTTYPERemove the first element of the list.default ELEMENTTYPEDeprecated, for removal: This API element is subject to removal in a future version.default ELEMENTTYPERemove the last element of the list.default ICommonsList<ELEMENTTYPE> reverse()Reverse the order of this list.default ELEMENTTYPEsetFirst(ELEMENTTYPE aNewElement) Set the first element of this list.default ELEMENTTYPEsetLast(ELEMENTTYPE aNewElement) Set the last element of this list.default ICommonsList<ELEMENTTYPE> swapItems(int nFirstIndex, int nSecondIndex) Swap list items.Methods inherited from interface java.util.Collection
parallelStream, removeIf, stream, toArrayMethods inherited from interface com.helger.commons.lang.ICloneable
getCloneMethods inherited from interface com.helger.commons.collection.impl.ICommonsCollection
addAll, addAll, addAll, addAll, addAll, addAll, addAll, addAll, addAllMapped, addAllMapped, addAllMapped, addAllMapped, addAllMapped, addAllMapped, addIf, addIfNotNull, addObject, getAtIndex, getAtIndex, getAtIndex, getAtIndexMapped, getAtIndexMapped, getAtIndexMapped, getAtIndexMapped, getCopyAsList, getCount, getSorted, iterator2, removeAll, removeObject, set, setAll, setAll, setAllMapped, setAllMappedMethods 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, sizeMethods inherited from interface java.util.List
add, add, addAll, addAll, addFirst, addLast, clear, contains, containsAll, equals, get, hashCode, indexOf, isEmpty, iterator, lastIndexOf, listIterator, listIterator, remove, remove, removeAll, replaceAll, retainAll, reversed, set, size, sort, spliterator, subList, toArray, toArray
-
Method Details
-
createInstance
Create a new empty list. Overwrite this if you don't want to useCommonsArrayList.- Type Parameters:
T- List element type- Returns:
- A new empty list. Never
null.
-
getAll
@Nonnull @ReturnsMutableCopy default ICommonsList<ELEMENTTYPE> getAll(@Nullable Predicate<? super ELEMENTTYPE> aFilter) Get all elements matching the provided filter. If no filter is provided, the return value is same asICloneable.getClone().- Parameters:
aFilter- The filter to be applied. May benull.- Returns:
- A non-
nullcopy of this list containing all matching entries (or all entries if no filter is provided). - See Also:
-
getAllMapped
@Nonnull @ReturnsMutableCopy default <DSTTYPE> ICommonsList<DSTTYPE> getAllMapped(@Nonnull Function<? super ELEMENTTYPE, DSTTYPE> aMapper) Create a new list where all existing elements are mapped with the provided function.- Type Parameters:
DSTTYPE- The destination type to be mapped to- Parameters:
aMapper- The mapping function to be executed. May not benull.- Returns:
- A new non-
nulllist with all mapped elements. - See Also:
-
getAllMapped
@Nonnull @ReturnsMutableCopy default <DSTTYPE> ICommonsList<DSTTYPE> getAllMapped(@Nullable Predicate<? super ELEMENTTYPE> aFilter, @Nonnull Function<? super ELEMENTTYPE, DSTTYPE> aMapper) Create a new list where all elements matching the filter are mapped with the provided function.- Type Parameters:
DSTTYPE- The destination type to be mapped to- Parameters:
aFilter- The filter to be applied. Maybenull.aMapper- The mapping function to be executed. May not benull.- Returns:
- A new non-
nulllist with all mapped elements. If no filter is provided the result is the same as ofgetAllMapped(Function). - See Also:
-
getAllInstanceOf
@Nonnull @ReturnsMutableCopy default <DSTTYPE extends ELEMENTTYPE> ICommonsList<DSTTYPE> getAllInstanceOf(@Nonnull Class<DSTTYPE> aDstClass) Get all instances of the provided class that are contained in this list.- Type Parameters:
DSTTYPE- The destination type to be casted to- Parameters:
aDstClass- The class to search all instances of. May not benull.- Returns:
- A list with all instances of the provided class, already casted.
Never
null. - See Also:
-
getFirst
Deprecated, for removal: This API element is subject to removal in a future version.UsegetFirstOrNull()insteadNote: this methods conflicts with a method added in Java SE 21 in class ArrayList. ThereforegetFirstOrNull()should be used instead.- Specified by:
getFirstin interfaceList<ELEMENTTYPE>- Specified by:
getFirstin interfaceSequencedCollection<ELEMENTTYPE>- Returns:
- The first element of the list or
nullif the list is empty. - See Also:
-
getFirstOrNull
- Returns:
- The first element of the list or
nullif the list is empty. - Since:
- 11.1.5
- See Also:
-
getFirst
- Parameters:
aDefault- The default value to be returned if this list is empty. May benull.- Returns:
- The first element of the list or the provided default value if the list is empty.
- See Also:
-
getLast
Deprecated, for removal: This API element is subject to removal in a future version.UsegetLastOrNull()insteadNote: this methods conflicts with a method added in Java SE 21 in class ArrayList. ThereforegetLastOrNull()should be used instead.- Specified by:
getLastin interfaceList<ELEMENTTYPE>- Specified by:
getLastin interfaceSequencedCollection<ELEMENTTYPE>- Returns:
- The last element of the list or
nullif the list is empty. - See Also:
-
getLastOrNull
- Returns:
- The last element of the list or
nullif the list is empty. - Since:
- 11.1.5
- See Also:
-
getLast
- Parameters:
aDefault- The default value to be returned if this list is empty. May benull.- Returns:
- The last element of the list or
nullif the list is empty. - See Also:
-
getAtIndex
Description copied from interface:ICommonsCollectionGet the element at the specified index or return the provided default value upon invalid index.- Specified by:
getAtIndexin interfaceICommonsCollection<ELEMENTTYPE>- 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:
-
setFirst
Set the first element of this list.- Parameters:
aNewElement- The new element at index 0.- Returns:
- The previous element. May be
null. - See Also:
-
setLast
Set the last element of this list.- Parameters:
aNewElement- The new element at indexsize()-1.- Returns:
- The previous element. May be
null. - See Also:
-
removeAtIndex
Remove the element at the specified index from the passed list. This works if the list is notnulland the index is ≥ 0 and <list.size()- Parameters:
nIndex- The index to be removed. May be arbitrary.- Returns:
EChange.CHANGEDif removal was successful- See Also:
-
removeAndReturnElementAtIndex
Remove the element at the specified index from the passed list. This works if the list is notnulland the index is ≥ 0 and <list.size()- Parameters:
nIndex- The index to be removed. May be arbitrary.- Returns:
nullif removal failed or the removed element. Note: the removed element may also benullso it may be tricky to determine if removal succeeded or not!- See Also:
-
removeFirst
Deprecated, for removal: This API element is subject to removal in a future version.UseremoveFirstOrNull()insteadRemove the first element of the list.
Note: this methods conflicts with a method added in Java SE 21 in class ArrayList. ThereforeremoveFirstOrNull()should be used instead.- Specified by:
removeFirstin interfaceList<ELEMENTTYPE>- Specified by:
removeFirstin interfaceSequencedCollection<ELEMENTTYPE>- Returns:
nullif the list is empty or the previously contained element at index 0.
-
removeFirstOrNull
Remove the first element of the list.- Returns:
nullif the list is empty or the previously contained element at index 0.- Since:
- 11.1.5
-
removeLast
Deprecated, for removal: This API element is subject to removal in a future version.Remove the last element of the list.
Note: this methods conflicts with a method added in Java SE 21 in class ArrayList. ThereforeremoveLastOrNull()should be used instead.- Specified by:
removeLastin interfaceList<ELEMENTTYPE>- Specified by:
removeLastin interfaceSequencedCollection<ELEMENTTYPE>- Returns:
nullif the list is empty or the previously contained element at indexsize()-1.
-
removeLastOrNull
Remove the last element of the list.- Returns:
nullif the list is empty or the previously contained element at indexsize()-1.- Since:
- 11.1.5
-
getAsUnmodifiable
- Specified by:
getAsUnmodifiablein interfaceICommonsCollection<ELEMENTTYPE>- Returns:
- An unmodifiable version of this collection. Never
null. - See Also:
-
getSortedInline
@Nonnull default ICommonsList<ELEMENTTYPE> getSortedInline(@Nonnull Comparator<? super ELEMENTTYPE> aComparator) Sort this line without creating a copy.- Parameters:
aComparator- The comparator used for sorting. May not benull.- Returns:
- this for chaining
-
reverse
Reverse the order of this list.- Returns:
- this for chaining
-
swapItems
Swap list items.- Parameters:
nFirstIndex- The first index to swap.nSecondIndex- The second index to swap.- Returns:
- this for chaining
- Since:
- 8.6.0
-
getFirstOrNull()instead