Package com.jidesoft.range
Class CategoryRange<T>
java.lang.Object
com.jidesoft.range.AbstractRange<T>
com.jidesoft.range.CategoryRange<T>
- All Implemented Interfaces:
Range<T>
,Comparable<Range>
,Iterable<Category<T>>
Note that this class is iterable so you can use it in an advanced for.. loop
- Author:
- Simon White (swhite@catalysoft.com)
-
Field Summary
FieldsFields inherited from interface com.jidesoft.range.Range
PROPERTY_MAX, PROPERTY_MIN
-
Constructor Summary
ConstructorsConstructorDescriptionCategoryRange
(CategoryRange<T> categoryRange) Create a new CategoryRange by copying an existing one.CategoryRange
(Set<T> values) Create a CategoryRange from a set of values.CategoryRange
(T... values) Create a CategoryRange from the supplied values -
Method Summary
Modifier and TypeMethodDescriptionAdds a category to the range.void
Not supported for Category Rangesboolean
Determines whether the category range contains the specified category valueboolean
Determines whether the category range contains the supplied possible valuecopy()
createIntermediate
(Range<T> target, double position) Creates an intermediate range between this range and a target range.boolean
getCategory
(int position) Returns the category with the supplied position value.Returns a list of the category values in this rangeReturns the comparator that, if set, will be used to sort the values in the rangeint
hashCode()
boolean
isSorted()
Returns a value to indicate whether the categories of the range are sortediterator()
Returns an iterator for the category valueslower()
double
maximum()
This may be the numeric representation of upper() or it may be rounded up.double
minimum()
This may be the numeric representation of lower() or it may be rounded down.int
void
reset()
Reset the maximum and minimum.void
setComparator
(Comparator<T> comparator) Specify the comparator that will be used to sort the values in the range.void
setMaximum
(double value) void
setMinimum
(double value) void
setSorted
(boolean sorted) Specify whether the categories of the range should be sorted.double
size()
Returns the size of the range, as given by the maximum minus the minimum.toString()
upper()
Methods inherited from class com.jidesoft.range.AbstractRange
addPropertyChangeListener, compareTo, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getPropertyChangeListeners, getPropertyChangeListeners, removePropertyChangeListener
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
Field Details
-
PROPERTY_VALUES
- See Also:
-
PROPERTY_COMPARATOR
- See Also:
-
PROPERTY_SORTED
- See Also:
-
-
Constructor Details
-
CategoryRange
public CategoryRange() -
CategoryRange
Create a CategoryRange from the supplied values- Parameters:
values
- the values.
-
CategoryRange
Create a CategoryRange from a set of values. Note that internally, a list is created out of the set so that the class can reliably determine anupper()
and alower()
value.- Parameters:
values
- - the set of possible values
-
CategoryRange
Create a new CategoryRange by copying an existing one. This would allow you subsequently to tweak the values in the copy without affecting the original.- Parameters:
categoryRange
- the category range instance to copy
-
-
Method Details
-
getPossibleValues
-
getCategory
Returns the category with the supplied position value. (Note that the first position is 1, not 0.)- Parameters:
position
- the position of a category along an axis- Returns:
- the category with the supplied position value.
-
add
Adds a category to the range. Note that after adding categories, you will need to call reset() if you want the minimum and maximum numeric values of the range to be recomputed.
This method fires a property change event, but to avoid cloning a list for efficiency, the old value is always null
- Parameters:
c
- the category to add- Returns:
- this range
-
setSorted
public void setSorted(boolean sorted) Specify whether the categories of the range should be sorted. If you call this method withtrue
but do not explicitly set a comparator for the sort ordering, then the natural ordering of the objects (using java.util.Comparable) will be used. If the objects do not implement Comparable, then a string comparator is constructed based on the toString() method of the object.- Parameters:
sorted
- whether the categories of the range should be sorted
-
isSorted
public boolean isSorted()Returns a value to indicate whether the categories of the range are sorted- Returns:
- a value to indicate whether the categories of the range are sorted
-
getComparator
Returns the comparator that, if set, will be used to sort the values in the range- Returns:
- the comparator that, if set, will be used to sort the values in the range
-
setComparator
Specify the comparator that will be used to sort the values in the range. Calling this method implicitly calls setSorted(): the sorted property will be set to true if the comparator is non-null and will be set to false if the comparator is null- Parameters:
comparator
- the comparator to be used to sort the values in the range
-
copy
- Overrides:
copy
in classAbstractRange<T>
-
lower
-
upper
-
adjust
Not supported for Category Ranges -
maximum
public double maximum()Description copied from interface:Range
This may be the numeric representation of upper() or it may be rounded up. -
minimum
public double minimum()Description copied from interface:Range
This may be the numeric representation of lower() or it may be rounded down. -
reset
public void reset()Reset the maximum and minimum. They will be recomputed on the next call to minimum() or maximum() respectively -
setMinimum
public void setMinimum(double value) -
setMaximum
public void setMaximum(double value) -
size
public double size()Returns the size of the range, as given by the maximum minus the minimum. To compute the size of the range in terms of the number of members in the category, use getPossibleValue().size() -
position
-
contains
Determines whether the category range contains the supplied possible value -
contains
Determines whether the category range contains the specified category value- Parameters:
value
- the category value.- Returns:
- true if the range contains the specified value. Otherwise false.
-
iterator
Returns an iterator for the category values -
getCategoryValues
Returns a list of the category values in this range- Returns:
- a list of category values
-
hashCode
public int hashCode() -
equals
-
createIntermediate
Creates an intermediate range between this range and a target range. Used for range morphing.- Specified by:
createIntermediate
in classAbstractRange<T>
- Parameters:
target
- the target range of the morphposition
- a value between 0 and 1 indicating the position of the morph- Returns:
- a CategoryRange
-
toString
-