fleXplorer.Types
Class Interval<Type extends java.lang.Comparable<Type>>

java.lang.Object
  extended by fleXplorer.Types.Interval<Type>
All Implemented Interfaces:
PartialComparable<Type>

public class Interval<Type extends java.lang.Comparable<Type>>
extends java.lang.Object
implements PartialComparable<Type>


Constructor Summary
Interval(Type lower, boolean isLowerClosed, Type upper, boolean isUpperClosed)
          Constructs an Interval with specified limits and defines if those limits are closed or open.
 
Method Summary
 Interval<Type> closed(Type lower, Type upper)
          Returns an Interval with specified limits which are closed.
 PartialComparison compareTo(Interval<Type> obj)
          Compares this object with the specified object for order.
 java.util.List<Interval<Type>> complementRelativeTo(Interval<Type> other)
          Returns an Interval that includes the left and right complement of this Interval relative to an other.
 boolean covers(Interval<Type> other)
          Checks if an Interval covers an other Interval.
 Interval<Type> emptyOfSameType()
          Returns an empty Interval.
 boolean equals(Interval<Type> other)
          Indicates whether some other Interval is "equal to" this one.
 Interval<Type> gap(Interval<Type> other)
          Returns an Interval that is the gap of two Intervals.
 int hashCode()
          Returns a hash code value for the Interval.
 boolean hasLowerLimit()
          Checks if Interval has lower limit.
 boolean hasUpperLimit()
          Checks if Interval has upper limit.
 boolean includes(Type value)
          Checks if an Interval includes a value.
 boolean includesLowerLimit()
          Checks if lower limit of Interval is closed or open.
 boolean includesUpperLimit()
          Checks if upper limit is closed or open.
 Interval<Type> intersect(Interval<Type> other)
          Returns the intersect of two Intervals.
 boolean intersects(Interval<Type> other)
          Checks if two Intervals intersected.
 boolean isAbove(Type value)
          Checks if value is greater than the upper limit of Interval.
 boolean isBelow(Type value)
          Checks if value is less than the lower limit of Interval.
 boolean isClosed()
          Checks if lower and upper limit of Interval are closed.
 boolean isEmpty()
          Checks if Interval is empty.
 boolean isOpen()
          Checks if lower and upper limit of Interval are open.
 boolean isSingleElement()
          Checks if Interval has only a single element.
 Type lowerLimit()
          Returns the value of lower limit of Interval.
 Interval<Type> newOfSameType(Type lower, boolean isLowerClosed, Type upper, boolean isUpperClosed)
          Returns a new Interval with specified limits and defines if those limits are closed or open.
 Interval<Type> open(Type lower, Type upper)
          Returns an Interval with specified limits which are open.
 Interval<Type> over(Type lower, boolean lowerIncluded, Type upper, boolean upperIncluded)
          Returns an Interval with specified limits and defines if those limits are closed or open.
 java.lang.String toString()
          Returns a String representation of Interval.
 Type upperLimit()
          Returns the value of upper limit of Interval.
 
Methods inherited from class java.lang.Object
equals, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Interval

public Interval(Type lower,
                boolean isLowerClosed,
                Type upper,
                boolean isUpperClosed)
Constructs an Interval with specified limits and defines if those limits are closed or open. Preconditions: Upper limit must not be larger than lower and the opposite.
Postconditions: Constructs an Interval with the specified limits and defines if those limits are closed or open.

Parameters:
lower - the lower limit of Interval.
isLowerClosed - defines if lower limit of Interval will be closed or open. True to closed; false otherwise.
upper - the upper limit of Interval.
isUpperClosed - defines if upper limit of Interval will be closed or open. True to closed; false otherwise.
Method Detail

closed

public Interval<Type> closed(Type lower,
                             Type upper)
Returns an Interval with specified limits which are closed. Preconditions: Upper limit must not be larger than lower and the opposite.
Postconditions: Returns an Interval with specified limits and defines those limits to be closed.

Parameters:
lower - the lower limit of Interval.
upper - the upper limit of Interval.
Returns:
an Interval with specified limits which are closed.

open

public Interval<Type> open(Type lower,
                           Type upper)
Returns an Interval with specified limits which are open. Preconditions: Upper limit must not be larger than lower and the opposite.
Postconditions: Returns an Interval with specified limits and defines those limits to be open.

Parameters:
lower - the lower limit of Interval.
upper - the upper limit of Interval.
Returns:
an Interval with specified limits which are open.

over

public Interval<Type> over(Type lower,
                           boolean lowerIncluded,
                           Type upper,
                           boolean upperIncluded)
Returns an Interval with specified limits and defines if those limits are closed or open. Preconditions: Upper limit must not be larger than lower and the opposite.
Postconditions: Returns an Interval with the specified limits and defines if those limits are closed or open.

Parameters:
lower - the lower limit of Interval.
isLowerClosed - defines if lower limit of Interval will be closed or open. True to closed; false otherwise.
upper - the upper limit of Interval.
isUpperClosed - defines if upper limit of Interval will be closed or open. True to closed; false otherwise.
Returns:
an Interval with specified limits and defines if those limits are closed or open.

upperLimit

public Type upperLimit()
Returns the value of upper limit of Interval. Preconditions:Interval must not be null.
Postconditions: Returns the value of upper limit of Interval.

Returns:
the value of upper limit of Interval.

includesUpperLimit

public boolean includesUpperLimit()
Checks if upper limit is closed or open. Preconditions:Interval must not be null.
Postconditions:Checks if upper limit is closed or open.

Returns:
true if upper limit of Interval is closed; false otherwise.

hasUpperLimit

public boolean hasUpperLimit()
Checks if Interval has upper limit. Preconditions:Interval must not be null.
Postconditions:Checks if the upper limit of Interval is null.

Returns:
true if Interval has upper limit; false otherwise.

lowerLimit

public Type lowerLimit()
Returns the value of lower limit of Interval. Preconditions:Interval must not be null.
Postconditions: Returns the value of lower limit of Interval.

Returns:
the value of lower limit of Interval.

includesLowerLimit

public boolean includesLowerLimit()
Checks if lower limit of Interval is closed or open. Preconditions:Interval must not be null.
Postconditions:Checks if lower limit of Interval is closed or open.

Returns:
true if lower limit of Interval is closed; false otherwise.

hasLowerLimit

public boolean hasLowerLimit()
Checks if Interval has lower limit. Preconditions:Interval must not be null.
Postconditions:Checks if the lower limit of Interval is null.

Returns:
true if Interval has lower limit; false otherwise.

newOfSameType

public Interval<Type> newOfSameType(Type lower,
                                    boolean isLowerClosed,
                                    Type upper,
                                    boolean isUpperClosed)
Returns a new Interval with specified limits and defines if those limits are closed or open. Preconditions: Upper limit must not be larger than lower and the opposite.
Postconditions: Returns a new Interval with the specified limits and defines if those limits are closed or open.

Parameters:
lower - the lower limit of Interval.
isLowerClosed - defines if lower limit of Interval will be closed or open. True to closed; false otherwise.
upper - the upper limit of Interval.
isUpperClosed - defines if upper limit of Interval will be closed or open. True to closed; false otherwise.
Returns:
a new Interval with specified limits and defines if those limits are closed or open.

emptyOfSameType

public Interval<Type> emptyOfSameType()
Returns an empty Interval. Preconditions:Interval must not be null.
Postconditions: Returns a Interval where upper and lower limit is the same and open.

Returns:
a Interval where upper and lower limit is the same and open.

includes

public boolean includes(Type value)
Checks if an Interval includes a value. Preconditions:Interval and argument must not be null.
Postconditions: Checks if value of argument is larger than lower limit of Interval or smaller than upper one.

Parameters:
value - the value to be checked if included in Interval.
Returns:
true if Interval includes the value; false otherwise.

covers

public boolean covers(Interval<Type> other)
Checks if an Interval covers an other Interval. Preconditions: Interval and argument must not be null. The of values of the two Intervals ust be the same.
Postconditions: Checks the limits of two Intervals and according these returns true if Interval covers the argument or the opposite.

Parameters:
other - Interval to be checked if it is covered by the other.
Returns:
true if Interval covers the argument; false otherwise.

isOpen

public boolean isOpen()
Checks if lower and upper limit of Interval are open. Preconditions:Interval must not be null.
Postconditions: Checks if lower and upper limit of Interval are open.

Returns:
true if lower and upper limit of Interval are open; false otherwise.

isClosed

public boolean isClosed()
Checks if lower and upper limit of Interval are closed. Preconditions:Interval must not be null.
Postconditions: Checks if lower and upper limit of Interval are closed.

Returns:
true if lower and upper limit of Interval are closed; false otherwise.

isEmpty

public boolean isEmpty()
Checks if Interval is empty. Preconditions:Interval must not be null.
Postconditions: Checks if lower limit is equal with the upper one.

Returns:
true if Interval is empty; false otherwise.

isSingleElement

public boolean isSingleElement()
Checks if Interval has only a single element. Preconditions: Interval must not be null.
Postconditions: Checks if upper and lower limit are equals and the Interval is not empty.

Returns:
true if Interval has only a single element; false otherwise.

isBelow

public boolean isBelow(Type value)
Checks if value is less than the lower limit of Interval. Preconditions:Interval must not be null. The Type of Interval and argument must be the same.
Postconditions: Checks if value is less than the lower limit of Interval.

Parameters:
value - value to be checked.
Returns:
true if value is less than the lower limit of Interval; false otherwise.

isAbove

public boolean isAbove(Type value)
Checks if value is greater than the upper limit of Interval. Preconditions:Interval must not be null. The Type of Interval and argument must be the same.
Postconditions: Checks if value is greater than the upper limit of Interval.

Parameters:
value - value to be checked.
Returns:
true if value is greater than the upper limit of Interval; false otherwise.

compareTo

public PartialComparison compareTo(Interval<Type> obj)
Compares this object with the specified object for order. Preconditions: Objects must not be null.
Postconditions: Compares this object with the specified object for order. Returns an enumeration type that defines the order of the objects.
Comparison.LESS if first object is less than the second one.
Comparison.GREATER if first object is greater than the second one.
Comparison.EQUALS if two objects are equals.
Comparison.NONCOMPARABLE if two objects are not comparable.

Specified by:
compareTo in interface PartialComparable<Type extends java.lang.Comparable<Type>>
Parameters:
arg - Interval to be compared.
Returns:
Comparison.LESS if first object is less than the second one.
Comparison.GREATER if first object is greater than the second one.
Comparison.EQUALS if two objects are equals.
Comparison.NONCOMPARABLE if two objects are not comparable.

toString

public java.lang.String toString()
Returns a String representation of Interval. Preconditions: Interval must not be null.
Postconditions: Returns a String representation of Interval.

Overrides:
toString in class java.lang.Object
Returns:
a String representation of Interval.

equals

public boolean equals(Interval<Type> other)
Indicates whether some other Interval is "equal to" this one. Preconditions: Intervals must not be null, and their values must be the same type.
Postconditions: -comparable-partialcomparable ??

Parameters:
other - the reference Interval with which to compare.
Returns:
true if this Interval is the same as the Interval argument; false otherwise.

hashCode

public int hashCode()
Returns a hash code value for the Interval. Preconditions:Interval must not be null.
Postconditions: Returns a hash code value for the Interval.

Overrides:
hashCode in class java.lang.Object
Returns:
a hash code value for this Interval.

intersects

public boolean intersects(Interval<Type> other)
Checks if two Intervals intersected. Preconditions: Intervals must not be null, and their values must be the same type.
Postconditions: Checks the limits of two Intervals and return true if they intersected; false otherwise.

Parameters:
other - the reference Interval with which to compared.
Returns:
true if Intervals intersected; false otherwise.

intersect

public Interval<Type> intersect(Interval<Type> other)
Returns the intersect of two Intervals. Preconditions: Intervals must not be null, and their values must be the same type.
Postconditions: Returns a new Interval which includes the values that belong in the intersect of the two Intervals.

Parameters:
other - the reference Interval with which to compared.
Returns:
a new Interval which includes the values that belong in the intersect of the two Intervals.

gap

public Interval<Type> gap(Interval<Type> other)
Returns an Interval that is the gap of two Intervals. Preconditions: Intervals must not be null, and their values must be the same type.
Postconditions: Returns a new Interval that is the gap of two Intervals.

Parameters:
other - the reference Interval with which to compared.
Returns:
an Interval that is the gap of two Intervals.

complementRelativeTo

public java.util.List<Interval<Type>> complementRelativeTo(Interval<Type> other)
Returns an Interval that includes the left and right complement of this Interval relative to an other. Preconditions: Intervals must not be null, and their values must be the same type.
Postconditions: Returns a new Interval that includes all values between this lower limit and the lower limit of argument, and all values between this upper limit and the upper limit of argument.

Parameters:
other - the reference Interval with which to compared.
Returns:
an Interval that includes the left and right complement of this Interval relative to an other.
See Also:
http://en.wikipedia.org/wiki/Set_theoretic_complement