Package org.cip4.jdflib.datatypes
Class JDFIntegerRangeList
java.lang.Object
org.cip4.jdflib.datatypes.JDFRangeList
org.cip4.jdflib.datatypes.JDFIntegerRangeList
- All Implemented Interfaces:
JDFBaseDataTypes
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"
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.cip4.jdflib.datatypes.JDFBaseDataTypes
JDFBaseDataTypes.EnumFitsValue -
Field Summary
Fields inherited from class org.cip4.jdflib.datatypes.JDFRangeList
rangeListFields inherited from interface org.cip4.jdflib.datatypes.JDFBaseDataTypes
EPSILON, MAX_CMYK_COLOR, MAX_LAB_COLOR, MAX_MATRIX_DIMENSION, MAX_RECTANGLE_DIMENSION, MAX_RGB_COLOR, MAX_SHAPE_DIMENSION, MAX_XY_DIMENSION -
Constructor Summary
ConstructorsConstructorDescriptionconstructs an empty range listJDFIntegerRangeList(int[] array) constructs a JDFIntegerRangeList with the given array of intsconstructs a JDFIntegerRangeList with the given string the default value for -1 is set to 0, i.e positive and negative numbers are handled explicitlyJDFIntegerRangeList(String s, int xdef) constructs a JDFIntegerRangeList with the given String and sets the number of itemsconstructs a JDFIntegerRangeList with the given JDFIntegerRange and sets xDefconstructs a JDFIntegerRangeList with the given JDFIntegerRangeList and sets the number of items -
Method Summary
Modifier and TypeMethodDescriptionvoidappend(int x) append - appends an integer to the last IntegerRange of the IntegerRangelist if possible, examples if the last range list element looks like:voidappend(int xMin, int xMax) append - appends a new IntegerRange to the IntegerRangeListvoidappend - appends a new IntegerRange to the IntegerRangeListstatic JDFIntegerRangeListcreateIntegerRangeList(String rangelist) create a JDFIntegerRangeList from a string - return null if no godeepCopy()deepCopy - a deep copy of this JDFIntegerRangeListintgetDef()getDef - gets xDef, the default value which is used for negative numbersintgetElement(int i) Element - value of the ith element in the range.intgetElementCount - returns the number of elements in the list.getIntegerList - returns this integer range list as a JDFIntegerListstatic JDFIntegerRangeListgetIntegerRangeList(String rangelist) Deprecated.use createIntegerRangeListbooleaninRange(int x) inRange - returns true if the given int value is in one of the ranges of the range listbooleanisOrdered - tests if 'this' is OrderedRangeListbooleanisOverlapping(JDFIntegerRange newRange, JDFIntegerRange oldRange) isOverlappingbooleanisUniqueOrdered - tests if 'this' is UniqueOrdered RangeListbooleanisValid - validate the given Stringvoidnormalize(boolean bSort) normalize this range by removing any consecutive entries and creating ranges insteadvoidsetDef(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 listvoidsetString - parse the given string and set the integer ranges
-
Constructor Details
-
JDFIntegerRangeList
public JDFIntegerRangeList()constructs an empty range list -
JDFIntegerRangeList
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:
DataFormatException- - if the String has not a valid format
-
JDFIntegerRangeList
constructs a JDFIntegerRangeList with the given String and sets the number of items- Parameters:
s- - the given stringxdef- - the default value that- Throws:
DataFormatException- - if the String has not a valid format
-
JDFIntegerRangeList
constructs a JDFIntegerRangeList with the given JDFIntegerRangeList and sets the number of items- Parameters:
irl- the given JDFIntegerRangeList
-
JDFIntegerRangeList
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 Details
-
getIntegerRangeList
Deprecated.use createIntegerRangeListcreate a JDFIntegerRangeList from a string - return null if no go- Parameters:
rangelist-- Returns:
-
createIntegerRangeList
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
setString - parse the given string and set the integer ranges- Parameters:
s- the given string- Throws:
DataFormatException- - if the String has not a valid format
-
isValid
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
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:
NoSuchElementException- - if the index is out of range
-
append
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 rangexMax- 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
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:
isOrderedin classJDFRangeList- Returns:
- boolean - true if 'this' is a OrdneredRangeList
-
isUniqueOrdered
public boolean isUniqueOrdered()isUniqueOrdered - tests if 'this' is UniqueOrdered RangeList- Specified by:
isUniqueOrderedin classJDFRangeList- Returns:
- boolean - true if 'this' is UniqueOrdered RangeList
-
deepCopy
deepCopy - a deep copy of this JDFIntegerRangeList- Returns:
- JDFIntegerRangeList - this object
- Throws:
DataFormatException
-
isOverlapping
isOverlapping- Parameters:
newRange- the range to check, if is overlapping one of the ranges in the listx: x.upper < y.lower,
z: z.lower > y.upper,
one of these situation, means there is no overlappingnewRange-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
-