Interface Bound<T extends Comparable<? super T>>

Type Parameters:
T - 边界值类型
All Superinterfaces:
Comparable<Bound<T>>, Predicate<T>
All Known Implementing Classes:
FiniteBound, NoneLowerBound, NoneUpperBound

public interface Bound<T extends Comparable<? super T>> extends Predicate<T>, Comparable<Bound<T>>

边界对象,描述具有特定上界或下界的单侧无界的区间。

边界的类型

边界根据其getType()所获得的类型,可用于描述基于边界值t的不等式:

当作为Predicate使用时,可用于判断入参对象是否能满足当前实例所对应的不等式。

边界的比较

边界对象本身实现了Comparable接口, 当使用Comparable.compareTo(T)比较两个边界对象时, 返回的比较值表示两个边界对象对应的点在实数轴上从左到右的先后顺序。 比如: 若令当前边界点为t1,另一边界点为t2,则有

  • -1:t1t2的左侧;
  • 0:t1t2所表示的点彼此重合;
  • -1:t1t2的右侧;
Since:
Java 17+
Author:
Kimi Liu
See Also:
  • Field Details

  • Method Details

    • noneLowerBound

      static <T extends Comparable<? super T>> Bound<T> noneLowerBound()
      {x | x > -∞}
      Type Parameters:
      T - 边界值类型
      Returns:
      区间
    • noneUpperBound

      static <T extends Comparable<? super T>> Bound<T> noneUpperBound()
      {x | x < +∞}
      Type Parameters:
      T - 边界值类型
      Returns:
      区间
    • greaterThan

      static <T extends Comparable<? super T>> Bound<T> greaterThan(T min)
      {x | x > min}
      Type Parameters:
      T - 边界值类型
      Parameters:
      min - 最小值
      Returns:
      区间
    • atLeast

      static <T extends Comparable<? super T>> Bound<T> atLeast(T min)
      {x | x >= min}
      Type Parameters:
      T - 边界值类型
      Parameters:
      min - 最小值
      Returns:
      区间
    • lessThan

      static <T extends Comparable<? super T>> Bound<T> lessThan(T max)
      {x | x < max}
      Type Parameters:
      T - 边界值类型
      Parameters:
      max - 最大值
      Returns:
      区间
    • atMost

      static <T extends Comparable<? super T>> Bound<T> atMost(T max)
      {x | x <= max}
      Type Parameters:
      T - 边界值类型
      Parameters:
      max - 最大值
      Returns:
      区间
    • getValue

      T getValue()
      获取边界值
      Returns:
      边界值
    • getType

      BoundType getType()
      获取边界类型
      Returns:
      边界类型
    • test

      boolean test(T t)
      检验指定值是否在当前边界表示的范围内
      Specified by:
      test in interface Predicate<T extends Comparable<? super T>>
      Parameters:
      t - 要检验的值,不允许为null
      Returns:
      是否
    • compareTo

      int compareTo(Bound<T> bound)

      比较另一边界与当前边界在坐标轴上位置的先后顺序。 若令当前边界为t1,另一边界为t2,则有

      • -1:t1t2的左侧;
      • 0:t1t2的重合;
      • -1:t1t2的右侧;
      Specified by:
      compareTo in interface Comparable<T extends Comparable<? super T>>
      Parameters:
      bound - 边界
      Returns:
      位置
    • descBound

      String descBound()
      获取"[value""(value"格式的字符串
      Returns:
      字符串
    • negate

      Bound<T> negate()
      对当前边界取反
      Specified by:
      negate in interface Predicate<T extends Comparable<? super T>>
      Returns:
      取反后的边界
    • toRange

      BoundedRange<T> toRange()
      将当前实例转为一个区间
      Returns:
      区间
    • toString

      String toString()
      获得当前实例对应的{x| x >= xxx}格式的不等式字符串
      Overrides:
      toString in class Object
      Returns:
      字符串