Class Pair<L,R>

java.lang.Object
org.aoju.bus.core.lang.tuple.Pair<L,R>
Type Parameters:
L - 左元素类型
R - 右元素类型
All Implemented Interfaces:
Serializable, Comparable<Pair<L,R>>, Map.Entry<L,R>
Direct Known Subclasses:
Different, ImmutablePair, MutablePair

@ThreadSafe public abstract class Pair<L,R> extends Object implements Map.Entry<L,R>, Comparable<Pair<L,R>>, Serializable
由两个元素组成

这个类是一个定义基本API的抽象实现 它表示元素为“left”和“right” 它还实现了 Map.Entry接口,其中键为'left',值为'right'. 子类实现可以是可变的,也可以是不可变的 但是,对可能存储的存储对象的类型没有限制 如果可变对象存储在对中,那么对本身就会有效地变成可变的

Since:
Java 17+
Author:
Kimi Liu
See Also:
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    int
    compareTo(Pair<L,R> other)
    比较基于左元素和右元素的对。类型必须是Comparable
    boolean
    据这两个元素,将这一对与另一对进行比较
    final L
    从这对中获取密钥
    abstract L
    从这一对中获取左元素
    abstract R
    从这一对中获取右元素
    从这对中获取值
    int
     
    static <L, R> Pair<L,R>
    of(L left, R right)
    获取两个推断泛型类型的对象的不可变对 这个工厂允许使用推理来创建对,以获得泛型类型
     
    toString(String format)
     

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait

    Methods inherited from interface java.util.Map.Entry

    setValue
  • Constructor Details

    • Pair

      public Pair()
  • Method Details

    • of

      public static <L, R> Pair<L,R> of(L left, R right)
      获取两个推断泛型类型的对象的不可变对 这个工厂允许使用推理来创建对,以获得泛型类型
      Type Parameters:
      L - 左元素类型
      R - 右元素类型
      Parameters:
      left - 左值可以为null
      right - 右值可以为null
      Returns:
      由两个参数组成的一对,不是空
    • getLeft

      public abstract L getLeft()
      从这一对中获取左元素
      Returns:
      左边的元素可能是空的
    • getRight

      public abstract R getRight()
      从这一对中获取右元素
      Returns:
      右边的元素可能是空的
    • getKey

      public final L getKey()
      从这对中获取密钥
      Specified by:
      getKey in interface Map.Entry<L,R>
      Returns:
      作为键的左元素可以为空
    • getValue

      public R getValue()
      从这对中获取值
      Specified by:
      getValue in interface Map.Entry<L,R>
      Returns:
      右边的元素作为值,可以是null
    • compareTo

      public int compareTo(Pair<L,R> other)
      比较基于左元素和右元素的对。类型必须是Comparable
      Specified by:
      compareTo in interface Comparable<L>
      Parameters:
      other - 另一对,不为空
      Returns:
      如果这个小,就是负的;如果相等,就是零;如果大,就是正的
    • equals

      public boolean equals(Object obj)
      据这两个元素,将这一对与另一对进行比较
      Specified by:
      equals in interface Map.Entry<L,R>
      Overrides:
      equals in class Object
      Parameters:
      obj - 要比较的对象null返回false
      Returns:
      如果这一对的元素相等,则为true
    • hashCode

      public int hashCode()
      Specified by:
      hashCode in interface Map.Entry<L,R>
      Overrides:
      hashCode in class Object
    • toString

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

      public String toString(String format)