Class IntInterval

  • All Implemented Interfaces:
    java.lang.Comparable<IntInterval>, java.lang.Iterable<java.lang.Long>

    public class IntInterval
    extends java.lang.Object
    implements java.lang.Iterable<java.lang.Long>, java.lang.Comparable<IntInterval>
    An interval with integer bounds.
    • Constructor Summary

      Constructors 
      Constructor Description
      IntInterval​(int low, int high)
      Builds a new interval.
      IntInterval​(MathNumber low, MathNumber high)
      Builds a new interval.
      IntInterval​(java.lang.Integer low, java.lang.Integer high)
      Builds a new interval.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      int compareTo​(IntInterval o)  
      IntInterval diff​(IntInterval other)
      Performs the interval subtraction between this and other.
      IntInterval div​(IntInterval other, boolean ignoreZero, boolean errorOnZero)
      Performs the interval division between this and other.
      boolean equals​(java.lang.Object obj)  
      MathNumber getHigh()
      Yields the upper bound of this interval.
      MathNumber getLow()
      Yields the lower bound of this interval.
      int hashCode()  
      boolean highIsPlusInfinity()
      Yields true if the upper bound of this interval is set to plus infinity.
      boolean includes​(IntInterval other)
      Yields true if this interval includes the given one.
      boolean intersects​(IntInterval other)
      Yields true if this interval intersects with the given one.
      boolean is​(int n)
      Yields true if this is a singleton interval containing only n.
      boolean isFinite()
      Yields true if this is interval is finite, that is, if neither bound is set to infinity.
      boolean isInfinite()
      Yields true if this is interval is not finite, that is, if at least one bound is set to infinity.
      boolean isInfinity()
      Yields true if this is the interval representing infinity, that is, [-Inf, +Inf].
      boolean isSingleton()
      Yields true if this is a singleton interval, that is, if the lower bound and the upper bound are the same.
      java.util.Iterator<java.lang.Long> iterator()  
      boolean lowIsMinusInfinity()
      Yields true if the lower bound of this interval is set to minus infinity.
      IntInterval mul​(IntInterval other)
      Performs the interval multiplication between this and other.
      IntInterval plus​(IntInterval other)
      Performs the interval addition between this and other.
      java.lang.String toString()  
      • Methods inherited from class java.lang.Object

        clone, finalize, getClass, notify, notifyAll, wait, wait, wait
      • Methods inherited from interface java.lang.Iterable

        forEach, spliterator
    • Field Detail

      • INFINITY

        public static final IntInterval INFINITY
        The interval [-Inf, +Inf].
      • ZERO

        public static final IntInterval ZERO
        The interval [0, 0].
      • ONE

        public static final IntInterval ONE
        The interval [1, 1].
      • MINUS_ONE

        public static final IntInterval MINUS_ONE
        The interval [-1, -1].
    • Constructor Detail

      • IntInterval

        public IntInterval​(int low,
                           int high)
        Builds a new interval. Order of the bounds is adjusted (i.e., if low is greater then high, then the interval [high, low] is created).
        Parameters:
        low - the lower bound
        high - the upper bound
      • IntInterval

        public IntInterval​(java.lang.Integer low,
                           java.lang.Integer high)
        Builds a new interval. Order of the bounds is adjusted (i.e., if low is greater then high, then the interval [high, low] is created).
        Parameters:
        low - the lower bound (if null, -inf will be used)
        high - the upper bound (if null, +inf will be used)
      • IntInterval

        public IntInterval​(MathNumber low,
                           MathNumber high)
        Builds a new interval. Order of the bounds is adjusted (i.e., if low is greater then high, then the interval [high, low] is created).
        Parameters:
        low - the lower bound
        high - the upper bound
    • Method Detail

      • getHigh

        public MathNumber getHigh()
        Yields the upper bound of this interval.
        Returns:
        the upper bound of this interval
      • getLow

        public MathNumber getLow()
        Yields the lower bound of this interval.
        Returns:
        the lower bound of this interval
      • lowIsMinusInfinity

        public boolean lowIsMinusInfinity()
        Yields true if the lower bound of this interval is set to minus infinity.
        Returns:
        true if that condition holds
      • highIsPlusInfinity

        public boolean highIsPlusInfinity()
        Yields true if the upper bound of this interval is set to plus infinity.
        Returns:
        true if that condition holds
      • isInfinite

        public boolean isInfinite()
        Yields true if this is interval is not finite, that is, if at least one bound is set to infinity.
        Returns:
        true if that condition holds
      • isFinite

        public boolean isFinite()
        Yields true if this is interval is finite, that is, if neither bound is set to infinity.
        Returns:
        true if that condition holds
      • isInfinity

        public boolean isInfinity()
        Yields true if this is the interval representing infinity, that is, [-Inf, +Inf].
        Returns:
        true if that condition holds
      • isSingleton

        public boolean isSingleton()
        Yields true if this is a singleton interval, that is, if the lower bound and the upper bound are the same.
        Returns:
        true if that condition holds
      • is

        public boolean is​(int n)
        Yields true if this is a singleton interval containing only n.
        Parameters:
        n - the integer to test
        Returns:
        true if that condition holds
      • plus

        public IntInterval plus​(IntInterval other)
        Performs the interval addition between this and other.
        Parameters:
        other - the other interval
        Returns:
        this + other
      • diff

        public IntInterval diff​(IntInterval other)
        Performs the interval subtraction between this and other.
        Parameters:
        other - the other interval
        Returns:
        this - other
      • mul

        public IntInterval mul​(IntInterval other)
        Performs the interval multiplication between this and other.
        Parameters:
        other - the other interval
        Returns:
        this * other
      • div

        public IntInterval div​(IntInterval other,
                               boolean ignoreZero,
                               boolean errorOnZero)
        Performs the interval division between this and other.
        Parameters:
        other - the other interval
        ignoreZero - if true, causes the division to ignore the fact that other might contain 0, producing a smaller result
        errorOnZero - whether or not an ArithmeticException should be thrown immediately if other contains zero
        Returns:
        this / other
        Throws:
        java.lang.ArithmeticException - if other contains 0 and errorOnZero is set to true
      • includes

        public boolean includes​(IntInterval other)
        Yields true if this interval includes the given one.
        Parameters:
        other - the other interval
        Returns:
        true if it is included, false otherwise
      • intersects

        public boolean intersects​(IntInterval other)
        Yields true if this interval intersects with the given one.
        Parameters:
        other - the other interval
        Returns:
        true if those intersects, false otherwise
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object
      • equals

        public boolean equals​(java.lang.Object obj)
        Overrides:
        equals in class java.lang.Object
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • iterator

        public java.util.Iterator<java.lang.Long> iterator()
        Specified by:
        iterator in interface java.lang.Iterable<java.lang.Long>
      • compareTo

        public int compareTo​(IntInterval o)
        Specified by:
        compareTo in interface java.lang.Comparable<IntInterval>