csheets.ext.assertion
Class Interval

java.lang.Object
  extended by csheets.ext.assertion.Interval
All Implemented Interfaces:
Serializable, Cloneable, Comparable<Interval>

public class Interval
extends Object
implements Comparable<Interval>, Cloneable, Serializable

This class represents a non-empty interval. A single number can be represented by setting lowerLimit == upperLimit A one sided interval is represented by either setting upperLimit to Double.POSITIVE_INFINITY or lowerLimit to Double.NEGATIVE_INFINITY.

Author:
Fredrik Johansson, Peter Palotas
See Also:
Serialized Form

Constructor Summary
Interval(double constant)
          Constructs a new instance of Interval containing a single value only.
Interval(double lowerLimit, double upperLimit, boolean lowerLimitClosed, boolean upperLimitClosed)
          Constructs a new instance of Interval.
 
Method Summary
static Interval abs(Interval interval)
          Calculates the absolute value Interval of an Interval
static Interval add(Interval interval1, Interval interval2)
          Calculates the sum of two intervals
static Interval avg(List<Interval> intervals)
          Calculates the average interval for a List of intervals
 Interval clone()
           
 int compareTo(Interval i)
          Compares two intervals, by essentially comparing their lower limit.
 boolean contains(double value)
          Indicates wether the specified value is contained in this Interval or not.
static Interval cos(Interval interval)
          Calculates the cosine interval of an interval.
static Interval div(Interval interval1, Interval interval2)
          Calculates the quotient of two intervals
 boolean encloses(Interval interval)
          Indicates wether this Interval fully encloses another interval.
 boolean equals(Object obj)
           
static Interval exp(Interval interval)
          Calculates Eulers number e raised to an Interval
static Interval fact(Interval interval)
          Calculates the factorial of an Interval
 double getLowerLimit()
          Return the lower limit of this Interval.
 double getUpperLimit()
          Return the upper limit of this Interval.
 boolean intersects(Interval interval)
          Indicates wether this interval intersects with another interval.
 boolean isLowerLimitClosed()
          Indicates if this interval is closed at its lower limit or not (i.e. wether the value returned by getLowerLimit() is included in the interval or not).
 boolean isUpperLimitClosed()
          Indicates if this interval is closed at its upper limit or not (i.e. wether the value returned by getUpperLimit() is included in the interval or not).
static Interval ln(Interval interval)
          Calculates the natural logarithm for an Interval
static Interval log10(Interval interval)
          Calculates the base 10 logarithm of an Interval
static Interval mul(Interval interval1, Interval interval2)
          Calculates the product of two intervals
static Interval negate(Interval interval)
          Calculates the negation of an interval
static Interval pow(Interval base, Interval exponent)
          Calculates the first Interval raised to the power of the second Interval
static Interval rand()
          Returns an Interval holding all possible values you get from the Math.random() method
static Interval sin(Interval interval)
          Calculates the sine interval of an interval.
 double size()
          Retrieve the size of this interval.
static Interval sqrt(Interval interval)
          Calculates the square root of an Interval
static Interval sub(Interval interval1, Interval interval2)
          Calculates the difference between two intervals
static Interval sum(List<Interval> intervals)
          Calculates the sum of a List of intervals
static Interval tan(Interval interval)
           
static Interval toInt(Interval interval)
          Calculates the Interval you get if you convert the values from double to int
 String toString()
          Converts this Interval into a string representation.
static Interval union(Interval i1, Interval i2)
          Returns the union of two intersecting or bordering intervals.
 
Methods inherited from class java.lang.Object
finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Interval

public Interval(double lowerLimit,
                double upperLimit,
                boolean lowerLimitClosed,
                boolean upperLimitClosed)
         throws IllegalArgumentException
Constructs a new instance of Interval.

Parameters:
lowerLimit - The value of the lower limit of this interval. This must be less than or equal to upperLimit.
upperLimit - The value of the upper limit of this interval. This must be greater than or equal to lowerLimit.
lowerLimitClosed - if true the value specified by lowerLimit will be included in the interval, otherwise it will not be. Note that this must be false if lowerLimit is infinite.
upperLimitClosed - if true the value specified by upperLimit will be included in the interval, otherwise it will not be. Note that this must be false if upperLimit is infinite.
Throws:
IllegalArgumentException - if illegal limits were passed. Limits must not be Double.NaNand lowerLimit must be less than or equal to upperLimit.

Interval

public Interval(double constant)
         throws IllegalArgumentException
Constructs a new instance of Interval containing a single value only.

Parameters:
constant - The single value this Interval should contain.
Throws:
IllegalArgumentException - if constant is Double.NaN or infinite.
Method Detail

getLowerLimit

public double getLowerLimit()
Return the lower limit of this Interval. NOTE! If isLowerLimitClosed() returns false, the value returned by this function is NOT part of the interval.

Returns:
the lower limit of this Interval.

getUpperLimit

public double getUpperLimit()
Return the upper limit of this Interval. NOTE! If isUpperLimitClosed() returns false, the value returned by this function is NOT part of the interval.

Returns:
the lower limit of this Interval.

isLowerLimitClosed

public boolean isLowerLimitClosed()
Indicates if this interval is closed at its lower limit or not (i.e. wether the value returned by getLowerLimit() is included in the interval or not).

Returns:
true if the value returned by getLowerLimit() is included in the Interval, false otherwise.

isUpperLimitClosed

public boolean isUpperLimitClosed()
Indicates if this interval is closed at its upper limit or not (i.e. wether the value returned by getUpperLimit() is included in the interval or not).

Returns:
true if the value returned by getUpperLimit() is included in the Interval, false otherwise.

contains

public boolean contains(double value)
Indicates wether the specified value is contained in this Interval or not.

Parameters:
value - the value to check against this Interval.
Returns:
true if value is contained in this Interval, false otherwise.

intersects

public boolean intersects(Interval interval)
Indicates wether this interval intersects with another interval.

Parameters:
interval - The interval to check this one against.
Returns:
true if the intervals do intersect, false otherwise.

encloses

public boolean encloses(Interval interval)
Indicates wether this Interval fully encloses another interval.

Parameters:
interval - The interval to check wether it is enclosed in this interval or not.
Returns:
true if interval is fully enclosed within this Interval, false otherwise.

equals

public boolean equals(Object obj)
Overrides:
equals in class Object

compareTo

public int compareTo(Interval i)
Compares two intervals, by essentially comparing their lower limit. If lower limits are equal (as well as isLowerLimitClosed()), the upper limits are compared.

Specified by:
compareTo in interface Comparable<Interval>
Parameters:
i - the interval to compare this interval to.
Returns:
A negative value if the lower limit of this interval is less than that of the compared one, zero (0) if the two intervals are equal, and a positive value if the lower limit of this interval is greater than that of the compared one.

union

public static Interval union(Interval i1,
                             Interval i2)
Returns the union of two intersecting or bordering intervals.

Parameters:
i1 - An interval
i2 - An interval intersecting or bordering i1.
Returns:
A new interval containing the union of the the two intervals specified, or null if the two intervals cannot be unioned into a single interval.

negate

public static Interval negate(Interval interval)
Calculates the negation of an interval

Parameters:
interval - is the interval
Returns:
the negated interval

add

public static Interval add(Interval interval1,
                           Interval interval2)
Calculates the sum of two intervals

Parameters:
interval1 - is the first interval
interval2 - is the second interval
Returns:
an interval describing the sum of the two intervals

sub

public static Interval sub(Interval interval1,
                           Interval interval2)
Calculates the difference between two intervals

Parameters:
interval1 - is the first interval
interval2 - is the second interval
Returns:
an interval describing the difference between the two intervals

mul

public static Interval mul(Interval interval1,
                           Interval interval2)
Calculates the product of two intervals

Parameters:
interval1 - is the first interval
interval2 - is the second interval
Returns:
an interval describing the product of the two intervals

cos

public static Interval cos(Interval interval)
Calculates the cosine interval of an interval.

Returns:
the interval corresponding to the possible values of running cosine on the values of this interval.

sin

public static Interval sin(Interval interval)
Calculates the sine interval of an interval.

Returns:
the interval corresponding to the possible values of running sine on the values of this interval.

tan

public static Interval tan(Interval interval)
                    throws MathException
Throws:
MathException

div

public static Interval div(Interval interval1,
                           Interval interval2)
                    throws MathException
Calculates the quotient of two intervals

Parameters:
interval1 - is the first interval
interval2 - is the second interval
Returns:
an interval describing the quotient of the two intervals
Throws:
ArithmeticException - if the second interval contains the value 0. Can't divide by zero.
MathException

pow

public static Interval pow(Interval base,
                           Interval exponent)
                    throws MathException
Calculates the first Interval raised to the power of the second Interval

Parameters:
base - is the first Interval
exponent - is the second Interval
Returns:
the first Interval raised to the power of the second Interval
Throws:
MathException - if the first Interval contains values below zero and the second Interval is not a singel integer value

ln

public static Interval ln(Interval interval)
                   throws MathException
Calculates the natural logarithm for an Interval

Parameters:
interval - is the Interval
Returns:
the natural logarithm for the Interval
Throws:
MathException - if the Interval contains values below zero

log10

public static Interval log10(Interval interval)
                      throws MathException
Calculates the base 10 logarithm of an Interval

Parameters:
interval - is the Interval
Returns:
the base 10 logarithm of the Interval
Throws:
MathException - if the Interval contains values below zero

exp

public static Interval exp(Interval interval)
Calculates Eulers number e raised to an Interval

Parameters:
interval - is the Interval
Returns:
Eulers number e raised to the Interval

sqrt

public static Interval sqrt(Interval interval)
                     throws MathException
Calculates the square root of an Interval

Parameters:
interval - is the Interval
Returns:
the square root of the Interval
Throws:
MathException - if the Interval contains values below zero

toInt

public static Interval toInt(Interval interval)
Calculates the Interval you get if you convert the values from double to int

Parameters:
interval - is the Interval
Returns:
the Interval you get if you convert the values from double to int

abs

public static Interval abs(Interval interval)
Calculates the absolute value Interval of an Interval

Parameters:
interval - is the Interval
Returns:
the absolute value Interval of the Interval

rand

public static Interval rand()
Returns an Interval holding all possible values you get from the Math.random() method

Returns:
an Interval holding all possible values you get from the Math.random() mathod

fact

public static Interval fact(Interval interval)
                     throws MathException
Calculates the factorial of an Interval

Parameters:
interval - is the Interval
Returns:
the factorial of the Interval
Throws:
MathException - if the Interval contains values below zero

sum

public static Interval sum(List<Interval> intervals)
Calculates the sum of a List of intervals

Parameters:
intervals - is the intervals to be summarized
Returns:
an Interval describing the sum of the intervals

avg

public static Interval avg(List<Interval> intervals)
Calculates the average interval for a List of intervals

Parameters:
intervals - is the intervals to calculate the average for
Returns:
an Interval describing the average of the intervals

clone

public Interval clone()
Overrides:
clone in class Object

size

public double size()
Retrieve the size of this interval.

Returns:
the size (or width) of this interval.

toString

public String toString()
Converts this Interval into a string representation.

Overrides:
toString in class Object
Returns:
a String containing a textual representation of this interval with the same syntax as is used for specifying assertions.