Class JDFIntegerRange

java.lang.Object
org.cip4.jdflib.datatypes.JDFRange
org.cip4.jdflib.datatypes.JDFIntegerRange
All Implemented Interfaces:
JDFBaseDataTypes

public class JDFIntegerRange extends JDFRange
This class represents an integer range (JDFIntegerRange). It is a pair of 2 integer values separated by a tilde "~", for example "123 ~ 145" negative values are treated differently depending on the value of m_defaultXDef @see getDefaultDef
  • Nested Class Summary

    Nested classes/interfaces inherited from interface org.cip4.jdflib.datatypes.JDFBaseDataTypes

    JDFBaseDataTypes.EnumFitsValue
  • Field Summary

  • Constructor Summary

    Constructors
    Constructor
    Description
    constructs an empty integer range
    constructs an integer range with the given int (both values are equal)
    JDFIntegerRange(int xmin, int xmax)
    constructs an integer range with the given int values
    JDFIntegerRange(int xmin, int xmax, int xdef)
    constructs an integer range with the given int values
    constructs an integer range with the given string
    JDFIntegerRange(String s, int xdef)
    constructs an integer range with the given string
    constructs an integer range with a given JDFIntegerRange
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    append(int x)
    append - appends a value to this range, returns true if possible returns false if the element is not the next element in the list, it only appends on the right side of the range.
    factory for JDFIntegerRange that silently returns null in case of illegal strings
    boolean
    equals(Object other)
    equals - returns true if both JDFIntegerRange are equal otherwise false
    int
    getDef - gets xDef, the default value which is used for negative numbers
    static int
    getDefaultDef - gets the preset for xDef, which will be used when constructing an IntegerRange
    the value represents the index that is one past the end of the list
    if xdef==0 (the default), the neg numbers themselves are used
    int
    getElement(int i)
    Element - value of the ith element in the range.
    If the index is negativ the position is counted from the end of the range.
    int
    getElementCount - returns the number of elements in this range, on the C++ side of the JDF library this method is called NElements if any if any range cannot be resolved due to an unknown negative value without a known default or a negative value > default, -1 is returned
    getIntegerList - returns the integer range as an integer list
    for example an integer range of "5~9" will be returned as "5 6 7 8 9"
    create a JDFIntegerRange from a string - return null if no go
    int
    getLeft - returns the left int object
    protected Integer
     
    getLeftString(int precision)
     
    int
    getLowerValue - returns the lower value of the bounds for example 4~6 return 4, 7~5 return 5
    int
    getRight - returns the right int object
    protected Integer
     
    getRightString(int precision)
     
    int
    getUpperValue - returns the upper value of the bounds for example 4~6 return 6, 7~5 return 7
    int
    hashCode complements equals() to fulfill the equals/hashCode contract
    protected void
    init(int xmin, int xmax, int xdef)
    Initialization
    protected boolean
     
    boolean
    inRange(int x)
    inRange - returns true if (lower value >= x <= upper value)
    boolean
    isPartOfRange - is range 'r' within this range?
    boolean
    isValid - validate the given String
    void
    scale(int f)
    scale - scales both values but NOT the default
    void
    setDef(int xdef)
    setDef - sets xDef, the default value which is used for negative numbers
    the value represents the index that is one past the end of the list
    if xdef==0 (the default), the neg numbers themselves are used
    static void
    setDefaultDef(int xdef)
    setDefaultDef - sets the preset for xDef, which will be used when constructing an IntegerRange
    the value represents the index that is one past the end of the list
    if xdef==0 (the default), the neg numbers themselves are used
    void
    setLeft(int x)
    setLeft - sets the left int object
    void
    setLowerValue - sets the lower value of the bounds
    void
    setRight(int x)
    setRight - sets the right int object
    void
    setUpperValue - sets the upper value of the bounds

    Methods inherited from class org.cip4.jdflib.datatypes.JDFRange

    getString, getXJDFString, toString

    Methods inherited from class java.lang.Object

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

    • JDFIntegerRange

      public JDFIntegerRange()
      constructs an empty integer range
    • JDFIntegerRange

      public JDFIntegerRange(int x)
      constructs an integer range with the given int (both values are equal)
      Parameters:
      x - the given min and max value
    • JDFIntegerRange

      public JDFIntegerRange(int xmin, int xmax)
      constructs an integer range with the given int values
      Parameters:
      xmin - the given min value
      xmax - the given max value
    • JDFIntegerRange

      public JDFIntegerRange(int xmin, int xmax, int xdef)
      constructs an integer range with the given int values
      Parameters:
      xmin - the given min value
      xmax - the given max value
      xdef - number of items
    • JDFIntegerRange

      public JDFIntegerRange(JDFIntegerRange ir)
      constructs an integer range with a given JDFIntegerRange
      Parameters:
      ir - the given JDFIntegerRange
    • JDFIntegerRange

      public JDFIntegerRange(String s) throws DataFormatException
      constructs an integer range with the given string
      Parameters:
      s - the given string
      Throws:
      DataFormatException - - if the String has not a valid format
    • JDFIntegerRange

      public JDFIntegerRange(String s, int xdef) throws DataFormatException
      constructs an integer range with the given string
      Parameters:
      s - the given string
      xdef - value which is used for negative numbers the value that -1 will represent in this range
      Throws:
      DataFormatException - - if the String has not a valid format
  • Method Details

    • createIntegerRange

      public static JDFIntegerRange createIntegerRange(String s)
      factory for JDFIntegerRange that silently returns null in case of illegal strings
      Parameters:
      s - the string to parse
      Returns:
      the JDFIntegerRange, null if s is not compatible
    • getIntegerRange

      public static JDFIntegerRange getIntegerRange(String range)
      create a JDFIntegerRange from a string - return null if no go
      Parameters:
      range -
      Returns:
    • init

      protected void init(int xmin, int xmax, int xdef)
      Initialization
    • isValid

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

      public boolean equals(Object other)
      equals - returns true if both JDFIntegerRange are equal otherwise false
      Overrides:
      equals in class JDFRange
      Parameters:
      other - Object to compare
      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
    • getLeft

      public int getLeft()
      getLeft - returns the left int object
      Returns:
      int - the left int object
    • setLeft

      public void setLeft(int x)
      setLeft - sets the left int object
      Parameters:
      x - the left int object
    • getRight

      public int getRight()
      getRight - returns the right int object
      Returns:
      int - the right int
    • scale

      public void scale(int f)
      scale - scales both values but NOT the default
      Parameters:
      f - the scaling factor
    • setRight

      public void setRight(int x)
      setRight - sets the right int object
      Parameters:
      x - the right int object
    • getLowerValue

      public int getLowerValue()
      getLowerValue - returns the lower value of the bounds for example 4~6 return 4, 7~5 return 5
      Returns:
      int - the lower value of the range
    • setLowerValue

      public void setLowerValue(int x)
      setLowerValue - sets the lower value of the bounds
      Parameters:
      x - the new lower value of the range
    • getUpperValue

      public int getUpperValue()
      getUpperValue - returns the upper value of the bounds for example 4~6 return 6, 7~5 return 7
      Returns:
      int the upper value of the range
    • setUpperValue

      public void setUpperValue(int x)
      setUpperValue - sets the upper value of the bounds
      Parameters:
      x - the new upper value of the range
    • inRange

      public boolean inRange(int 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 r)
      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
    • getElementCount

      public int getElementCount()
      getElementCount - returns the number of elements in this range, on the C++ side of the JDF library this method is called NElements if any if any range cannot be resolved due to an unknown negative value without a known default or a negative value > default, -1 is returned
      Returns:
      int - the number of elements in this range, -1 if any range cannot be resolved
    • append

      public boolean append(int x)
      append - appends a value to this range, returns true if possible returns false if the element is not the next element in the list, it only appends on the right side of the range. For example:
       "3˜5"        append(6)   -> "3˜6"
       "5"          append(6)   -> "5˜6"
       "5"          append(7)   -> "5 7"
       "5˜9"        append(6)   -> "5˜9 6"
       "7˜5"        append(4)   -> "7˜4"
       
      Parameters:
      x - the new value
      Returns:
      boolean - true if successful
    • getElement

      public int getElement(int i) throws NoSuchElementException
      Element - value of the ith element in the range.
      If the index is negativ the position is counted from the end of the range. For example the range is 3~7, the 2nd element is 5 and the -2nd element is 6. On the C++ side of the JDF library this method is called Element.
      Parameters:
      i - the position, if it is a negativ value start counting from the right side +1
      Returns:
      int the value at the ith position
      Throws:
      NoSuchElementException - - if the index is out of range
    • setDef

      public void setDef(int xdef)
      setDef - sets xDef, the default value which is used for negative numbers
      the value represents the index that is one past the end of the list
      if xdef==0 (the default), the neg numbers themselves are used
      Parameters:
      xdef - the value that will represent negative values in this range
    • setDefaultDef

      public static void setDefaultDef(int xdef)
      setDefaultDef - sets the preset for xDef, which will be used when constructing an IntegerRange
      the value represents the index that is one past the end of the list
      if xdef==0 (the default), the neg numbers themselves are used
      Parameters:
      xdef - - (int)1 above the value that -1 will represent in this range i.e. the value that -0, were it possible to specify, would represent
    • getDefaultDef

      public static int getDefaultDef()
      getDefaultDef - gets the preset for xDef, which will be used when constructing an IntegerRange
      the value represents the index that is one past the end of the list
      if xdef==0 (the default), the neg numbers themselves are used
      Returns:
      int - (int)1 above the value that -1 will represent in this range i.e. the value that -0, were it possible to specify, would represent
    • getDef

      public int getDef()
      getDef - gets xDef, the default value which is used for negative numbers
      Returns:
      int - one above the value that -1 will represent in this range i.e. the value that -0, were it possible to specify, would represent
    • getIntegerList

      public JDFIntegerList getIntegerList()
      getIntegerList - returns the integer range as an integer list
      for example an integer range of "5~9" will be returned as "5 6 7 8 9"
      Returns:
      JDFIntegerList - the integer list
    • getRightObject

      protected Integer getRightObject()
      Specified by:
      getRightObject in class JDFRange
    • getLeftObject

      protected Integer getLeftObject()
      Specified by:
      getLeftObject in class JDFRange
    • inObjectRange

      protected boolean inObjectRange(Object other)
      Overrides:
      inObjectRange in class JDFRange
    • getRightString

      public String getRightString(int precision)
      Overrides:
      getRightString in class JDFRange
    • getLeftString

      public String getLeftString(int precision)
      Overrides:
      getLeftString in class JDFRange