csheets.ext.assertion
Class MultiInterval

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

public class MultiInterval
extends Object
implements Iterable<Interval>, Serializable

A class representing (possibly) multiple intervals. This can be used to specify any combination of values to be included in an interval. The MultiInterval is built up by specifying normal intervals to be included or excluded from the MultiInterval.

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

Constructor Summary
MultiInterval()
          Default constructor.
 
Method Summary
static MultiInterval abs(MultiInterval mInterval)
          Calculates the absolute value MultiInterval of a MultiInterval
static MultiInterval add(MultiInterval term1, MultiInterval term2)
          Calculates the sum of two MultiIntervals
static MultiInterval avg(List<MultiInterval> terms)
          Calculates the average of a List of MultiIntervals
 MultiInterval clone()
          Makes a copy of this MultiInterval intance
 boolean contains(double value)
          Check if a value is contained in this MultiInterval.
static MultiInterval cos(MultiInterval mInterval)
          Calculates the cosine MultiInterval of a MultiInterval
static MultiInterval div(MultiInterval numerator, MultiInterval denominator)
          Calculates the quotient of two MultiIntervals
 boolean equals(Object o)
          Compares the specified MultiInterval with this MultiInterval for equality.
 void exclude(Interval interval)
          Exclude a specific interval from this MultiInterval.
static MultiInterval exp(MultiInterval exponent)
          Calculates Eulers number e raised to a MultiInterval
static MultiInterval fact(MultiInterval mInterval)
          Calculates the factorial of a MultiInterval
 void include(Interval interval)
          Add an interval to be included in this MultiInterval.
 Iterator<Interval> iterator()
          Returns an iterator over the intervals in this MultiInterval in proper sequence.
static MultiInterval ln(MultiInterval mInterval)
          Calculates the natural logarithm of a MultiInterval
static MultiInterval log10(MultiInterval mInterval)
          Calculates the base 10 logarithm of a MultiInterval
static MultiInterval mul(MultiInterval factor1, MultiInterval factor2)
          Calculates the product of two MultiIntervals
static MultiInterval negate(MultiInterval term)
          Calculates a negation av a MultiInterval
static MultiInterval pow(MultiInterval base, MultiInterval exponent)
          Calculates the first MultiInterval raised to the power of the second MultiInterval
static MultiInterval rand()
          Returns a MultiInterval holding all possible values you get from the Math.random() method
static MultiInterval sin(MultiInterval mInterval)
          Calculates the sine MultiInterval of a MultiInterval
static MultiInterval sqrt(MultiInterval mInterval)
          Calculates the square root of a MultiInterval
static MultiInterval sub(MultiInterval term1, MultiInterval term2)
          Calculates the difference of two MultiIntervals
static MultiInterval sum(List<MultiInterval> terms)
          Calculates the sum of a List of MultiIntervals
static MultiInterval tan(MultiInterval mInterval)
          Calculates the tangent MultiInterval of a MultiInterval
static MultiInterval toInt(MultiInterval mInterval)
          Calculates the MultiInterval you get if you convert all values from double to int
 String toString()
          Returns a string representation of this MultiInterval.
 
Methods inherited from class java.lang.Object
finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

MultiInterval

public MultiInterval()
Default constructor. Constructs an empty MultiInterval containing no values. Note that if the first operation called on this interval after its construction is exclude(), all values except the ones excluded will be included in this interval.

Method Detail

include

public void include(Interval interval)
Add an interval to be included in this MultiInterval.

Parameters:
interval - An interval specifying values to be included in this MultiInterval.

exclude

public void exclude(Interval interval)
Exclude a specific interval from this MultiInterval. If this MultiInterval is empty (i.e. does not include anything) when this function is called, the MultiInterval will accept any value except the ones included in the interval specified.

Parameters:
interval - an interval specifying which values to exclude from this MultiInterval.

contains

public boolean contains(double value)
Check if a value is contained in this MultiInterval.

NOTE: Infinity and NaN is never reported to be included in a MultiInterval.

Parameters:
value - The value to check for.
Returns:
true if the value has been specified to be included in this MultiInterval, false otherwise.

negate

public static MultiInterval negate(MultiInterval term)
Calculates a negation av a MultiInterval

Parameters:
term - is the MultiInterval to be negated
Returns:
the negated MultiInterval

add

public static MultiInterval add(MultiInterval term1,
                                MultiInterval term2)
Calculates the sum of two MultiIntervals

Parameters:
term1 - is the first term
term2 - is the second term
Returns:
the summarized MultiIntervals

sub

public static MultiInterval sub(MultiInterval term1,
                                MultiInterval term2)
Calculates the difference of two MultiIntervals

Parameters:
term1 - is the first term
term2 - is the second term
Returns:
the difference of the two MultiIntervals

mul

public static MultiInterval mul(MultiInterval factor1,
                                MultiInterval factor2)
Calculates the product of two MultiIntervals

Parameters:
factor1 - is the first factor
factor2 - is the second factor
Returns:
the product of thw two MultiIntervals

div

public static MultiInterval div(MultiInterval numerator,
                                MultiInterval denominator)
                         throws MathException
Calculates the quotient of two MultiIntervals

Parameters:
numerator - is the numerator
denominator - is the denominator
Returns:
the quotient of the two MultiIntervals
Throws:
MathException

pow

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

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

cos

public static MultiInterval cos(MultiInterval mInterval)
Calculates the cosine MultiInterval of a MultiInterval

Parameters:
mInterval - is the MultiInterval
Returns:
the cosine MultiInterval of the MultiInterval

sin

public static MultiInterval sin(MultiInterval mInterval)
Calculates the sine MultiInterval of a MultiInterval

Parameters:
mInterval - is the MultiInterval
Returns:
the sine MultiInterval of the MultiInterval

tan

public static MultiInterval tan(MultiInterval mInterval)
Calculates the tangent MultiInterval of a MultiInterval

Parameters:
mInterval - is the MultiInterval
Returns:
the tangent MultiInterval of the MultiInterval

ln

public static MultiInterval ln(MultiInterval mInterval)
                        throws MathException
Calculates the natural logarithm of a MultiInterval

Parameters:
mInterval - is the MultiInterval
Returns:
the natural logarithm of the MultiInterval
Throws:
MathException - if the MultiInterval contains values below zero

log10

public static MultiInterval log10(MultiInterval mInterval)
                           throws MathException
Calculates the base 10 logarithm of a MultiInterval

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

exp

public static MultiInterval exp(MultiInterval exponent)
Calculates Eulers number e raised to a MultiInterval

Parameters:
exponent - is the MultiInterval
Returns:
Eulers number e raised to the MultiInterval

sqrt

public static MultiInterval sqrt(MultiInterval mInterval)
                          throws MathException
Calculates the square root of a MultiInterval

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

toInt

public static MultiInterval toInt(MultiInterval mInterval)
Calculates the MultiInterval you get if you convert all values from double to int

Parameters:
mInterval - is the MultiInterval
Returns:
the MultiInterval you get if you convert the values from double to int

abs

public static MultiInterval abs(MultiInterval mInterval)
Calculates the absolute value MultiInterval of a MultiInterval

Parameters:
mInterval - is the MultiInterval
Returns:
the absolute value MultiInterval of the MultiInterval

rand

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

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

fact

public static MultiInterval fact(MultiInterval mInterval)
                          throws MathException
Calculates the factorial of a MultiInterval

Parameters:
mInterval - is the MultiInterval
Returns:
the factorial of the MultiInterval
Throws:
MathException - if the MultiInterval contains values below zero

sum

public static MultiInterval sum(List<MultiInterval> terms)
Calculates the sum of a List of MultiIntervals

Parameters:
terms - is the terms to be summarized
Returns:
the sum of the MultiIntervals

avg

public static MultiInterval avg(List<MultiInterval> terms)
Calculates the average of a List of MultiIntervals

Parameters:
terms - is the terms
Returns:
the average of the MultiIntervals

iterator

public Iterator<Interval> iterator()
Returns an iterator over the intervals in this MultiInterval in proper sequence. Note that this iterator cannot be used to modify the MultiInterval.

Specified by:
iterator in interface Iterable<Interval>
Returns:
an iterator over the intervals in this MultiInterval in proper sequence.

equals

public boolean equals(Object o)
Compares the specified MultiInterval with this MultiInterval for equality.

Overrides:
equals in class Object
Returns:
true if the two intervals represent the same ranges of values, false otherwise.

clone

public MultiInterval clone()
Makes a copy of this MultiInterval intance

Overrides:
clone in class Object

toString

public String toString()
Returns a string representation of this MultiInterval.

Overrides:
toString in class Object