Class Range
- java.lang.Object
-
- org.openstreetmap.josm.gui.mappaint.Range
-
public class Range extends java.lang.Object
A scale interval of the form "lower < x <= upper" where 0 <= lower < upper. (upper can be Double.POSITIVE_INFINITY) immutable class
-
-
Field Summary
Fields Modifier and Type Field Description private doublelowerprivate doubleupperstatic RangeZERO_TO_INFINITYThe full scale range from zero to infinity
-
Constructor Summary
Constructors Constructor Description Range(double lower, double upper)Constructs a newRange.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description booleancontains(double x)Check if a number is contained in this rangestatic Rangecut(Range a, Range b)provides the intersection of 2 overlapping rangesbooleanequals(java.lang.Object o)doublegetLower()Gets the lower bounddoublegetUpper()Gets the upper boundinthashCode()RangereduceAround(double x, Range other)under the premise, that x is within this range, and not within the other range, it shrinks this range in a way to exclude the other range, but still contain x.java.lang.StringtoString()
-
-
-
Field Detail
-
lower
private final double lower
-
upper
private final double upper
-
ZERO_TO_INFINITY
public static final Range ZERO_TO_INFINITY
The full scale range from zero to infinity
-
-
Constructor Detail
-
Range
public Range(double lower, double upper)
Constructs a newRange.- Parameters:
lower- Lower bound. Must be positive or zeroupper- Upper bound- Throws:
java.lang.IllegalArgumentException- if the range is invalid (lower < 0 || lower >= upper)
-
-
Method Detail
-
contains
public boolean contains(double x)
Check if a number is contained in this range- Parameters:
x- The number to test- Returns:
trueif it is in this range
-
cut
public static Range cut(Range a, Range b)
provides the intersection of 2 overlapping ranges- Parameters:
a- first rangeb- second range- Returns:
- intersection of
aandb
-
reduceAround
public Range reduceAround(double x, Range other)
under the premise, that x is within this range, and not within the other range, it shrinks this range in a way to exclude the other range, but still contain x. x | this (------------------------------] other (-------] or (-----------------] result (----------------]- Parameters:
x- valueother- other range- Returns:
- reduced range
-
getLower
public double getLower()
Gets the lower bound- Returns:
- The lower, exclusive, bound
-
getUpper
public double getUpper()
Gets the upper bound- Returns:
- The upper, inclusive, bound
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
equals
public boolean equals(java.lang.Object o)
- Overrides:
equalsin classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCodein classjava.lang.Object
-
-