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.StringPROPERTY_COMPARATORstatic java.lang.StringPROPERTY_SORTEDstatic java.lang.StringPROPERTY_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.voidadjust(T lower, T upper)Not supported for Category Rangesbooleancontains(Category<T> value)Determines whether the category range contains the specified category valuebooleancontains(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.booleanequals(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()inthashCode()booleanisSorted()Returns a value to indicate whether the categories of the range are sortedjava.util.Iterator<Category<T>>iterator()Returns an iterator for the category valuesTlower()doublemaximum()This may be the numeric representation of upper() or it may be rounded up.doubleminimum()This may be the numeric representation of lower() or it may be rounded down.intposition(T value)voidreset()Reset the maximum and minimum.voidsetComparator(java.util.Comparator<T> comparator)Specify the comparator that will be used to sort the values in the range.voidsetMaximum(double value)voidsetMinimum(double value)voidsetSorted(boolean sorted)Specify whether the categories of the range should be sorted.doublesize()Returns the size of the range, as given by the maximum minus the minimum.java.lang.StringtoString()Tupper()-
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 withtruebut 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:
copyin classAbstractRange<T>
-
lower
public T lower()
-
upper
public T upper()
-
maximum
public double maximum()
Description copied from interface:RangeThis may be the numeric representation of upper() or it may be rounded up.- Specified by:
maximumin interfaceRange<T>- Returns:
- the maximum value for the axis in the range
- See Also:
Range.maximum()
-
minimum
public double minimum()
Description copied from interface:RangeThis may be the numeric representation of lower() or it may be rounded down.- Specified by:
minimumin 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:
sizein 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:
iteratorin 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:
hashCodein classjava.lang.Object
-
equals
public boolean equals(java.lang.Object obj)
- Overrides:
equalsin 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:
createIntermediatein 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:
toStringin classjava.lang.Object
-
-