Class OperationUtils


  • public class OperationUtils
    extends Object
    Since:
    4.0.0
    Author:
    Florian Kleedorfer
    • Constructor Detail

      • OperationUtils

        public OperationUtils()
    • Method Detail

      • atMostOne

        public static <T> Optional<T> atMostOne​(Collection<T> objects)
        Returns the object in the Collection wrapped in an Optional, an empty Optional if the collection is empty, throwing an Exception if the Collection contains more than one element.
      • require

        public static <T> T require​(Optional<T> required)
        Returns the object contained in the specified Optional, throwing an Exception if it is empty.
      • exactlyOne

        public static <T> T exactlyOne​(Collection<T> objects)
        Returns the element in the Collection, throwing an exception if the collection is empty or contains more than one element.
      • toSingleton

        public static <T> Collector<T,​?,​T> toSingleton()
        Returns the element in the Stream, throwing an exception if the stream is empty or contains more than one element.
      • toSingletonMaybe

        public static <T> Collector<T,​?,​T> toSingletonMaybe()
        Returns the element in the Stream, or null if the stream is empty, throwing an exception if the stream contains more than one element.
      • toSingletonOptional

        public static <T> Collector<T,​?,​Optional<T>> toSingletonOptional()
        Returns the element in the Stream wrapped in an Optional throwing an exception if the stream contains more than one element.