Package info.monitorenter.util
Class Range
- java.lang.Object
-
- info.monitorenter.util.Range
-
- All Implemented Interfaces:
java.io.Serializable
public class Range extends java.lang.Object implements java.io.SerializableA simple data structure that defines a minimum and a maximum and knows, what lies within it and what not.- Author:
- Achim Westermann
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description protected doublem_maxThe upper bound of this range.protected doublem_minThe lower bound of this range.static RangeRANGE_UNBOUNDEDThe unbounded range.
-
Constructor Summary
Constructors Constructor Description Range(double min, double max)Constructs a new Range that covers the given bounds.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanensureContained(double contain)Force this Range to cover the given value.booleanequals(java.lang.Object obj)doublegetExtent()Returns the extent of this range.doublegetMax()Returns the upper bound of this range.doublegetMin()Returns the lower bound of this range.inthashCode()booleanisContained(double contained)Returns true if the given value is covered by this range.voidmimic(Range r)Mutator that shifts this range to the given one.voidsetMax(double max)Sets the max value of this range.voidsetMin(double min)Sets the min value of this range.java.lang.StringtoString()
-
-
-
Field Detail
-
RANGE_UNBOUNDED
public static final Range RANGE_UNBOUNDED
The unbounded range.
-
m_max
protected double m_max
The upper bound of this range.
-
m_min
protected double m_min
The lower bound of this range.
-
-
Method Detail
-
ensureContained
public boolean ensureContained(double contain)
Force this Range to cover the given value.- Parameters:
contain- the value that has to be contained within this range.- Returns:
- true, if an internal modification of one bound took place, false else.
-
equals
public boolean equals(java.lang.Object obj)
- Overrides:
equalsin classjava.lang.Object- See Also:
Object.equals(java.lang.Object)
-
getExtent
public double getExtent()
Returns the extent of this range.- Returns:
- the extent of this range.
-
getMax
public double getMax()
Returns the upper bound of this range.- Returns:
- the upper bound of this range.
-
getMin
public double getMin()
Returns the lower bound of this range.- Returns:
- the lower bound of this range.
-
hashCode
public int hashCode()
- Overrides:
hashCodein classjava.lang.Object- See Also:
Object.hashCode()
-
isContained
public boolean isContained(double contained)
Returns true if the given value is covered by this range.- Parameters:
contained- the value to test wether it is contained within this range.- Returns:
- true if the given value is covered by this range.
-
mimic
public void mimic(Range r)
Mutator that shifts this range to the given one.This is support for "clone" without allocations in case range instances are reused.
- Parameters:
r- the range to copy from.
-
setMax
public final void setMax(double max)
Sets the max value of this range.- Parameters:
max- the max to set.
-
setMin
public final void setMin(double min)
Sets the min value of this range.- Parameters:
min- the min to set
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object- See Also:
Object.toString()
-
-