Class Pair<L,R>

java.lang.Object
com.landawn.abacus.util.Pair<L,R>
Type Parameters:
L -
R -
All Implemented Interfaces:
Mutable

public final class Pair<L,R> extends Object implements Mutable
Since:
0.8
Author:
Haiyang Li
  • Field Details

    • left

      public L left
  • Constructor Details

    • Pair

      public Pair()
  • Method Details

    • of

      public static <L, R> Pair<L,R> of(L l, R r)
      Type Parameters:
      L -
      R -
      Parameters:
      l -
      r -
      Returns:
    • create

      public static <K, V> Pair<K,V> create(Map.Entry<K,V> entry)
      Create a new Pair with the values from the specified entry.
      Type Parameters:
      K - the key type
      V - the value type
      Parameters:
      entry -
      Returns:
    • emptyArray

      public static <L, R> Pair<L,R>[] emptyArray()
      Type Parameters:
      L -
      R -
      Returns:
    • getLeft

      public L getLeft()
      Gets the left.
      Returns:
    • setLeft

      public void setLeft(L left)
      Sets the left.
      Parameters:
      left - the new left
    • getRight

      public R getRight()
      Gets the right.
      Returns:
    • setRight

      public void setRight(R right)
      Sets the right.
      Parameters:
      right - the new right
    • set

      public void set(L left, R right)
      Parameters:
      left -
      right -
    • getAndSetLeft

      public L getAndSetLeft(L newLeft)
      Gets the and set left.
      Parameters:
      newLeft -
      Returns:
    • setAndGetLeft

      public L setAndGetLeft(L newLeft)
      Sets the and get left.
      Parameters:
      newLeft -
      Returns:
    • getAndSetRight

      public R getAndSetRight(R newRight)
      Gets the and set right.
      Parameters:
      newRight -
      Returns:
    • setAndGetRight

      public R setAndGetRight(R newRight)
      Sets the and get right.
      Parameters:
      newRight -
      Returns:
    • setLeftIf

      public <E extends Exception> boolean setLeftIf(L newLeft, Throwables.BiPredicate<? super Pair<L,R>,? super L,E> predicate) throws E
      Set to the specified newLeft and returns true if predicate returns true. Otherwise returns false without setting the value to new value.
      Type Parameters:
      E -
      Parameters:
      newLeft -
      predicate - - the first parameter is current pair, the second parameter is the newLeft
      Returns:
      Throws:
      E - the e
    • setRightIf

      public <E extends Exception> boolean setRightIf(R newRight, Throwables.BiPredicate<? super Pair<L,R>,? super R,E> predicate) throws E
      Set to the specified newRight and returns true if predicate returns true. Otherwise returns false without setting the value to new value.
      Type Parameters:
      E -
      Parameters:
      newRight -
      predicate - - the first parameter is current pair, the second parameter is the newRight
      Returns:
      Throws:
      E - the e
    • setIf

      public <E extends Exception> boolean setIf(L newLeft, R newRight, Throwables.TriPredicate<? super Pair<L,R>,? super L,? super R,E> predicate) throws E
      Set to the specified newLeft and newRight and returns true if predicate returns true. Otherwise returns false without setting the left/right to new values.
      Type Parameters:
      E -
      Parameters:
      newLeft -
      newRight -
      predicate - - the first parameter is current pair, the second parameter is the newLeft, the third parameter is the newRight.
      Returns:
      Throws:
      E - the e
    • reverse

      @Beta public Pair<R,L> reverse()
      Returns a new instance of Pair<R, L>.
      Returns:
      a new instance of Pair<R, L>.
    • copy

      public Pair<L,R> copy()
      Returns:
    • toArray

      public Object[] toArray()
      Returns:
    • toArray

      public <A> A[] toArray(A[] a)
      Type Parameters:
      A -
      Parameters:
      a -
      Returns:
    • forEach

      public <E extends Exception> void forEach(Throwables.Consumer<?,E> comsumer) throws E
      Type Parameters:
      E -
      Parameters:
      comsumer -
      Throws:
      E - the e
    • accept

      public <E extends Exception> void accept(Throwables.BiConsumer<? super L,? super R,E> action) throws E
      Type Parameters:
      E -
      Parameters:
      action -
      Throws:
      E - the e
    • accept

      public <E extends Exception> void accept(Throwables.Consumer<? super Pair<L,R>,E> action) throws E
      Type Parameters:
      E -
      Parameters:
      action -
      Throws:
      E - the e
    • map

      public <U, E extends Exception> U map(Throwables.BiFunction<? super L,? super R,U,E> mapper) throws E
      Type Parameters:
      U -
      E -
      Parameters:
      mapper -
      Returns:
      Throws:
      E - the e
    • map

      public <U, E extends Exception> U map(Throwables.Function<? super Pair<L,R>,U,E> mapper) throws E
      Type Parameters:
      U -
      E -
      Parameters:
      mapper -
      Returns:
      Throws:
      E - the e
    • filter

      public <E extends Exception> u.Optional<Pair<L,R>> filter(Throwables.BiPredicate<? super L,? super R,E> predicate) throws E
      Type Parameters:
      E -
      Parameters:
      predicate -
      Returns:
      Throws:
      E - the e
    • filter

      public <E extends Exception> u.Optional<Pair<L,R>> filter(Throwables.Predicate<? super Pair<L,R>,E> predicate) throws E
      Type Parameters:
      E -
      Parameters:
      predicate -
      Returns:
      Throws:
      E - the e
    • stream

      public Stream<Pair<L,R>> stream()
      Returns:
    • stream

      public <T, E extends Exception> Stream<T> stream(Throwables.Function<? super Pair<L,R>,Stream<T>,E> func) throws E
      Type Parameters:
      T -
      E -
      Parameters:
      func -
      Returns:
      Throws:
      E
    • toOptional

      public u.Optional<Pair<L,R>> toOptional()
      Returns:
    • toTuple

      public Tuple.Tuple2<L,R> toTuple()
      Returns:
    • toEntry

      public Map.Entry<L,R> toEntry()
      Returns:
    • toImmutableEntry

      public ImmutableEntry<L,R> toImmutableEntry()
      Returns:
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
      Returns:
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object
      Parameters:
      obj -
      Returns:
    • toString

      public String toString()
      Overrides:
      toString in class Object
      Returns: