APIdia Launch Partner
Top Description Fields Constructors Methods
javax.print.attribute

public abstract Class SetOfIntegerSyntax

extends Object
implements Serializable, Cloneable
Class Inheritance
All Implemented Interfaces
java.lang.Cloneable, java.io.Serializable
Known Direct Subclasses
javax.print.attribute.standard.CopiesSupported, javax.print.attribute.standard.JobImpressionsSupported, javax.print.attribute.standard.JobKOctetsSupported, javax.print.attribute.standard.JobMediaSheetsSupported, javax.print.attribute.standard.NumberUpSupported, javax.print.attribute.standard.PageRanges
Imports
java.io.Serial, .Serializable, java.util.Vector

Class SetOfIntegerSyntax 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 comma-separated 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 through 9). Whitespace characters cannot appear within an integer but are otherwise ignored. For example: "", "1", "5-10", "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 length-1 or length-2 array of ints; 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 a SetOfIntegerSyntax 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 no null 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 length-two array of ints in the form {lower bound, upper bound}. An empty set is represented as a zero-length 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.

Authors
David Mendenhall, Alan Kaminsky

Field Summary

Modifier and TypeField and Description
private int[][]
members

This set's members in canonical array form.

private static final long
serialVersionUID

Use serialVersionUID from JDK 1.4 for interoperability.

Constructor Summary

AccessConstructor and Description
protected
SetOfIntegerSyntax(String
set members in string form. If null, an empty set is constructed.
members
)

Construct a new set-of-integer attribute with the given members in string form.

protected
SetOfIntegerSyntax(int[][]
set members in array form. If null, an empty set is constructed.
members
)

Construct a new set-of-integer attribute with the given members in array form.

protected
SetOfIntegerSyntax(int
set member
member
)

Construct a new set-of-integer attribute containing a single integer.

protected
SetOfIntegerSyntax(int
Lower bound of the range
lowerBound
,
int
Upper bound of the range
upperBound
)

Construct a new set-of-integer attribute containing a single range of integers.

Method Summary

Modifier and TypeMethod and Description
private static void
accumulate(Vector<int[]> ranges, int lb, int ub)

Accumulate the given range (lb ..

private static int[][]
canonicalArrayForm(Vector<int[]> ranges)

Convert the given vector of int[] objects to canonical array form.

public boolean

Returns:

true if this set-of-integer attribute contains the value x, false otherwise
contains
(int
the Integer value
x
)

Determine if this set-of-integer attribute contains the given value.

public boolean

Returns:

true if this set-of-integer attribute contains attribute's value, false otherwise
contains
(IntegerSyntax
the Integer attribute
attribute
)

Determine if this set-of-integer attribute contains the given integer attribute's value.

public boolean

Returns:

true if object is equivalent to this set-of-integer attribute, false otherwise
equals
(Object
Object to compare to
object
)

Overrides java.lang.Object.equals.

Returns whether this set-of-integer attribute is equivalent to the passed in object.

public int[][]

Returns:

this set-of-integer attribute's members in canonical array form
getMembers
()

Obtain this set-of-integer attribute's members in canonical array form.

public int
hashCode()

Overrides java.lang.Object.hashCode.

Returns a hash code value for this set-of-integer attribute.

public int

Returns:

the smallest integer in this set-of-integer attribute that is greater than x, or -1 if no integer in this set-of-integer attribute is greater than x.
next
(int
the Integer value
x
)

Determine the smallest integer in this set-of-integer attribute that is greater than the given value.

private static int[][]

Returns:

the canonical array form
parse
(String
the string
members
)

Parse the given string, returning canonical array form.

private static int[][]
parse(int[][] members)

Parse the given array form, returning canonical array form.

public String
toString()

Overrides java.lang.Object.toString.

Returns a string value corresponding to this set-of-integer attribute.

Inherited from java.lang.Object:
clonefinalizegetClassnotifynotifyAllwaitwaitwait

Field Detail

membersback to summary
private int[][] members

This set's members in canonical array form.

serialVersionUIDback to summary
private static final long serialVersionUID

Use serialVersionUID from JDK 1.4 for interoperability.

Annotations
@Serial

Constructor Detail

SetOfIntegerSyntaxback to summary
protected SetOfIntegerSyntax(String members)

Construct a new set-of-integer attribute with the given members in string form.

Parameters
members:String

set members in string form. If null, an empty set is constructed.

Exceptions
IllegalArgumentException:
if members does not obey the proper syntax
SetOfIntegerSyntaxback to summary
protected SetOfIntegerSyntax(int[][] members)

Construct a new set-of-integer attribute with the given members in array form.

Parameters
members:int[][]

set members in array form. If null, an empty set is constructed.

Exceptions
NullPointerException:
if any element of members is null
IllegalArgumentException:
if any element of members is not a length-one or length-two array or if any non-null range in members has a lower bound less than zero
SetOfIntegerSyntaxback to summary
protected SetOfIntegerSyntax(int member)

Construct a new set-of-integer attribute containing a single integer.

Parameters
member:int

set member

Exceptions
IllegalArgumentException:
if member is negative
SetOfIntegerSyntaxback to summary
protected SetOfIntegerSyntax(int lowerBound, int upperBound)

Construct a new set-of-integer 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:int

Lower bound of the range

upperBound:int

Upper bound of the range

Exceptions
IllegalArgumentException:
if the range is non-null and lowerBound is less than zero

Method Detail

accumulateback to summary
private static void accumulate(Vector<int[]> ranges, int lb, int ub)

Accumulate the given range (lb .. ub) into the canonical array form into the given vector of int[] objects.

canonicalArrayFormback to summary
private static int[][] canonicalArrayForm(Vector<int[]> ranges)

Convert the given vector of int[] objects to canonical array form.

containsback to summary
public boolean contains(int x)

Determine if this set-of-integer attribute contains the given value.

Parameters
x:int

the Integer value

Returns:boolean

true if this set-of-integer attribute contains the value x, false otherwise

containsback to summary
public boolean contains(IntegerSyntax attribute)

Determine if this set-of-integer attribute contains the given integer attribute's value.

Parameters
attribute:IntegerSyntax

the Integer attribute

Returns:boolean

true if this set-of-integer attribute contains attribute's value, false otherwise

equalsback to summary
public boolean equals(Object object)

Overrides java.lang.Object.equals.

Returns whether this set-of-integer attribute is equivalent to the passed in object. To be equivalent, all of the following conditions must be true:

  1. object is not null.
  2. object is an instance of class SetOfIntegerSyntax.
  3. This set-of-integer attribute's members and object's members are the same.
Parameters
object:Object

Object to compare to

Returns:boolean

true if object is equivalent to this set-of-integer attribute, false otherwise

Annotations
@Override
getMembersback to summary
public int[][] getMembers()

Obtain this set-of-integer attribute's members in canonical array form. The returned array is "safe;" the client may alter it without affecting this set-of-integer attribute.

Returns:int[][]

this set-of-integer attribute's members in canonical array form

hashCodeback to summary
public int hashCode()

Overrides java.lang.Object.hashCode.

Returns a hash code value for this set-of-integer 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.

Annotations
@Override
nextback to summary
public int next(int x)

Determine the smallest integer in this set-of-integer attribute that is greater than the given value. If there are no integers in this set-of-integer attribute greater than the given value, -1 is returned. (Since a set-of-integer attribute can only contain nonnegative values, -1 will never appear in the set.) You can use the next() method to iterate through the integer values in a set-of-integer attribute in ascending order, like this:

    SetOfIntegerSyntax attribute = . . .;
    int i = -1;
    while ((i = attribute.next (i)) != -1)
        {
        foo (i);
        }
Parameters
x:int

the Integer value

Returns:int

the smallest integer in this set-of-integer attribute that is greater than x, or -1 if no integer in this set-of-integer attribute is greater than x.

parseback to summary
private static int[][] parse(String members)

Parse the given string, returning canonical array form.

Parameters
members:String

the string

Returns:int[][]

the canonical array form

parseback to summary
private static int[][] parse(int[][] members)

Parse the given array form, returning canonical array form.

toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Returns a string value corresponding to this set-of-integer attribute. The string value is a zero-length string if this set is empty. Otherwise, the string value is a comma-separated 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 "i-j" otherwise.

Annotations
@Override