Class ValueRange


  • public class ValueRange
    extends Object
    An inclusive range of integer values used to track value constraints.
    • Constructor Detail

      • ValueRange

        public ValueRange​(long min,
                          long max)
        Creates an inclusive range; a min above max denotes the empty range.
        Parameters:
        min - the lower bound
        max - the upper bound
    • Method Detail

      • getMin

        public long getMin()
        Returns:
        the min
      • getMax

        public long getMax()
        Returns:
        the max
      • isEmpty

        public boolean isEmpty()
        Returns:
        whether the range holds no values
      • isConstant

        public boolean isConstant()
        Returns:
        whether the range holds exactly one value
      • contains

        public boolean contains​(long value)
        Tests membership, always false for an empty range.
        Parameters:
        value - the value to test
        Returns:
        whether the value lies within the bounds
      • intersect

        public ValueRange intersect​(ValueRange other)
        Intersects this range with another, narrowing the result.
        Parameters:
        other - the range to intersect with
        Returns:
        the overlap, or EMPTY if either side is empty or they do not overlap
      • lessThan

        public static ValueRange lessThan​(long val)
        Builds the range satisfying x < val.
        Parameters:
        val - the compared value
        Returns:
        the range [MIN_VALUE, val-1], or EMPTY if nothing is below it
      • lessOrEqual

        public static ValueRange lessOrEqual​(long val)
        Builds the range satisfying x <= val.
        Parameters:
        val - the compared value
        Returns:
        the range [MIN_VALUE, val]
      • greaterThan

        public static ValueRange greaterThan​(long val)
        Builds the range satisfying x > val.
        Parameters:
        val - the compared value
        Returns:
        the range [val+1, MAX_VALUE], or EMPTY if nothing is above it
      • greaterOrEqual

        public static ValueRange greaterOrEqual​(long val)
        Builds the range satisfying x >= val.
        Parameters:
        val - the compared value
        Returns:
        the range [val, MAX_VALUE]
      • equalTo

        public static ValueRange equalTo​(long val)
        Builds the range satisfying x == val.
        Parameters:
        val - the compared value
        Returns:
        the single-value range [val, val]
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class Object