Class JDFIntegerRangeList

  • All Implemented Interfaces:
    JDFBaseDataTypes

    public class JDFIntegerRangeList
    extends JDFRangeList
    This class is a representation of an integer range list (JDFIntegerRangeList). It is a whitespace separated list of integer ranges, for example "12~15 19~33"
    • Constructor Detail

      • JDFIntegerRangeList

        public JDFIntegerRangeList()
        constructs an empty range list
      • JDFIntegerRangeList

        public JDFIntegerRangeList​(java.lang.String s)
                            throws java.util.zip.DataFormatException
        constructs a JDFIntegerRangeList with the given string the default value for -1 is set to 0, i.e positive and negative numbers are handled explicitly
        Parameters:
        s - - the given string
        Throws:
        java.util.zip.DataFormatException - - if the String has not a valid format
      • JDFIntegerRangeList

        public JDFIntegerRangeList​(java.lang.String s,
                                   int xdef)
                            throws java.util.zip.DataFormatException
        constructs a JDFIntegerRangeList with the given String and sets the number of items
        Parameters:
        s - - the given string
        xdef - - the default value that
        Throws:
        java.util.zip.DataFormatException - - if the String has not a valid format
      • JDFIntegerRangeList

        public JDFIntegerRangeList​(JDFIntegerRangeList irl)
        constructs a JDFIntegerRangeList with the given JDFIntegerRangeList and sets the number of items
        Parameters:
        irl - the given JDFIntegerRangeList
      • JDFIntegerRangeList

        public JDFIntegerRangeList​(JDFIntegerRange ir)
        constructs a JDFIntegerRangeList with the given JDFIntegerRange and sets xDef
        Parameters:
        ir - the given JDFIntegerRange
      • JDFIntegerRangeList

        public JDFIntegerRangeList​(int[] array)
        constructs a JDFIntegerRangeList with the given array of ints
        Parameters:
        array - the given JDFIntegerRange
    • Method Detail

      • getIntegerRangeList

        @Deprecated
        public static JDFIntegerRangeList getIntegerRangeList​(java.lang.String rangelist)
        Deprecated.
        use createIntegerRangeList
        create a JDFIntegerRangeList from a string - return null if no go
        Parameters:
        rangelist -
        Returns:
      • createIntegerRangeList

        public static JDFIntegerRangeList createIntegerRangeList​(java.lang.String rangelist)
        create a JDFIntegerRangeList from a string - return null if no go
        Parameters:
        rangelist -
        Returns:
      • inRange

        public boolean inRange​(int x)
        inRange - returns true if the given int value is in one of the ranges of the range list
        Parameters:
        x - the given int value to compare
        Returns:
        boolean - true if in range otherwise false
      • setString

        public void setString​(java.lang.String s)
                       throws java.util.zip.DataFormatException
        setString - parse the given string and set the integer ranges
        Parameters:
        s - the given string
        Throws:
        java.util.zip.DataFormatException - - if the String has not a valid format
      • isValid

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

        public int getElementCount()
        getElementCount - returns the number of elements in the list. On the C++ side of the JDF library this method is called NElements.
        E.g. the following list has 14 elements: "1~5 10~15 20~22" if any if any range cannot be resolved due to an unknown negative value without a known default, -1 is returned
        Returns:
        int - the number of elements in this range, -1 if any range cannot be resolved
      • getElement

        public int getElement​(int i)
                       throws java.util.NoSuchElementException
        Element - value of the ith element in the range. If the index is negative, 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.

        performace warning: don't loop over getElement for potentially large lists with many individual elements.
        Prefer to call getIntegerList() and loop over the list.

        Parameters:
        i - the position, if it is a negative value start counting from the right side +1
        Returns:
        int - the value at the ith position
        Throws:
        java.util.NoSuchElementException - - if the index is out of range
      • append

        public void append​(JDFIntegerRange r)
        append - appends a new IntegerRange to the IntegerRangeList
        Parameters:
        r - the given JDFIntegerRange
      • append

        public void append​(int xMin,
                           int xMax)
        append - appends a new IntegerRange to the IntegerRangeList
        Parameters:
        xMin - the left value of the new range
        xMax - the right value of the new range
      • append

        public void append​(int x)
        append - appends an integer to the last IntegerRange of the IntegerRangelist if possible, examples if the last range list element looks like:
         "3˜5"        append(6)   -> "3˜6"
         "5"          append(6)   -> "5˜6"
         "5"          append(7)   -> "5 7"
         "5 6"        append(7)   -> "5 ˜ 7"
         "3˜7 5˜7"    append(8)   -> "3˜7 5˜8"
         "3˜7 5˜9"    append(8)   -> "3˜7 5˜9 8"
         "3˜7 5˜7"    append(18)  -> "3˜7 5˜7 18"
         
        note that lists are not preserved. If you want to guarantee individual entries use append(x,x);
        Parameters:
        x - the given int x
      • getIntegerList

        public JDFIntegerList getIntegerList()
        getIntegerList - returns this integer range list as a JDFIntegerList
        Returns:
        JDFIntegerList - the integer range list as a JDFIntegerList
      • setDef

        public void setDef​(int xdef)
        setDef - sets xDef, the default value which is used for negative numbers
        if xdef==0 (the default), the neg numbers themselves are used
        the value represents the index that is one past the end of the list
        Parameters:
        xdef - one 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
      • isOrdered

        public boolean isOrdered()
        isOrdered - tests if 'this' is OrderedRangeList
        Specified by:
        isOrdered in class JDFRangeList
        Returns:
        boolean - true if 'this' is a OrdneredRangeList
      • isUniqueOrdered

        public boolean isUniqueOrdered()
        isUniqueOrdered - tests if 'this' is UniqueOrdered RangeList
        Specified by:
        isUniqueOrdered in class JDFRangeList
        Returns:
        boolean - true if 'this' is UniqueOrdered RangeList
      • deepCopy

        public JDFIntegerRangeList deepCopy()
                                     throws java.util.zip.DataFormatException
        deepCopy - a deep copy of this JDFIntegerRangeList
        Returns:
        JDFIntegerRangeList - this object
        Throws:
        java.util.zip.DataFormatException
      • isOverlapping

        public boolean isOverlapping​(JDFIntegerRange newRange,
                                     JDFIntegerRange oldRange)
        isOverlapping
        Parameters:
        newRange - the range to check, if is overlapping one of the ranges in the list

        x: x.upper < y.lower,
        z: z.lower > y.upper,
        one of these situation, means there is no overlapping

        newRange -
        oldRange - the JDFRangeList removed from the RangeList, before check for overlap. If null, the oldRange is ignored
        Returns:
        boolean - true if there is an overlapping, otherwise false
      • normalize

        public void normalize​(boolean bSort)
        normalize this range by removing any consecutive entries and creating ranges instead
        Parameters:
        bSort - if true, sort the rangelist prior to normalizing