1 /*
   2  * Copyright (c) 2000, 2014, 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()} gives the IPP attribute name.
  41  *
  42  * @author  Alan Kaminsky
  43  */
  44 public final class NumberUpSupported    extends SetOfIntegerSyntax
  45         implements SupportedValuesAttribute {
  46 
  47      private static final long serialVersionUID = -1041573395759141805L;
  48 
  49 
  50     /**
  51      * Construct a new number up supported attribute with the given members.
  52      * The supported values for NumberUp are specified in "array form;" see
  53      * class
  54      * {@link javax.print.attribute.SetOfIntegerSyntax SetOfIntegerSyntax}
  55      * for an explanation of array form.
  56      *
  57      * @param  members  Set members in array form.
  58      *
  59      * @exception  NullPointerException
  60      *     (unchecked exception) Thrown if {@code members} is null or
  61      *     any element of {@code members} is null.
  62      * @exception  IllegalArgumentException
  63      *     (unchecked exception) Thrown if any element of
  64      *   {@code members} is not a length-one or length-two array. Also
  65      *    thrown if {@code members} is a zero-length array or if any
  66      *    member of the set is less than 1.
  67      */
  68     public NumberUpSupported(int[][] members) {
  69         super (members);
  70         if (members == null) {
  71             throw new NullPointerException("members is null");
  72         }
  73         int[][] myMembers = getMembers();
  74         int n = myMembers.length;
  75         if (n == 0) {
  76             throw new IllegalArgumentException("members is zero-length");
  77         }
  78         int i;
  79         for (i = 0; i < n; ++ i) {
  80             if (myMembers[i][0] < 1) {
  81                 throw new IllegalArgumentException
  82                     ("Number up value must be > 0");
  83             }
  84         }
  85     }
  86 
  87     /**
  88      * Construct a new number up supported attribute containing a single
  89      * integer. That is, only the one value of NumberUp is supported.
  90      *
  91      * @param  member  Set member.
  92      *
  93      * @exception  IllegalArgumentException
  94      *     (Unchecked exception) Thrown if {@code member} is less than
  95      *     1.
  96      */
  97     public NumberUpSupported(int member) {
  98         super (member);
  99         if (member < 1) {
 100             throw new IllegalArgumentException("Number up value must be > 0");
 101         }
 102     }
 103 
 104     /**
 105      * Construct a new number up supported attribute containing a single range
 106      * of integers. That is, only those values of NumberUp in the one range are
 107      * supported.
 108      *
 109      * @param  lowerBound  Lower bound of the range.
 110      * @param  upperBound  Upper bound of the range.
 111      *
 112      * @exception  IllegalArgumentException
 113      *     (Unchecked exception) Thrown if a null range is specified or if a
 114      *     non-null range is specified with {@code lowerBound} less than
 115      *     1.
 116      */
 117     public NumberUpSupported(int lowerBound, int upperBound) {
 118         super (lowerBound, upperBound);
 119         if (lowerBound > upperBound) {
 120             throw new IllegalArgumentException("Null range specified");
 121         } else if (lowerBound < 1) {
 122             throw new IllegalArgumentException
 123                 ("Number up value must be > 0");
 124         }
 125     }
 126 
 127     /**
 128      * Returns whether this number up supported attribute is equivalent to the
 129      * passed in object. To be equivalent, all of the following conditions
 130      * must be true:
 131      * <OL TYPE=1>
 132      * <LI>
 133      * {@code object} is not null.
 134      * <LI>
 135      * {@code object} is an instance of class NumberUpSupported.
 136      * <LI>
 137      * This number up supported attribute's members and {@code object}'s
 138      * members are the same.
 139      * </OL>
 140      *
 141      * @param  object  Object to compare to.
 142      *
 143      * @return  True if {@code object} is equivalent to this number up
 144      *          supported attribute, false otherwise.
 145      */
 146     public boolean equals(Object object) {
 147         return (super.equals (object) &&
 148                 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"}.
 171      *
 172      * @return  Attribute category name.
 173      */
 174     public final String getName() {
 175         return "number-up-supported";
 176     }
 177 
 178 }