Package com.jidesoft.range
Class CombinedNumericRange
- All Implemented Interfaces:
Range<Double>
,Comparable<Range>
A little convenience class to compute the maximum and minimum values of multiple ranges.
- Author:
- swhite@catalysoft.com
-
Field Summary
Fields inherited from interface com.jidesoft.range.Range
PROPERTY_MAX, PROPERTY_MIN
-
Constructor Summary
ConstructorsConstructorDescriptionUsing this constructor relies on the user subsequently calling add() to add a range -
Method Summary
Modifier and TypeMethodDescriptionAdd a new range to this combined range.void
Calls to this method throw an UnsupportedOprationException.boolean
This range contains some point iff one or more of its sub-ranges contain that pointcreateIntermediate
(Range<Double> targetRange, double position) getRange
(double leadingMarginProportion, double trailingMarginProportion) Returns a new numeric range that is based on this range, but with a margin introduced at each end.lower()
The lower value in the range; here, the same asminimum
double
maximum()
Lazily calculates the maximum value in the rangedouble
minimum()
Lazily calculates the minimum value in the rangeint
Returns the number of sub-ranges contained by this rangedouble
size()
The size of the range is computed as the maximum minus the minimum value.toString()
upper()
The upper value in the range; here, the same asmaximum()
Methods inherited from class com.jidesoft.range.AbstractRange
addPropertyChangeListener, compareTo, copy, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getPropertyChangeListeners, getPropertyChangeListeners, removePropertyChangeListener
-
Constructor Details
-
CombinedNumericRange
public CombinedNumericRange()Using this constructor relies on the user subsequently calling add() to add a range
-
-
Method Details
-
add
Add a new range to this combined range. Notice the method returns this instance, so method calls can be chained together. If you pass null to this method the CombinedNumericRange remains unchanged; an Exception is NOT thrown.- Parameters:
range
- the new range to add- Returns:
- this instance
-
lower
The lower value in the range; here, the same asminimum
- Returns:
- the smallest value of the range
-
upper
The upper value in the range; here, the same asmaximum()
- Returns:
- the largest value of the range
-
rangeCount
public int rangeCount()Returns the number of sub-ranges contained by this range- Returns:
- the number of sub-ranges in this range
-
adjust
Calls to this method throw an UnsupportedOprationException. The idea is that in the case of this class we don't want to be able to mess with the lower and upper bounds as they are computed from the supplied range values. If the class needed to recompute the lower and upper bounds any previous adjustment that had been made through this method would have been lost.- Parameters:
lower
- the new smallest value of the rangeupper
- the new largest value of the range- Throws:
UnsupportedOperationException
-
maximum
public double maximum()Lazily calculates the maximum value in the range- Returns:
- The numeric value of the largest value to include in the range.
-
minimum
public double minimum()Lazily calculates the minimum value in the range- Returns:
- the numeric value of the smallest value to include in the range.
-
contains
This range contains some point iff one or more of its sub-ranges contain that point- Parameters:
x
-- Returns:
- a boolean to indicate whether the supplied point lies within the range
-
size
public double size()The size of the range is computed as the maximum minus the minimum value. -
getRange
Returns a new numeric range that is based on this range, but with a margin introduced at each end. The margin proportion is a value between 0 and 1. For example to add a 20% margin to each end use parameters of 0.2 for both the leading and trailing margin proportion.- Parameters:
leadingMarginProportion
- how much margin to add at the low end of the rangetrailingMarginProportion
- how much margin to add at the top end of the range- Returns:
- a new NumericRange object with margins added
-
createIntermediate
- Specified by:
createIntermediate
in classAbstractRange<Double>
-
toString
-