csheets.ext.assertion
Class Assertion

java.lang.Object
  extended by csheets.ext.assertion.Assertion
All Implemented Interfaces:
Serializable
Direct Known Subclasses:
SGAssertion, USAssertion

public abstract class Assertion
extends Object
implements Serializable

Abstract class representing an assertion. This class contains the common data and functionality for assertion (USAssertion and SGAssertion).

Author:
Peter Palotas
See Also:
Serialized Form

Nested Class Summary
static class Assertion.ComparisonResult
          The possible results when two assertions are compared.
static class Assertion.Result
          Enumeration indicating the result of a validation of a value.
 
Field Summary
protected  MultiInterval intervals
          Represents the intervals of allowed values for this assertion.
protected  boolean isInteger
          Indicates wether only integer values are allowed
 
Constructor Summary
Assertion()
           
 
Method Summary
 boolean allowsIntegersOnly()
          Checks if this assertion allows only integer values.
 boolean equals(Object o)
           
 Iterator<Interval> getIntervalIterator()
          Returns an iterator over the intervals representing all allowed values in this assertion.
 MultiInterval getMultiInterval()
          Returns the MultiInterval specifying the valid values for this assertion.
 String toString()
           
 Assertion.Result validate(double value)
          Checks if the current assertion holds for the given value
 Assertion.Result validate(Value value)
          Checks if the current assertion holds for the given value.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

intervals

protected MultiInterval intervals
Represents the intervals of allowed values for this assertion.


isInteger

protected boolean isInteger
Indicates wether only integer values are allowed

Constructor Detail

Assertion

public Assertion()
Method Detail

getIntervalIterator

public Iterator<Interval> getIntervalIterator()
Returns an iterator over the intervals representing all allowed values in this assertion. Note that this iterator cannot be used to modify the underlying collection.

Returns:
Returns an iterator over the intervals representing all allowed values in this assertion.

getMultiInterval

public MultiInterval getMultiInterval()
Returns the MultiInterval specifying the valid values for this assertion.

Returns:
the MultiInterval specifying the valid values for this assertion.

allowsIntegersOnly

public boolean allowsIntegersOnly()
Checks if this assertion allows only integer values.

Returns:
true if this assertion will validate only integer values successfully, and false otherwise.

validate

public Assertion.Result validate(Value value)
Checks if the current assertion holds for the given value. The value may be any object.

Parameters:
value - An arbritrary object. The value the assertion will be verified against will be retrieved from the object using its toString() method.
Returns:
  • Result.NO_DATA if value is null or value.toString() returns an empty string.
  • Result.NAN if the string returned by value.toString() does not represent a number parsable by Double.parseDouble().
  • Result.OK if assertion holds for the value.
  • Result.FAILED if the assertion failed for the value, unless one of the reasons above.

validate

public Assertion.Result validate(double value)
Checks if the current assertion holds for the given value

Returns:
  • Result.OK if the assertion holds for the value,
  • Result.NAN if value == Double.NaN
  • Result.FAILED otherwise.

equals

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

toString

public String toString()
Overrides:
toString in class Object