< prev index next >

src/java.desktop/share/classes/javax/print/attribute/standard/NumberUpSupported.java

Print this page


   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 }
   1 /*
   2  * Copyright (c) 2000, 2017, 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 
  26 package javax.print.attribute.standard;
  27 
  28 import javax.print.attribute.Attribute;
  29 import javax.print.attribute.SetOfIntegerSyntax;
  30 import javax.print.attribute.SupportedValuesAttribute;
  31 
  32 /**
  33  * Class {@code NumberUpSupported} is a printing attribute class, a set of
  34  * integers, that gives the supported values for a {@link NumberUp NumberUp}
  35  * attribute.
  36  * <p>
  37  * <b>IPP Compatibility:</b> The NumberUpSupported attribute's canonical array
  38  * form gives the lower and upper bound for each range of number-up to be
  39  * included in an IPP "number-up-supported" attribute. See class
  40  * {@link SetOfIntegerSyntax SetOfIntegerSyntax} for an explanation of canonical
  41  * array form. The category name returned by {@code getName()} gives the IPP
  42  * attribute name.
  43  *
  44  * @author Alan Kaminsky
  45  */
  46 public final class NumberUpSupported    extends SetOfIntegerSyntax
  47         implements SupportedValuesAttribute {
  48 
  49     /**
  50      * Use serialVersionUID from JDK 1.4 for interoperability.
  51      */
  52     private static final long serialVersionUID = -1041573395759141805L;
  53 

  54     /**
  55      * Construct a new number up supported attribute with the given members. The
  56      * supported values for NumberUp are specified in "array form;" see class
  57      * {@link SetOfIntegerSyntax SetOfIntegerSyntax} for
  58      * an explanation of array form.
  59      *
  60      * @param  members set members in array form
  61      * @throws NullPointerException if {@code members} is {@code null} or any
  62      *         element of {@code members} is {@code null}
  63      * @throws IllegalArgumentException if any element of {@code members} is not
  64      *         a length-one or length-two array. Also if {@code members} is a
  65      *         zero-length array or if any member of the set is less than 1.





  66      */
  67     public NumberUpSupported(int[][] members) {
  68         super (members);
  69         if (members == null) {
  70             throw new NullPointerException("members is null");
  71         }
  72         int[][] myMembers = getMembers();
  73         int n = myMembers.length;
  74         if (n == 0) {
  75             throw new IllegalArgumentException("members is zero-length");
  76         }
  77         int i;
  78         for (i = 0; i < n; ++ i) {
  79             if (myMembers[i][0] < 1) {
  80                 throw new IllegalArgumentException
  81                     ("Number up value must be > 0");
  82             }
  83         }
  84     }
  85 
  86     /**
  87      * Construct a new number up supported attribute containing a single
  88      * integer. That is, only the one value of {@code NumberUp} is supported.
  89      *
  90      * @param  member set member
  91      * @throws IllegalArgumentException if {@code member < 1}



  92      */
  93     public NumberUpSupported(int member) {
  94         super (member);
  95         if (member < 1) {
  96             throw new IllegalArgumentException("Number up value must be > 0");
  97         }
  98     }
  99 
 100     /**
 101      * Construct a new number up supported attribute containing a single range
 102      * of integers. That is, only those values of {@code NumberUp} in the one
 103      * range are supported.



 104      *
 105      * @param  lowerBound lower bound of the range
 106      * @param  upperBound upper bound of the range
 107      * @throws IllegalArgumentException if a {@code null} range is specified or
 108      *         if a {@code non-null} range is specified with {@code lowerBound}
 109      *         less than 1
 110      */
 111     public NumberUpSupported(int lowerBound, int upperBound) {
 112         super (lowerBound, upperBound);
 113         if (lowerBound > upperBound) {
 114             throw new IllegalArgumentException("Null range specified");
 115         } else if (lowerBound < 1) {
 116             throw new IllegalArgumentException
 117                 ("Number up value must be > 0");
 118         }
 119     }
 120 
 121     /**
 122      * Returns whether this number up supported attribute is equivalent to the
 123      * passed in object. To be equivalent, all of the following conditions must
 124      * be true:
 125      * <ol type=1>
 126      *   <li>{@code object} is not {@code null}.
 127      *   <li>{@code object} is an instance of class {@code NumberUpSupported}.
 128      *   <li>This number up supported attribute's members and {@code object}'s



 129      *   members are the same.
 130      * </ol>
 131      *
 132      * @param  object {@code Object} to compare to
 133      * @return {@code true} if {@code object} is equivalent to this number up
 134      *         supported attribute, {@code false} otherwise

 135      */
 136     public boolean equals(Object object) {
 137         return (super.equals (object) &&
 138                 object instanceof NumberUpSupported);
 139     }
 140 
 141     /**
 142      * Get the printing attribute class which is to be used as the "category"
 143      * for this printing attribute value.
 144      * <p>
 145      * For class {@code NumberUpSupported}, the category is class
 146      * {@code NumberUpSupported} itself.
 147      *
 148      * @return printing attribute class (category), an instance of class
 149      *         {@link Class java.lang.Class}
 150      */
 151     public final Class<? extends Attribute> getCategory() {
 152         return NumberUpSupported.class;
 153     }
 154 
 155     /**
 156      * Get the name of the category of which this attribute value is an
 157      * instance.
 158      * <p>
 159      * For class {@code NumberUpSupported}, the category name is
 160      * {@code "number-up-supported"}.
 161      *
 162      * @return attribute category name
 163      */
 164     public final String getName() {
 165         return "number-up-supported";
 166     }

 167 }
< prev index next >