 java.lang.Object

 javax.print.attribute.SetOfIntegerSyntax

 All Implemented Interfaces:
Serializable
,Cloneable
 Direct Known Subclasses:
CopiesSupported
,JobImpressionsSupported
,JobKOctetsSupported
,JobMediaSheetsSupported
,NumberUpSupported
,PageRanges
public abstract class SetOfIntegerSyntax extends Object implements Serializable, Cloneable
ClassSetOfIntegerSyntax
is an abstract base class providing the common implementation of all attributes whose value is a set of nonnegative integers. This includes attributes whose value is a single range of integers and attributes whose value is a set of ranges of integers.You can construct an instance of
SetOfIntegerSyntax
by giving it in "string form." The string consists of zero or more commaseparated integer groups. Each integer group consists of either one integer, two integers separated by a hyphen (
), or two integers separated by a colon (:
). Each integer consists of one or more decimal digits (0
through9
). Whitespace characters cannot appear within an integer but are otherwise ignored. For example:""
,"1"
,"510"
,"1:2, 4"
.You can also construct an instance of
SetOfIntegerSyntax
by giving it in "array form." Array form consists of an array of zero or more integer groups where each integer group is a length1 or length2 array ofint
s; for example,int[0][]
,int[][]{{1}}
,int[][]{{5,10}}
,int[][]{{1,2},{4}}
.In both string form and array form, each successive integer group gives a range of integers to be included in the set. The first integer in each group gives the lower bound of the range; the second integer in each group gives the upper bound of the range; if there is only one integer in the group, the upper bound is the same as the lower bound. If the upper bound is less than the lower bound, it denotes a
null
range (no values). If the upper bound is equal to the lower bound, it denotes a range consisting of a single value. If the upper bound is greater than the lower bound, it denotes a range consisting of more than one value. The ranges may appear in any order and are allowed to overlap. The union of all the ranges gives the set's contents. Once aSetOfIntegerSyntax
instance is constructed, its value is immutable.The
SetOfIntegerSyntax
object's value is actually stored in "canonical array form." This is the same as array form, except there are nonull
ranges; the members of the set are represented in as few ranges as possible (i.e., overlapping ranges are coalesced); the ranges appear in ascending order; and each range is always represented as a lengthtwo array ofint
s in the form {lower bound, upper bound}. An empty set is represented as a zerolength array.Class
SetOfIntegerSyntax
has operations to return the set's members in canonical array form, to test whether a given integer is a member of the set, and to iterate through the members of the set. See Also:
 Serialized Form


Constructor Summary
Constructors Modifier Constructor Description protected
SetOfIntegerSyntax(int member)
Construct a new setofinteger attribute containing a single integer.protected
SetOfIntegerSyntax(int[][] members)
Construct a new setofinteger attribute with the given members in array form.protected
SetOfIntegerSyntax(int lowerBound, int upperBound)
Construct a new setofinteger attribute containing a single range of integers.protected
SetOfIntegerSyntax(String members)
Construct a new setofinteger attribute with the given members in string form.

Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
contains(int x)
Determine if this setofinteger attribute contains the given value.boolean
contains(IntegerSyntax attribute)
Determine if this setofinteger attribute contains the given integer attribute's value.boolean
equals(Object object)
Returns whether this setofinteger attribute is equivalent to the passed in object.int[][]
getMembers()
Obtain this setofinteger attribute's members in canonical array form.int
hashCode()
Returns a hash code value for this setofinteger attribute.int
next(int x)
Determine the smallest integer in this setofinteger attribute that is greater than the given value.String
toString()
Returns a string value corresponding to this setofinteger attribute.



Constructor Detail

SetOfIntegerSyntax
protected SetOfIntegerSyntax(String members)
Construct a new setofinteger attribute with the given members in string form. Parameters:
members
 set members in string form. Ifnull
, an empty set is constructed. Throws:
IllegalArgumentException
 ifmembers
does not obey the proper syntax

SetOfIntegerSyntax
protected SetOfIntegerSyntax(int[][] members)
Construct a new setofinteger attribute with the given members in array form. Parameters:
members
 set members in array form. Ifnull
, an empty set is constructed. Throws:
NullPointerException
 if any element ofmembers
isnull
IllegalArgumentException
 if any element ofmembers
is not a lengthone or lengthtwo array or if anynonnull
range inmembers
has a lower bound less than zero

SetOfIntegerSyntax
protected SetOfIntegerSyntax(int member)
Construct a new setofinteger attribute containing a single integer. Parameters:
member
 set member Throws:
IllegalArgumentException
 ifmember
is negative

SetOfIntegerSyntax
protected SetOfIntegerSyntax(int lowerBound, int upperBound)
Construct a new setofinteger attribute containing a single range of integers. If the lower bound is greater than the upper bound (a null range), an empty set is constructed. Parameters:
lowerBound
 Lower bound of the rangeupperBound
 Upper bound of the range Throws:
IllegalArgumentException
 if the range isnonnull
andlowerBound
is less than zero


Method Detail

getMembers
public int[][] getMembers()
Obtain this setofinteger attribute's members in canonical array form. The returned array is "safe;" the client may alter it without affecting this setofinteger attribute. Returns:
 this setofinteger attribute's members in canonical array form

contains
public boolean contains(int x)
Determine if this setofinteger attribute contains the given value. Parameters:
x
 the Integer value Returns:
true
if this setofinteger attribute contains the valuex
,false
otherwise

contains
public boolean contains(IntegerSyntax attribute)
Determine if this setofinteger attribute contains the given integer attribute's value. Parameters:
attribute
 the Integer attribute Returns:
true
if this setofinteger attribute containsattribute
's value,false
otherwise

next
public int next(int x)
Determine the smallest integer in this setofinteger attribute that is greater than the given value. If there are no integers in this setofinteger attribute greater than the given value,1
is returned. (Since a setofinteger attribute can only contain nonnegative values,1
will never appear in the set.) You can use thenext()
method to iterate through the integer values in a setofinteger attribute in ascending order, like this:SetOfIntegerSyntax attribute = . . .; int i = 1; while ((i = attribute.next (i)) != 1) { foo (i); }
 Parameters:
x
 the Integer value Returns:
 the smallest integer in this setofinteger attribute that is
greater than
x
, or1
if no integer in this setofinteger attribute is greater thanx
.

equals
public boolean equals(Object object)
Returns whether this setofinteger attribute is equivalent to the passed in object. To be equivalent, all of the following conditions must be true:object
is notnull
.object
is an instance of classSetOfIntegerSyntax
. This setofinteger attribute's members and
object
's members are the same.
 Overrides:
equals
in classObject
 Parameters:
object
Object
to compare to Returns:
true
ifobject
is equivalent to this setofinteger attribute,false
otherwise See Also:
Object.hashCode()
,HashMap

hashCode
public int hashCode()
Returns a hash code value for this setofinteger attribute. The hash code is the sum of the lower and upper bounds of the ranges in the canonical array form, or 0 for an empty set. Overrides:
hashCode
in classObject
 Returns:
 a hash code value for this object.
 See Also:
Object.equals(java.lang.Object)
,System.identityHashCode(java.lang.Object)

toString
public String toString()
Returns a string value corresponding to this setofinteger attribute. The string value is a zerolength string if this set is empty. Otherwise, the string value is a commaseparated list of the ranges in the canonical array form, where each range is represented as"i"
if the lower bound equals the upper bound or"ij"
otherwise.

