Class SamePair<T>

java.lang.Object
com.yetnt.utils.tuple.Pair<T,T>
com.yetnt.utils.tuple.SamePair<T>
Type Parameters:
T - The type of both elements in the pair.

public class SamePair<T> extends Pair<T,T>
A specialized Pair where both elements are of the same type.

From Jaiva!

Author:
Lehlogonolo Poole
See Also:
  • Field Summary

    Fields inherited from class com.yetnt.utils.tuple.Pair

    first, second
  • Constructor Summary

    Constructors
    Constructor
    Description
    SamePair(T first, T second)
    Constructs a new SamePair with the given first and second elements.
  • Method Summary

    Modifier and Type
    Method
    Description
    static <T> SamePair<T>
    from(Pair<T,T> samePair)
    Creates a new SamePair from a Pair who's already defined as having the same types.
    <U> SamePair<U>
    map(Function<T,U> function)
    Applies a given mapping function to each element of this SamePair, returning a new SamePair with the transformed elements.
    <U> U
    mapTo(BiFunction<T,T,U> function)
    Applies the given function to the SamePair to return a single value.

    Methods inherited from class com.yetnt.utils.tuple.Pair

    equals, getFirst, getSecond, hashCode, toString

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • SamePair

      public SamePair(T first, T second)
      Constructs a new SamePair with the given first and second elements.
      Parameters:
      first - The first element of the pair.
      second - The second element of the pair.
  • Method Details

    • from

      public static <T> SamePair<T> from(Pair<T,T> samePair)
      Creates a new SamePair from a Pair who's already defined as having the same types.
      Type Parameters:
      T - The type the original pair has in both fields.
      Parameters:
      samePair - The pair
      Returns:
      A new same pair
    • map

      public <U> SamePair<U> map(Function<T,U> function)
      Applies a given mapping function to each element of this SamePair, returning a new SamePair with the transformed elements.
      Type Parameters:
      U - The type of the elements in the new SamePair after mapping.
      Parameters:
      function - The function to apply to each element.
      Returns:
      A new SamePair containing the results of applying the mapper function to each element.
    • mapTo

      public <U> U mapTo(BiFunction<T,T,U> function)
      Applies the given function to the SamePair to return a single value.
      Type Parameters:
      U - The type of the single value to return
      Parameters:
      function - The mapper function
      Returns:
      A single value