Class JDFNumberRange

  • All Implemented Interfaces:
    JDFBaseDataTypes

    public class JDFNumberRange
    extends JDFRange
    This class represents a number range (JDFNumberRange). It is a whitespace separated list of 2 double values separated by a tilde "~", for example "1.23 ~ 1.45"
    • Constructor Summary

      Constructors 
      Constructor Description
      JDFNumberRange()
      constructs an empty JDFNumberRange
      JDFNumberRange​(double x)
      constructs a JDFNumberRange, both values are equal ("from x to x")
      JDFNumberRange​(double xmin, double xmax)
      constructor, creates a JDFNumberRange bounded by two double values ("from xmin to xmax")
      JDFNumberRange​(java.lang.String s)
      constructs a JDFNumberRange with the values of the given string
      JDFNumberRange​(JDFNumberRange nr)
      copy constructor, creates a JDFNumberRange with the given JDFNumberRange
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      static JDFNumberRange createNumberRange​(java.lang.String s)
      factory for JDFNumberRange that silently returns null in case of illegal strings
      boolean equals​(java.lang.Object other)
      equals - returns true if both JDFNumberRange are equal otherwise false, the difference must be smaller than EPSILON
      double getLeft()
      getLeft - returns the left value of the range
      protected java.lang.Object getLeftObject()  
      java.lang.String getLeftString()
      returns the string representation of the left value of the range
      java.lang.String getLeftString​(int precision)
      returns the string representation of the left value of the range
      double getLowerValue()
      getLowerValue - returns the lower value of the bounds
      for example 4.5~6.3 returns 4.5, 7.0~5.9 returns 5.9
      double getRight()
      getRight - returns the right value of the range
      protected java.lang.Object getRightObject()  
      java.lang.String getRightString()
      returns the string representation of the left value of the range
      java.lang.String getRightString​(int precision)
      returns the string representation of the left value of the range
      java.lang.String getString​(int precision)
      get a string with precision digits after each decimal
      double getUpperValue()
      getUpperValue - return the upper value of the bounds
      for example 4.5~6.3 returns 6.3, 7.0~5.9 returns 7.0
      int hashCode()
      hashCode complements equals() to fulfill the equals/hashCode contract
      protected void init​(double xmin, double xmax)
      Initialization
      protected boolean inObjectRange​(java.lang.Object other)  
      boolean inRange​(double x)
      inRange - returns true if (lower value >= x <= upper value)
      boolean isPartOfRange​(JDFRange ra)
      isPartOfRange - is range 'r' within this range?
      boolean isValid​(java.lang.String s)
      isValid - validate the given String
      void scale​(double f)
      scale - scales both values
      void setLeft​(double x)
      setLeft - sets the left double object
      void setRight​(double x)
      setRight - sets the right double object
      • Methods inherited from class java.lang.Object

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

      • JDFNumberRange

        public JDFNumberRange()
        constructs an empty JDFNumberRange
      • JDFNumberRange

        public JDFNumberRange​(double x)
        constructs a JDFNumberRange, both values are equal ("from x to x")
        Parameters:
        x - the given double
      • JDFNumberRange

        public JDFNumberRange​(double xmin,
                              double xmax)
        constructor, creates a JDFNumberRange bounded by two double values ("from xmin to xmax")
        Parameters:
        xmin - the given min value
        xmax - the given max value
      • JDFNumberRange

        public JDFNumberRange​(JDFNumberRange nr)
        copy constructor, creates a JDFNumberRange with the given JDFNumberRange
        Parameters:
        nr -
      • JDFNumberRange

        public JDFNumberRange​(java.lang.String s)
                       throws java.util.zip.DataFormatException
        constructs a JDFNumberRange with the values of the given string
        Parameters:
        s - the given string
        Throws:
        java.util.zip.DataFormatException - - if the String has not a valid format
    • Method Detail

      • createNumberRange

        public static JDFNumberRange createNumberRange​(java.lang.String s)
        factory for JDFNumberRange that silently returns null in case of illegal strings
        Parameters:
        s - the string to parse
        Returns:
        the JDFNumberRange, null if s is not compatible
      • init

        protected void init​(double xmin,
                            double xmax)
        Initialization
        Parameters:
        xmin - left value
        xmax - right value
      • isValid

        public boolean isValid​(java.lang.String s)
        isValid - validate the given String
        Parameters:
        s - the given string to validate
        Returns:
        boolean - false if the String has not a valid format
      • equals

        public boolean equals​(java.lang.Object other)
        equals - returns true if both JDFNumberRange are equal otherwise false, the difference must be smaller than EPSILON
        Overrides:
        equals in class JDFRange
        Parameters:
        other - the object to compare with this
        Returns:
        boolean - true if equal otherwise false
      • hashCode

        public int hashCode()
        hashCode complements equals() to fulfill the equals/hashCode contract
        Overrides:
        hashCode in class JDFRange
        Returns:
        int - hash code of this
      • getLeftString

        public java.lang.String getLeftString()
        returns the string representation of the left value of the range
        Returns:
        the left value of the range
      • getLeft

        public double getLeft()
        getLeft - returns the left value of the range
        Returns:
        double - the left value of the range
      • getLeftString

        public java.lang.String getLeftString​(int precision)
        returns the string representation of the left value of the range
        Overrides:
        getLeftString in class JDFRange
        Parameters:
        precision -
        Returns:
      • getRightString

        public java.lang.String getRightString​(int precision)
        returns the string representation of the left value of the range
        Overrides:
        getRightString in class JDFRange
        Parameters:
        precision -
        Returns:
      • getRightString

        public java.lang.String getRightString()
        returns the string representation of the left value of the range
        Returns:
        the left value of the range
      • getRight

        public double getRight()
        getRight - returns the right value of the range
        Returns:
        double - the right value of the range
      • setLeft

        public void setLeft​(double x)
        setLeft - sets the left double object
        Parameters:
        x - the left double object
      • setRight

        public void setRight​(double x)
        setRight - sets the right double object
        Parameters:
        x - the right double object
      • scale

        public void scale​(double f)
        scale - scales both values
        Parameters:
        f - the scaling factor
      • getLowerValue

        public double getLowerValue()
        getLowerValue - returns the lower value of the bounds
        for example 4.5~6.3 returns 4.5, 7.0~5.9 returns 5.9
        Returns:
        double - the lower value of the range
      • getUpperValue

        public double getUpperValue()
        getUpperValue - return the upper value of the bounds
        for example 4.5~6.3 returns 6.3, 7.0~5.9 returns 7.0
        Returns:
        double - the upper value of the range
      • inRange

        public boolean inRange​(double x)
        inRange - returns true if (lower value >= x <= upper value)
        Parameters:
        x - comparison value
        Returns:
        boolean - true if x in range
      • isPartOfRange

        public boolean isPartOfRange​(JDFRange ra)
        isPartOfRange - is range 'r' within this range?
        Specified by:
        isPartOfRange in class JDFRange
        Parameters:
        r - the range to test
        Returns:
        boolean - true if range 'r' is within this range, else false
      • getRightObject

        protected java.lang.Object getRightObject()
        Specified by:
        getRightObject in class JDFRange
      • getLeftObject

        protected java.lang.Object getLeftObject()
        Specified by:
        getLeftObject in class JDFRange
      • inObjectRange

        protected boolean inObjectRange​(java.lang.Object other)
        Overrides:
        inObjectRange in class JDFRange
      • getString

        public java.lang.String getString​(int precision)
        Description copied from class: JDFRange
        get a string with precision digits after each decimal
        Overrides:
        getString in class JDFRange
        Returns:
        See Also:
        JDFRange.getString(int)