Class Range<T extends java.lang.Comparable<T>>

  • All Implemented Interfaces:
    java.io.Serializable, java.lang.Cloneable, java.lang.Comparable<Tuple2<T,​T>>, java.lang.Iterable<java.lang.Object>, Tuple

    public class Range<T extends java.lang.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.

    See Also:
    Serialized Form
    • Constructor Detail

      • Range

        public Range​(T lowerInclusive,
                     T upperInclusive)
      • Range

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

      • r

        private static <T extends java.lang.Comparable<T>> Tuple2<T,​T> r​(T t1,
                                                                               T t2)
      • 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 java.util.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 java.util.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 java.util.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))