Class Range<T extends Comparable<T>>

java.lang.Object
org.jooq.lambda.tuple.Tuple2<T,T>
org.jooq.lambda.tuple.Range<T>
All Implemented Interfaces:
Serializable, Cloneable, Comparable<Tuple2<T,T>>, Iterable<Object>, Tuple

public class Range<T extends Comparable<T>> extends Tuple2<T,T>
A range is a special Tuple2 with two times the same type.

Ranges can be (partially) unbounded if one or both of their bounds are null, which corresponds to "infinity", if T is a type that doesn't already have an infinity value, such as Double.POSITIVE_INFINITY or Double.NEGATIVE_INFINITY.

Ranges are inclusive on both bounds.

Author:
Lukas Eder
See Also:
  • Constructor Details

    • Range

      public Range(T lowerInclusive, T upperInclusive)
    • Range

      public Range(Tuple2<T,T> tuple)
  • Method Details

    • overlaps

      @Deprecated public boolean overlaps(Tuple2<T,T> other)
      Deprecated.
      - Use overlaps(Range) instead.
      Whether two ranges overlap.

      
       // true
       range(1, 3).overlaps(range(2, 4))
      
       // false
       range(1, 3).overlaps(range(5, 8))
       
    • overlaps

      public boolean overlaps(Range<T> other)
      Whether two ranges overlap.

      
       // true
       range(1, 3).overlaps(range(2, 4))
      
       // false
       range(1, 3).overlaps(range(5, 8))
       
    • overlaps

      public boolean overlaps(T lowerInclusive, T upperInclusive)
      Whether two ranges overlap.

      
       // true
       range(1, 3).overlaps(2, 4)
      
       // false
       range(1, 3).overlaps(5, 8)
       
    • intersect

      public Optional<Range<T>> intersect(Tuple2<T,T> other)
      Deprecated.
      - Use intersect(Range) instead.
      The intersection of two ranges.

      
       // (2, 3)
       range(1, 3).intersect(range(2, 4))
      
       // none
       range(1, 3).intersect(range(5, 8))
       
    • intersect

      public Optional<Range<T>> intersect(Range<T> other)
      The intersection of two ranges.

      
       // (2, 3)
       range(1, 3).intersect(range(2, 4))
      
       // none
       range(1, 3).intersect(range(5, 8))
       
    • intersect

      public Optional<Range<T>> intersect(T lowerInclusive, T upperInclusive)
      The intersection of two ranges.

      
       // (2, 3)
       range(1, 3).intersect(2, 4)
      
       // none
       range(1, 3).intersect(5, 8)
       
    • contains

      public boolean contains(T t)
      Whether a value is contained in this range.

      
       // true
       range(1, 3).contains(2)
      
       // false
       range(1, 3).contains(4)
       
    • contains

      public boolean contains(Range<T> other)
      Whether a range is contained in this range.

      
       // true
       range(1, 3).contains(range(2, 3))
      
       // false
       range(1, 3).contains(range(2, 4))