Module de.carne

Class Unique<T,​R>

  • Type Parameters:
    T - the actual stream element type.
    R - the actual result type (either T or Optional<T>).
    All Implemented Interfaces:
    java.util.stream.Collector<T,​de.carne.util.stream.UniqueLatch<T>,​R>

    public final class Unique<T,​R>
    extends java.lang.Object
    implements java.util.stream.Collector<T,​de.carne.util.stream.UniqueLatch<T>,​R>
    Collector implementation ensuring a one element collection at the end of a stream operation.
    • Nested Class Summary

      • Nested classes/interfaces inherited from interface java.util.stream.Collector

        java.util.stream.Collector.Characteristics
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.util.function.BiConsumer<de.carne.util.stream.UniqueLatch<T>,​T> accumulator()  
      java.util.Set<java.util.stream.Collector.Characteristics> characteristics()  
      java.util.function.BinaryOperator<de.carne.util.stream.UniqueLatch<T>> combiner()  
      java.util.function.Function<de.carne.util.stream.UniqueLatch<T>,​R> finisher()  
      static <T> Unique<T,​T> get()
      Collects and gets the unique result element.
      static <T> Unique<T,​java.util.Optional<T>> getOptional()
      Collects and gets the unique result element as an Optional.
      java.util.function.Supplier<de.carne.util.stream.UniqueLatch<T>> supplier()  
      • Methods inherited from class java.lang.Object

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

      • get

        public static <T> Unique<T,​T> get()
        Collects and gets the unique result element.
        Type Parameters:
        T - the actual result type.
        Returns:
        the unique result element.
        Throws:
        java.util.NoSuchElementException - if the stream operation result contains zero or more than one element.
      • getOptional

        public static <T> Unique<T,​java.util.Optional<T>> getOptional()
        Collects and gets the unique result element as an Optional.
        Type Parameters:
        T - the actual result type.
        Returns:
        the unique result element.
      • supplier

        public java.util.function.Supplier<de.carne.util.stream.UniqueLatch<T>> supplier()
        Specified by:
        supplier in interface java.util.stream.Collector<T,​de.carne.util.stream.UniqueLatch<T>,​R>
      • accumulator

        public java.util.function.BiConsumer<de.carne.util.stream.UniqueLatch<T>,​T> accumulator()
        Specified by:
        accumulator in interface java.util.stream.Collector<T,​de.carne.util.stream.UniqueLatch<T>,​R>
      • combiner

        public java.util.function.BinaryOperator<de.carne.util.stream.UniqueLatch<T>> combiner()
        Specified by:
        combiner in interface java.util.stream.Collector<T,​de.carne.util.stream.UniqueLatch<T>,​R>
      • finisher

        public java.util.function.Function<de.carne.util.stream.UniqueLatch<T>,​R> finisher()
        Specified by:
        finisher in interface java.util.stream.Collector<T,​de.carne.util.stream.UniqueLatch<T>,​R>
      • characteristics

        public java.util.Set<java.util.stream.Collector.Characteristics> characteristics()
        Specified by:
        characteristics in interface java.util.stream.Collector<T,​de.carne.util.stream.UniqueLatch<T>,​R>