Class OptionalListExtensions


  • public class OptionalListExtensions
    extends java.lang.Object
    Extensions class for use with List objects
    • 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 an Optional with the first object from the given List
      static <T> java.util.Optional<T> getLast​(@NonNull java.util.List<T> list)
      Returns an Optional with the last object from the given List
      static <T> java.util.Optional<T> getNext​(@NonNull java.util.List<T> list, T element)
      Gets the next element from the given List.
      static <T> java.util.Optional<T> getPrevious​(@NonNull java.util.List<T> list, T element)
      Gets the previous element from the given List.
      static <T> java.util.Optional<T> removeFirst​(@NonNull java.util.List<T> list)
      Returns an Optional with the first object if it was removed from the given List
      static <T> java.util.Optional<T> removeLast​(@NonNull java.util.List<T> list)
      Returns an Optional with the last object if it was removed from the given List
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • OptionalListExtensions

        public OptionalListExtensions()
    • Method Detail

      • getFirst

        public static <T> java.util.Optional<T> getFirst​(@NonNull
                                                         @NonNull java.util.List<T> list)
        Returns an Optional with the first object from the given List
        Type Parameters:
        T - the generic type of the elements
        Parameters:
        list - the List object
        Returns:
        an Optional with the first object from the given List or an empty Optional if the List is empty
      • getLast

        public static <T> java.util.Optional<T> getLast​(@NonNull
                                                        @NonNull java.util.List<T> list)
        Returns an Optional with the last object from the given List
        Type Parameters:
        T - the generic type of the elements
        Parameters:
        list - the List object
        Returns:
        an Optional with the last object from the given List or an empty Optional if the List is empty
      • removeFirst

        public static <T> java.util.Optional<T> removeFirst​(@NonNull
                                                            @NonNull java.util.List<T> list)
        Returns an Optional with the first object if it was removed from the given List
        Type Parameters:
        T - the generic type of the elements
        Parameters:
        list - the List object
        Returns:
        returns an Optional with the first object if it was removed from the given List or an empty Optional if the List is empty
      • removeLast

        public static <T> java.util.Optional<T> removeLast​(@NonNull
                                                           @NonNull java.util.List<T> list)
        Returns an Optional with the last object if it was removed from the given List
        Type Parameters:
        T - the generic type of the elements
        Parameters:
        list - the List object
        Returns:
        returns an Optional with the last object if it was removed from the given List or an empty Optional if the List is 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 given List. As start point is the given element
        Type Parameters:
        T - the generic type of elements
        Parameters:
        list - the list
        element - the element
        Returns:
        an Optional with the previous element from the given List or an empty Optional if the List has 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 given List. As start point is the given element
        Type Parameters:
        T - the generic type of elements
        Parameters:
        list - the list
        element - the element
        Returns:
        an Optional with the next element from the given List or an empty Optional if the List has no next element