Class Range

  • All Implemented Interfaces:
    java.io.Serializable

    public class Range
    extends java.lang.Object
    implements java.io.Serializable
    A simple data structure that defines a minimum and a maximum and knows, what lies within it and what not.

    Author:
    Achim Westermann
    See Also:
    Serialized Form
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected double m_max
      The upper bound of this range.
      protected double m_min
      The lower bound of this range.
      static Range RANGE_UNBOUNDED
      The unbounded range.
    • Constructor Summary

      Constructors 
      Constructor Description
      Range​(double min, double max)
      Constructs a new Range that covers the given bounds.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean ensureContained​(double contain)
      Force this Range to cover the given value.
      boolean equals​(java.lang.Object obj)  
      double getExtent()
      Returns the extent of this range.
      double getMax()
      Returns the upper bound of this range.
      double getMin()
      Returns the lower bound of this range.
      int hashCode()  
      boolean isContained​(double contained)
      Returns true if the given value is covered by this range.
      void mimic​(Range r)
      Mutator that shifts this range to the given one.
      void setMax​(double max)
      Sets the max value of this range.
      void setMin​(double min)
      Sets the min value of this range.
      java.lang.String toString()  
      • Methods inherited from class java.lang.Object

        clone, finalize, getClass, notify, notifyAll, wait, wait, wait
    • Field Detail

      • RANGE_UNBOUNDED

        public static final Range RANGE_UNBOUNDED
        The unbounded range.
      • m_max

        protected double m_max
        The upper bound of this range.
      • m_min

        protected double m_min
        The lower bound of this range.
    • Constructor Detail

      • Range

        public Range​(double min,
                     double max)
        Constructs a new Range that covers the given bounds.

        Parameters:
        min - the lower bound for the range.
        max - the upper bound for the range.
    • Method Detail

      • ensureContained

        public boolean ensureContained​(double contain)
        Force this Range to cover the given value.

        Parameters:
        contain - the value that has to be contained within this range.
        Returns:
        true, if an internal modification of one bound took place, false else.
      • equals

        public boolean equals​(java.lang.Object obj)
        Overrides:
        equals in class java.lang.Object
        See Also:
        Object.equals(java.lang.Object)
      • getExtent

        public double getExtent()
        Returns the extent of this range.

        Returns:
        the extent of this range.
      • getMax

        public double getMax()
        Returns the upper bound of this range.

        Returns:
        the upper bound of this range.
      • getMin

        public double getMin()
        Returns the lower bound of this range.

        Returns:
        the lower bound of this range.
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object
        See Also:
        Object.hashCode()
      • isContained

        public boolean isContained​(double contained)
        Returns true if the given value is covered by this range.

        Parameters:
        contained - the value to test wether it is contained within this range.
        Returns:
        true if the given value is covered by this range.
      • mimic

        public void mimic​(Range r)
        Mutator that shifts this range to the given one.

        This is support for "clone" without allocations in case range instances are reused.

        Parameters:
        r - the range to copy from.
      • setMax

        public final void setMax​(double max)
        Sets the max value of this range.

        Parameters:
        max - the max to set.
      • setMin

        public final void setMin​(double min)
        Sets the min value of this range.

        Parameters:
        min - the min to set
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
        See Also:
        Object.toString()