001 /*
002 * Copyright 2000-2004 Sun Microsystems, Inc. All Rights Reserved.
003 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
004 *
005 * This code is free software; you can redistribute it and/or modify it
006 * under the terms of the GNU General Public License version 2 only, as
007 * published by the Free Software Foundation. Sun designates this
008 * particular file as subject to the "Classpath" exception as provided
009 * by Sun in the LICENSE file that accompanied this code.
010 *
011 * This code is distributed in the hope that it will be useful, but WITHOUT
012 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
013 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
014 * version 2 for more details (a copy is included in the LICENSE file that
015 * accompanied this code).
016 *
017 * You should have received a copy of the GNU General Public License version
018 * 2 along with this work; if not, write to the Free Software Foundation,
019 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
020 *
021 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
022 * CA 95054 USA or visit www.sun.com if you need additional information or
023 * have any questions.
024 */
025 package javax.print.attribute.standard;
026
027 import javax.print.attribute.Attribute;
028 import javax.print.attribute.SetOfIntegerSyntax;
029 import javax.print.attribute.SupportedValuesAttribute;
030
031 /**
032 * Class NumberUpSupported is a printing attribute class, a set of integers,
033 * that gives the supported values for a {@link NumberUp NumberUp} attribute.
034 * <P>
035 * <B>IPP Compatibility:</B> The NumberUpSupported attribute's canonical array
036 * form gives the lower and upper bound for each range of number-up to be
037 * included in an IPP "number-up-supported" attribute. See class {@link
038 * javax.print.attribute.SetOfIntegerSyntax SetOfIntegerSyntax} for an
039 * explanation of canonical array form. The category name returned by
040 * <CODE>getName()</CODE> gives the IPP attribute name.
041 * <P>
042 *
043 * @author Alan Kaminsky
044 */
045 public final class NumberUpSupported extends SetOfIntegerSyntax
046 implements SupportedValuesAttribute {
047
048 private static final long serialVersionUID = -1041573395759141805L;
049
050 /**
051 * Construct a new number up supported attribute with the given members.
052 * The supported values for NumberUp are specified in "array form;" see
053 * class
054 * {@link javax.print.attribute.SetOfIntegerSyntax SetOfIntegerSyntax}
055 * for an explanation of array form.
056 *
057 * @param members Set members in array form.
058 *
059 * @exception NullPointerException
060 * (unchecked exception) Thrown if <CODE>members</CODE> is null or
061 * any element of <CODE>members</CODE> is null.
062 * @exception IllegalArgumentException
063 * (unchecked exception) Thrown if any element of
064 * <CODE>members</CODE> is not a length-one or length-two array. Also
065 * thrown if <CODE>members</CODE> is a zero-length array or if any
066 * member of the set is less than 1.
067 */
068 public NumberUpSupported(int[][] members) {
069 super (members);
070 if (members == null) {
071 throw new NullPointerException("members is null");
072 }
073 int[][] myMembers = getMembers();
074 int n = myMembers.length;
075 if (n == 0) {
076 throw new IllegalArgumentException("members is zero-length");
077 }
078 int i;
079 for (i = 0; i < n; ++i) {
080 if (myMembers[i][0] < 1) {
081 throw new IllegalArgumentException(
082 "Number up value must be > 0");
083 }
084 }
085 }
086
087 /**
088 * Construct a new number up supported attribute containing a single
089 * integer. That is, only the one value of NumberUp is supported.
090 *
091 * @param member Set member.
092 *
093 * @exception IllegalArgumentException
094 * (Unchecked exception) Thrown if <CODE>member</CODE> is less than
095 * 1.
096 */
097 public NumberUpSupported(int member) {
098 super (member);
099 if (member < 1) {
100 throw new IllegalArgumentException(
101 "Number up value must be > 0");
102 }
103 }
104
105 /**
106 * Construct a new number up supported attribute containing a single range
107 * of integers. That is, only those values of NumberUp in the one range are
108 * supported.
109 *
110 * @param lowerBound Lower bound of the range.
111 * @param upperBound Upper bound of the range.
112 *
113 * @exception IllegalArgumentException
114 * (Unchecked exception) Thrown if a null range is specified or if a
115 * non-null range is specified with <CODE>lowerBound</CODE> less than
116 * 1.
117 */
118 public NumberUpSupported(int lowerBound, int upperBound) {
119 super (lowerBound, upperBound);
120 if (lowerBound > upperBound) {
121 throw new IllegalArgumentException("Null range specified");
122 } else if (lowerBound < 1) {
123 throw new IllegalArgumentException(
124 "Number up value must be > 0");
125 }
126 }
127
128 /**
129 * Returns whether this number up supported attribute is equivalent to the
130 * passed in object. To be equivalent, all of the following conditions
131 * must be true:
132 * <OL TYPE=1>
133 * <LI>
134 * <CODE>object</CODE> is not null.
135 * <LI>
136 * <CODE>object</CODE> is an instance of class NumberUpSupported.
137 * <LI>
138 * This number up supported attribute's members and <CODE>object</CODE>'s
139 * members are the same.
140 * </OL>
141 *
142 * @param object Object to compare to.
143 *
144 * @return True if <CODE>object</CODE> is equivalent to this number up
145 * supported attribute, false otherwise.
146 */
147 public boolean equals(Object object) {
148 return (super .equals(object) && object instanceof NumberUpSupported);
149 }
150
151 /**
152 * Get the printing attribute class which is to be used as the "category"
153 * for this printing attribute value.
154 * <P>
155 * For class NumberUpSupported, the
156 * category is class NumberUpSupported itself.
157 *
158 * @return Printing attribute class (category), an instance of class
159 * {@link java.lang.Class java.lang.Class}.
160 */
161 public final Class<? extends Attribute> getCategory() {
162 return NumberUpSupported.class;
163 }
164
165 /**
166 * Get the name of the category of which this attribute value is an
167 * instance.
168 * <P>
169 * For class NumberUpSupported, the
170 * category name is <CODE>"number-up-supported"</CODE>.
171 *
172 * @return Attribute category name.
173 */
174 public final String getName() {
175 return "number-up-supported";
176 }
177
178 }
|