Class Pair<L,​R>

  • Type Parameters:
    L - Left value type.
    R - Right value type.
    All Implemented Interfaces:
    java.util.Map.Entry<L,​R>

    public final class Pair<L,​R>
    extends java.lang.Object
    implements java.util.Map.Entry<L,​R>
    Generic immutable pair of values.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      L left  
      R right  
    • Constructor Summary

      Constructors 
      Constructor Description
      Pair​(L left, R right)  
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean equals​(java.lang.Object o)  
      static <L,​R>
      java.util.stream.Stream<Pair<L,​R>>
      flatMapStream​(L left, java.util.function.Function<L,​java.util.Optional<R>> f)
      Creates a Stream of zero or one Pairs if the mapping function returns a non-empty Optional.
      static <L,​R>
      java.util.stream.Stream<Pair<L,​R>>
      flatMapStream​(L left, java.util.function.Supplier<java.util.Optional<R>> f)  
      L getKey()  
      L getLeft()  
      R getRight()  
      R getValue()  
      int hashCode()  
      static <L,​R>
      Pair<L,​R>
      of​(L left, R right)
      Creates a Pair from the given values.
      R setValue​(R value)  
      java.lang.String toString()  
      • Methods inherited from class java.lang.Object

        clone, finalize, getClass, notify, notifyAll, wait, wait, wait
    • Field Detail

      • left

        public final L left
      • right

        public final R right
    • Constructor Detail

      • Pair

        public Pair​(L left,
                    R right)
    • Method Detail

      • of

        public static <L,​R> Pair<L,​R> of​(L left,
                                                     R right)
        Creates a Pair from the given values.
        Type Parameters:
        L - Left value type.
        R - Right value type.
        Parameters:
        left - Left value.
        right - Right value.
        Returns:
        Returns the created Pair.
      • flatMapStream

        public static <L,​R> java.util.stream.Stream<Pair<L,​R>> flatMapStream​(L left,
                                                                                         java.util.function.Function<L,​java.util.Optional<R>> f)
        Creates a Stream of zero or one Pairs if the mapping function returns a non-empty Optional.
        Type Parameters:
        L - Left value type.
        R - Right value type.
        Parameters:
        left - Value to set as the left side of the pair.
        f - Mapping function that accepts the left value and returns an Optional value.
        Returns:
        Returns a Stream that contains either a single Pair if the Optional is not empty, or an empty Stream.
      • flatMapStream

        public static <L,​R> java.util.stream.Stream<Pair<L,​R>> flatMapStream​(L left,
                                                                                         java.util.function.Supplier<java.util.Optional<R>> f)
      • getLeft

        public L getLeft()
      • getRight

        public R getRight()
      • getKey

        public L getKey()
        Specified by:
        getKey in interface java.util.Map.Entry<L,​R>
      • getValue

        public R getValue()
        Specified by:
        getValue in interface java.util.Map.Entry<L,​R>
      • setValue

        public R setValue​(R value)
        Specified by:
        setValue in interface java.util.Map.Entry<L,​R>
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • equals

        public boolean equals​(java.lang.Object o)
        Specified by:
        equals in interface java.util.Map.Entry<L,​R>
        Overrides:
        equals in class java.lang.Object
      • hashCode

        public int hashCode()
        Specified by:
        hashCode in interface java.util.Map.Entry<L,​R>
        Overrides:
        hashCode in class java.lang.Object