Package com.jidesoft.range
Class CombinedNumericRange
- java.lang.Object
-
- com.jidesoft.range.AbstractRange<T>
-
- com.jidesoft.range.AbstractNumericRange<java.lang.Double>
-
- com.jidesoft.range.CombinedNumericRange
-
public class CombinedNumericRange extends AbstractNumericRange<java.lang.Double>
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
Constructors Constructor Description CombinedNumericRange()
Using this constructor relies on the user subsequently calling add() to add a range
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description CombinedNumericRange
add(Range<java.lang.Double> range)
Add a new range to this combined range.void
adjust(java.lang.Double lower, java.lang.Double upper)
Calls to this method throw an UnsupportedOprationException.boolean
contains(java.lang.Double x)
This range contains some point iff one or more of its sub-ranges contain that pointRange<java.lang.Double>
createIntermediate(Range<java.lang.Double> targetRange, double position)
NumericRange
getRange(double leadingMarginProportion, double trailingMarginProportion)
Returns a new numeric range that is based on this range, but with a margin introduced at each end.java.lang.Double
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
rangeCount()
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.java.lang.String
toString()
java.lang.Double
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
-
-
-
-
Method Detail
-
add
public CombinedNumericRange add(Range<java.lang.Double> range)
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
public java.lang.Double lower()
The lower value in the range; here, the same asminimum
- Returns:
- the smallest value of the range
-
upper
public java.lang.Double 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
public void adjust(java.lang.Double lower, java.lang.Double upper)
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:
java.lang.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
public boolean contains(java.lang.Double x)
This range contains some point iff one or more of its sub-ranges contain that point- 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
public NumericRange getRange(double leadingMarginProportion, double trailingMarginProportion)
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
public Range<java.lang.Double> createIntermediate(Range<java.lang.Double> targetRange, double position)
- Specified by:
createIntermediate
in classAbstractRange<java.lang.Double>
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
-