1 /*
   2  * Copyright (c) 2000, 2004, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 package javax.print.attribute.standard;
  26 
  27 import javax.print.attribute.Attribute;
  28 import javax.print.attribute.SetOfIntegerSyntax;
  29 import javax.print.attribute.SupportedValuesAttribute;
  30 
  31 /**
  32  * Class NumberUpSupported is a printing attribute class, a set of integers,
  33  * that gives the supported values for a {@link NumberUp NumberUp} attribute.
  34  * <P>
  35  * <B>IPP Compatibility:</B> The NumberUpSupported attribute's canonical array
  36  * form gives the lower and upper bound for each range of number-up to be
  37  * included in an IPP "number-up-supported" attribute. See class {@link
  38  * javax.print.attribute.SetOfIntegerSyntax SetOfIntegerSyntax} for an
  39  * explanation of canonical array form. The category name returned by
  40  * <CODE>getName()</CODE> gives the IPP attribute name.
  41  * <P>
  42  *
  43  * @author  Alan Kaminsky
  44  */
  45 public final class NumberUpSupported    extends SetOfIntegerSyntax
  46         implements SupportedValuesAttribute {
  47 
  48      private static final long serialVersionUID = -1041573395759141805L;
  49 
  50 
  51     /**
  52      * Construct a new number up supported attribute with the given members.
  53      * The supported values for NumberUp are specified in "array form;" see
  54      * class
  55      * {@link javax.print.attribute.SetOfIntegerSyntax SetOfIntegerSyntax}
  56      * for an explanation of array form.
  57      *
  58      * @param  members  Set members in array form.
  59      *
  60      * @exception  NullPointerException
  61      *     (unchecked exception) Thrown if <CODE>members</CODE> is null or
  62      *     any element of <CODE>members</CODE> is null.
  63      * @exception  IllegalArgumentException
  64      *     (unchecked exception) Thrown if any element of
  65      *   <CODE>members</CODE> is not a length-one or length-two array. Also
  66      *    thrown if <CODE>members</CODE> is a zero-length array or if any
  67      *    member of the set is less than 1.
  68      */
  69     public NumberUpSupported(int[][] members) {
  70         super (members);
  71         if (members == null) {
  72             throw new NullPointerException("members is null");
  73         }
  74         int[][] myMembers = getMembers();
  75         int n = myMembers.length;
  76         if (n == 0) {
  77             throw new IllegalArgumentException("members is zero-length");
  78         }
  79         int i;
  80         for (i = 0; i < n; ++ i) {
  81             if (myMembers[i][0] < 1) {
  82                 throw new IllegalArgumentException
  83                     ("Number up value must be > 0");
  84             }
  85         }
  86     }
  87 
  88     /**
  89      * Construct a new number up supported attribute containing a single
  90      * integer. That is, only the one value of NumberUp is supported.
  91      *
  92      * @param  member  Set member.
  93      *
  94      * @exception  IllegalArgumentException
  95      *     (Unchecked exception) Thrown if <CODE>member</CODE> is less than
  96      *     1.
  97      */
  98     public NumberUpSupported(int member) {
  99         super (member);
 100         if (member < 1) {
 101             throw new IllegalArgumentException("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) &&
 149                 object instanceof NumberUpSupported);
 150     }
 151 
 152     /**
 153      * Get the printing attribute class which is to be used as the "category"
 154      * for this printing attribute value.
 155      * <P>
 156      * For class NumberUpSupported, the
 157      * category is class NumberUpSupported itself.
 158      *
 159      * @return  Printing attribute class (category), an instance of class
 160      *          {@link java.lang.Class java.lang.Class}.
 161      */
 162     public final Class<? extends Attribute> getCategory() {
 163         return NumberUpSupported.class;
 164     }
 165 
 166     /**
 167      * Get the name of the category of which this attribute value is an
 168      * instance.
 169      * <P>
 170      * For class NumberUpSupported, the
 171      * category name is <CODE>"number-up-supported"</CODE>.
 172      *
 173      * @return  Attribute category name.
 174      */
 175     public final String getName() {
 176         return "number-up-supported";
 177     }
 178 
 179 }