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>>

public class CategoryRange<T> extends AbstractRange<T> implements 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 Details

  • Constructor Details

    • CategoryRange

      public CategoryRange()
    • CategoryRange

      public CategoryRange(T... values)
      Create a CategoryRange from the supplied values
      Parameters:
      values - the values.
    • CategoryRange

      public CategoryRange(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 an upper() and a lower() 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 Details

    • getPossibleValues

      public 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 with true 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 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(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 class AbstractRange<T>
    • lower

      public T lower()
      Specified by:
      lower in interface Range<T>
      Returns:
      the smallest value of the range
    • upper

      public T upper()
      Specified by:
      upper in interface Range<T>
      Returns:
      the largest value of the range
    • adjust

      public void adjust(T lower, T upper)
      Not supported for Category Ranges
      Specified by:
      adjust in interface Range<T>
      Parameters:
      lower - the new smallest value of the range
      upper - the new largest value of the range
    • 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 interface Range<T>
      Returns:
      the maximum value for the axis in the range
      See Also:
    • 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 interface Range<T>
      Returns:
      the minimum value for the axis in the range
      See Also:
    • 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 interface Range<T>
      Returns:
      the size of the range
      See Also:
    • position

      public int position(T value)
    • contains

      public boolean contains(T x)
      Determines whether the category range contains the supplied possible value
      Specified by:
      contains in interface Range<T>
      Returns:
      a boolean to indicate whether the supplied point lies within the range
    • 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 Iterator<Category<T>> iterator()
      Returns an iterator for the category values
      Specified by:
      iterator in interface Iterable<T>
      Returns:
      an iterator for the category values
    • getCategoryValues

      public 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 class Object
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class 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 class AbstractRange<T>
      Parameters:
      target - the target range of the morph
      position - a value between 0 and 1 indicating the position of the morph
      Returns:
      a CategoryRange
    • toString

      public String toString()
      Overrides:
      toString in class Object