Package de.alpharogroup.collections.list
Class OptionalListExtensions
- java.lang.Object
-
- de.alpharogroup.collections.list.OptionalListExtensions
-
public class OptionalListExtensions extends java.lang.ObjectExtensions class for use withListobjects
-
-
Constructor Summary
Constructors Constructor Description OptionalListExtensions()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <T> java.util.Optional<T>getFirst(@NonNull java.util.List<T> list)Returns anOptionalwith the first object from the givenListstatic <T> java.util.Optional<T>getLast(@NonNull java.util.List<T> list)Returns anOptionalwith the last object from the givenListstatic <T> java.util.Optional<T>getNext(@NonNull java.util.List<T> list, T element)Gets the next element from the givenList.static <T> java.util.Optional<T>getPrevious(@NonNull java.util.List<T> list, T element)Gets the previous element from the givenList.static <T> java.util.Optional<T>removeFirst(@NonNull java.util.List<T> list)Returns anOptionalwith the first object if it was removed from the givenListstatic <T> java.util.Optional<T>removeLast(@NonNull java.util.List<T> list)Returns anOptionalwith the last object if it was removed from the givenList
-
-
-
Method Detail
-
getFirst
public static <T> java.util.Optional<T> getFirst(@NonNull @NonNull java.util.List<T> list)Returns anOptionalwith the first object from the givenList- Type Parameters:
T- the generic type of the elements- Parameters:
list- theListobject- Returns:
- an
Optionalwith the first object from the givenListor an emptyOptionalif the List is empty
-
getLast
public static <T> java.util.Optional<T> getLast(@NonNull @NonNull java.util.List<T> list)Returns anOptionalwith the last object from the givenList- Type Parameters:
T- the generic type of the elements- Parameters:
list- theListobject- Returns:
- an
Optionalwith the last object from the givenListor an emptyOptionalif the List is empty
-
removeFirst
public static <T> java.util.Optional<T> removeFirst(@NonNull @NonNull java.util.List<T> list)Returns anOptionalwith the first object if it was removed from the givenList- Type Parameters:
T- the generic type of the elements- Parameters:
list- theListobject- Returns:
- returns an
Optionalwith the first object if it was removed from the givenListor an emptyOptionalif theListis empty
-
removeLast
public static <T> java.util.Optional<T> removeLast(@NonNull @NonNull java.util.List<T> list)Returns anOptionalwith the last object if it was removed from the givenList- Type Parameters:
T- the generic type of the elements- Parameters:
list- theListobject- Returns:
- returns an
Optionalwith the last object if it was removed from the givenListor an emptyOptionalif theListis empty
-
getPrevious
public static <T> java.util.Optional<T> getPrevious(@NonNull @NonNull java.util.List<T> list, T element)Gets the previous element from the givenList. As start point is the given element- Type Parameters:
T- the generic type of elements- Parameters:
list- the listelement- the element- Returns:
- an
Optionalwith the previous element from the givenListor an emptyOptionalif theListhas no previous element
-
getNext
public static <T> java.util.Optional<T> getNext(@NonNull @NonNull java.util.List<T> list, T element)Gets the next element from the givenList. As start point is the given element- Type Parameters:
T- the generic type of elements- Parameters:
list- the listelement- the element- Returns:
- an
Optionalwith the next element from the givenListor an emptyOptionalif theListhas no next element
-
-