public abstract class SetOfIntegerSyntax extends Object implements Serializable, Cloneable
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
int
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 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 int
s
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.
Modifier | Constructor and Description |
---|---|
protected |
SetOfIntegerSyntax(int member)
Construct a new set-of-integer attribute containing a single integer.
|
protected |
SetOfIntegerSyntax(int[][] members)
Construct a new set-of-integer attribute with the given members in
array form.
|
protected |
SetOfIntegerSyntax(int lowerBound,
int upperBound)
Construct a new set-of-integer attribute containing a single range of
integers.
|
protected |
SetOfIntegerSyntax(String members)
Construct a new set-of-integer attribute with the given members in
string form.
|
Modifier and Type | Method and Description |
---|---|
boolean |
contains(int x)
Determine if this set-of-integer attribute contains the given value.
|
boolean |
contains(IntegerSyntax attribute)
Determine if this set-of-integer attribute contains the given integer
attribute's value.
|
boolean |
equals(Object object)
Returns whether this set-of-integer attribute is equivalent to the passed
in object.
|
int[][] |
getMembers()
Obtain this set-of-integer attribute's members in canonical array form.
|
int |
hashCode()
Returns a hash code value for this set-of-integer attribute.
|
int |
next(int x)
Determine the smallest integer in this set-of-integer attribute that is
greater than the given value.
|
String |
toString()
Returns a string value corresponding to this set-of-integer attribute.
|
protected SetOfIntegerSyntax(String members)
members
- Set members in string form. If null, an empty set is
constructed.IllegalArgumentException
- (Unchecked exception) Thrown if members
does not
obey the proper syntax.protected SetOfIntegerSyntax(int[][] members)
members
- Set members in array form. If null, an empty set is
constructed.NullPointerException
- (Unchecked exception) Thrown if any element of
members
is null.IllegalArgumentException
- (Unchecked exception) Thrown 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.protected SetOfIntegerSyntax(int member)
member
- Set member.IllegalArgumentException
- (Unchecked exception) Thrown if member
is less than
zero.protected SetOfIntegerSyntax(int lowerBound, int upperBound)
lowerBound
- Lower bound of the range.upperBound
- Upper bound of the range.IllegalArgumentException
- (Unchecked exception) Thrown if the range is non-null and
lowerBound
is less than zero.public int[][] getMembers()
public boolean contains(int x)
x
- Integer value.x
, false otherwise.public boolean contains(IntegerSyntax attribute)
attribute
- Integer attribute.theAttribute
's value, false otherwise.public int next(int x)
-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); }
x
- Integer value.x
, or -1
if no integer in
this set-of-integer attribute is greater than x
.public boolean equals(Object object)
object
is not null.
object
is an instance of class SetOfIntegerSyntax.
object
's
members are the same.
equals
in class Object
object
- Object to compare to.object
is equivalent to this
set-of-integer attribute, false otherwise.Object.hashCode()
,
HashMap
public int hashCode()
hashCode
in class Object
Object.equals(java.lang.Object)
,
System.identityHashCode(java.lang.Object)
public String toString()
"i"
if
the lower bound equals the upper bound or
"i-j"
otherwise. Submit a bug or feature
For further API reference and developer documentation, see Java SE Documentation. That documentation contains more detailed, developer-targeted descriptions, with conceptual overviews, definitions of terms, workarounds, and working code examples.
Copyright © 1993, 2012, Oracle and/or its affiliates. All rights reserved.