Package com.jidesoft.range
Class CategoryRange<T>
- java.lang.Object
-
- com.jidesoft.range.AbstractRange<T>
-
- com.jidesoft.range.CategoryRange<T>
-
public class CategoryRange<T> extends AbstractRange<T> implements java.lang.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
Fields Modifier and Type Field Description static java.lang.String
PROPERTY_COMPARATOR
static java.lang.String
PROPERTY_SORTED
static java.lang.String
PROPERTY_VALUES
-
Fields inherited from interface com.jidesoft.range.Range
PROPERTY_MAX, PROPERTY_MIN
-
-
Constructor Summary
Constructors Constructor Description CategoryRange()
CategoryRange(CategoryRange<T> categoryRange)
Create a new CategoryRange by copying an existing one.CategoryRange(java.util.Set<T> values)
Create a CategoryRange from a set of values.CategoryRange(T... values)
Create a CategoryRange from the supplied values
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description CategoryRange<T>
add(Category<T> c)
Adds a category to the range.void
adjust(T lower, T upper)
Not supported for Category Rangesboolean
contains(Category<T> value)
Determines whether the category range contains the specified category valueboolean
contains(T x)
Determines whether the category range contains the supplied possible valueRange<T>
copy()
Range<T>
createIntermediate(Range<T> target, double position)
Creates an intermediate range between this range and a target range.boolean
equals(java.lang.Object obj)
Category<T>
getCategory(int position)
Returns the category with the supplied position value.java.util.List<Category<T>>
getCategoryValues()
Returns a list of the category values in this rangejava.util.Comparator<T>
getComparator()
Returns the comparator that, if set, will be used to sort the values in the rangejava.util.List<T>
getPossibleValues()
int
hashCode()
boolean
isSorted()
Returns a value to indicate whether the categories of the range are sortedjava.util.Iterator<Category<T>>
iterator()
Returns an iterator for the category valuesT
lower()
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
position(T value)
void
reset()
Reset the maximum and minimum.void
setComparator(java.util.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.java.lang.String
toString()
T
upper()
-
Methods inherited from class com.jidesoft.range.AbstractRange
addPropertyChangeListener, compareTo, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getPropertyChangeListeners, getPropertyChangeListeners, removePropertyChangeListener
-
-
-
-
Field Detail
-
PROPERTY_VALUES
public static final java.lang.String PROPERTY_VALUES
- See Also:
- Constant Field Values
-
PROPERTY_COMPARATOR
public static final java.lang.String PROPERTY_COMPARATOR
- See Also:
- Constant Field Values
-
PROPERTY_SORTED
public static final java.lang.String PROPERTY_SORTED
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
CategoryRange
public CategoryRange()
-
CategoryRange
public CategoryRange(T... values)
Create a CategoryRange from the supplied values- Parameters:
values
- the values.
-
CategoryRange
public CategoryRange(java.util.Set<T> values)
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
public CategoryRange(CategoryRange<T> 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 Detail
-
getPossibleValues
public java.util.List<T> getPossibleValues()
-
getCategory
public Category<T> getCategory(int position)
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
public CategoryRange<T> add(Category<T> c)
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
public java.util.Comparator<T> 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
public void setComparator(java.util.Comparator<T> comparator)
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
public Range<T> copy()
- Overrides:
copy
in classAbstractRange<T>
-
lower
public T lower()
-
upper
public T upper()
-
maximum
public double maximum()
Description copied from interface:Range
This may be the numeric representation of upper() or it may be rounded up.- Specified by:
maximum
in interfaceRange<T>
- Returns:
- the maximum value for the axis in the range
- See Also:
Range.maximum()
-
minimum
public double minimum()
Description copied from interface:Range
This may be the numeric representation of lower() or it may be rounded down.- Specified by:
minimum
in interfaceRange<T>
- Returns:
- the minimum value for the axis in the range
- See Also:
Range.minimum()
-
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()- Specified by:
size
in interfaceRange<T>
- Returns:
- the size of the range
- See Also:
Range.size()
-
position
public int position(T value)
-
contains
public boolean contains(T x)
Determines whether the category range contains the supplied possible value
-
contains
public boolean contains(Category<T> value)
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
public java.util.Iterator<Category<T>> iterator()
Returns an iterator for the category values- Specified by:
iterator
in interfacejava.lang.Iterable<T>
- Returns:
- an iterator for the category values
-
getCategoryValues
public java.util.List<Category<T>> getCategoryValues()
Returns a list of the category values in this range- Returns:
- a list of category values
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classjava.lang.Object
-
equals
public boolean equals(java.lang.Object obj)
- Overrides:
equals
in classjava.lang.Object
-
createIntermediate
public Range<T> createIntermediate(Range<T> target, double position)
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
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
-