KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > javax > print > attribute > standard > NumberUpSupported


1 /*
2  * @(#)NumberUpSupported.java 1.7 04/05/05
3  *
4  * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
5  * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
6  */

7 package javax.print.attribute.standard;
8
9 import javax.print.attribute.Attribute JavaDoc;
10 import javax.print.attribute.SetOfIntegerSyntax JavaDoc;
11 import javax.print.attribute.SupportedValuesAttribute JavaDoc;
12
13 /**
14  * Class NumberUpSupported is a printing attribute class, a set of integers,
15  * that gives the supported values for a {@link NumberUp NumberUp} attribute.
16  * <P>
17  * <B>IPP Compatibility:</B> The NumberUpSupported attribute's canonical array
18  * form gives the lower and upper bound for each range of number-up to be
19  * included in an IPP "number-up-supported" attribute. See class {@link
20  * javax.print.attribute.SetOfIntegerSyntax SetOfIntegerSyntax} for an
21  * explanation of canonical array form. The category name returned by
22  * <CODE>getName()</CODE> gives the IPP attribute name.
23  * <P>
24  *
25  * @author Alan Kaminsky
26  */

27 public final class NumberUpSupported extends SetOfIntegerSyntax JavaDoc
28     implements SupportedValuesAttribute JavaDoc {
29
30      private static final long serialVersionUID = -1041573395759141805L;
31
32
33     /**
34      * Construct a new number up supported attribute with the given members.
35      * The supported values for NumberUp are specified in "array form;" see
36      * class
37      * {@link javax.print.attribute.SetOfIntegerSyntax SetOfIntegerSyntax}
38      * for an explanation of array form.
39      *
40      * @param members Set members in array form.
41      *
42      * @exception NullPointerException
43      * (unchecked exception) Thrown if <CODE>members</CODE> is null or
44      * any element of <CODE>members</CODE> is null.
45      * @exception IllegalArgumentException
46      * (unchecked exception) Thrown if any element of
47      * <CODE>members</CODE> is not a length-one or length-two array. Also
48      * thrown if <CODE>members</CODE> is a zero-length array or if any
49      * member of the set is less than 1.
50      */

51     public NumberUpSupported(int[][] members) {
52     super (members);
53     if (members == null) {
54         throw new NullPointerException JavaDoc("members is null");
55     }
56     int[][] myMembers = getMembers();
57     int n = myMembers.length;
58     if (n == 0) {
59         throw new IllegalArgumentException JavaDoc("members is zero-length");
60     }
61     int i;
62     for (i = 0; i < n; ++ i) {
63         if (myMembers[i][0] < 1) {
64         throw new IllegalArgumentException JavaDoc
65             ("Number up value must be > 0");
66         }
67     }
68     }
69
70     /**
71      * Construct a new number up supported attribute containing a single
72      * integer. That is, only the one value of NumberUp is supported.
73      *
74      * @param member Set member.
75      *
76      * @exception IllegalArgumentException
77      * (Unchecked exception) Thrown if <CODE>member</CODE> is less than
78      * 1.
79      */

80     public NumberUpSupported(int member) {
81     super (member);
82     if (member < 1) {
83         throw new IllegalArgumentException JavaDoc("Number up value must be > 0");
84     }
85     }
86
87     /**
88      * Construct a new number up supported attribute containing a single range
89      * of integers. That is, only those values of NumberUp in the one range are
90      * supported.
91      *
92      * @param lowerBound Lower bound of the range.
93      * @param upperBound Upper bound of the range.
94      *
95      * @exception IllegalArgumentException
96      * (Unchecked exception) Thrown if a null range is specified or if a
97      * non-null range is specified with <CODE>lowerBound</CODE> less than
98      * 1.
99      */

100     public NumberUpSupported(int lowerBound, int upperBound) {
101     super (lowerBound, upperBound);
102     if (lowerBound > upperBound) {
103         throw new IllegalArgumentException JavaDoc("Null range specified");
104     } else if (lowerBound < 1) {
105         throw new IllegalArgumentException JavaDoc
106         ("Number up value must be > 0");
107     }
108     }
109
110     /**
111      * Returns whether this number up supported attribute is equivalent to the
112      * passed in object. To be equivalent, all of the following conditions
113      * must be true:
114      * <OL TYPE=1>
115      * <LI>
116      * <CODE>object</CODE> is not null.
117      * <LI>
118      * <CODE>object</CODE> is an instance of class NumberUpSupported.
119      * <LI>
120      * This number up supported attribute's members and <CODE>object</CODE>'s
121      * members are the same.
122      * </OL>
123      *
124      * @param object Object to compare to.
125      *
126      * @return True if <CODE>object</CODE> is equivalent to this number up
127      * supported attribute, false otherwise.
128      */

129     public boolean equals(Object JavaDoc object) {
130     return (super.equals (object) &&
131         object instanceof NumberUpSupported JavaDoc);
132     }
133
134     /**
135      * Get the printing attribute class which is to be used as the "category"
136      * for this printing attribute value.
137      * <P>
138      * For class NumberUpSupported, the
139      * category is class NumberUpSupported itself.
140      *
141      * @return Printing attribute class (category), an instance of class
142      * {@link java.lang.Class java.lang.Class}.
143      */

144     public final Class JavaDoc<? extends Attribute JavaDoc> getCategory() {
145     return NumberUpSupported JavaDoc.class;
146     }
147
148     /**
149      * Get the name of the category of which this attribute value is an
150      * instance.
151      * <P>
152      * For class NumberUpSupported, the
153      * category name is <CODE>"number-up-supported"</CODE>.
154      *
155      * @return Attribute category name.
156      */

157     public final String JavaDoc getName() {
158     return "number-up-supported";
159     }
160     
161 }
162
Popular Tags