< prev index next >

src/java.desktop/share/classes/javax/print/attribute/IntegerSyntax.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 
  26 package javax.print.attribute;
  27 
  28 import java.io.Serializable;
  29 
  30 /**
  31  * Class IntegerSyntax is an abstract base class providing the common
  32  * implementation of all attributes with integer values.
  33  * <P>
  34  * Under the hood, an integer attribute is just an integer. You can get an
  35  * integer attribute's integer value by calling {@link #getValue()
  36  * getValue()}. An integer attribute's integer value is
  37  * established when it is constructed (see {@link #IntegerSyntax(int)
  38  * IntegerSyntax(int)}). Once constructed, an integer attribute's
  39  * value is immutable.
  40  *
  41  * @author  David Mendenhall
  42  * @author  Alan Kaminsky
  43  */
  44 public abstract class IntegerSyntax implements Serializable, Cloneable {
  45 



  46     private static final long serialVersionUID = 3644574816328081943L;
  47 
  48     /**
  49      * This integer attribute's integer value.

  50      * @serial
  51      */
  52     private int value;
  53 
  54     /**
  55      * Construct a new integer attribute with the given integer value.
  56      *
  57      * @param  value  Integer value.
  58      */
  59     protected IntegerSyntax(int value) {
  60         this.value = value;
  61     }
  62 
  63     /**
  64      * Construct a new integer attribute with the given integer value, which
  65      * must lie within the given range.
  66      *
  67      * @param  value       Integer value.
  68      * @param  lowerBound  Lower bound.
  69      * @param  upperBound  Upper bound.
  70      *
  71      * @exception  IllegalArgumentException
  72      *     (Unchecked exception) Thrown if {@code value} is less than
  73      *     {@code lowerBound} or greater than
  74      *     {@code upperBound}.
  75      */
  76     protected IntegerSyntax(int value, int lowerBound, int upperBound) {
  77         if (lowerBound > value || value > upperBound) {
  78             throw new IllegalArgumentException("Value " + value +
  79                                                " not in range " + lowerBound +
  80                                                ".." + upperBound);
  81         }
  82         this.value = value;
  83     }
  84 
  85     /**
  86      * Returns this integer attribute's integer value.

  87      * @return the integer value
  88      */
  89     public int getValue() {
  90         return value;
  91     }
  92 
  93     /**
  94      * Returns whether this integer attribute is equivalent to the passed in
  95      * object. To be equivalent, all of the following conditions must be true:
  96      * <OL TYPE=1>
  97      * <LI>
  98      * {@code object} is not null.
  99      * <LI>
 100      * {@code object} is an instance of class IntegerSyntax.
 101      * <LI>
 102      * This integer attribute's value and {@code object}'s value are
 103      * equal.
 104      * </OL>
 105      *
 106      * @param  object  Object to compare to.
 107      *
 108      * @return  True if {@code object} is equivalent to this integer
 109      *          attribute, false otherwise.

 110      */
 111     public boolean equals(Object object) {
 112 
 113         return (object != null && object instanceof IntegerSyntax &&
 114                 value == ((IntegerSyntax) object).value);
 115     }
 116 
 117     /**
 118      * Returns a hash code value for this integer attribute. The hash code is
 119      * just this integer attribute's integer value.
 120      */
 121     public int hashCode() {
 122         return value;
 123     }
 124 
 125     /**
 126      * Returns a string value corresponding to this integer attribute. The
 127      * string value is just this integer attribute's integer value converted to
 128      * a string.
 129      */
   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;
  27 
  28 import java.io.Serializable;
  29 
  30 /**
  31  * Class {@code IntegerSyntax} is an abstract base class providing the common
  32  * implementation of all attributes with integer values.
  33  * <p>
  34  * Under the hood, an integer attribute is just an integer. You can get an
  35  * integer attribute's integer value by calling {@link #getValue() getValue()}.
  36  * An integer attribute's integer value is established when it is constructed
  37  * (see {@link #IntegerSyntax(int) IntegerSyntax(int)}). Once constructed, an
  38  * integer attribute's value is immutable.

  39  *
  40  * @author David Mendenhall
  41  * @author Alan Kaminsky
  42  */
  43 public abstract class IntegerSyntax implements Serializable, Cloneable {
  44 
  45     /**
  46      * Use serialVersionUID from JDK 1.4 for interoperability.
  47      */
  48     private static final long serialVersionUID = 3644574816328081943L;
  49 
  50     /**
  51      * This integer attribute's integer value.
  52      *
  53      * @serial
  54      */
  55     private int value;
  56 
  57     /**
  58      * Construct a new integer attribute with the given integer value.
  59      *
  60      * @param  value Integer value
  61      */
  62     protected IntegerSyntax(int value) {
  63         this.value = value;
  64     }
  65 
  66     /**
  67      * Construct a new integer attribute with the given integer value, which
  68      * must lie within the given range.
  69      *
  70      * @param  value Integer value
  71      * @param  lowerBound Lower bound
  72      * @param  upperBound Upper bound
  73      * @throws IllegalArgumentException if {@code value} is less than
  74      *         {@code lowerBound} or greater than {@code upperBound}



  75      */
  76     protected IntegerSyntax(int value, int lowerBound, int upperBound) {
  77         if (lowerBound > value || value > upperBound) {
  78             throw new IllegalArgumentException("Value " + value +
  79                                                " not in range " + lowerBound +
  80                                                ".." + upperBound);
  81         }
  82         this.value = value;
  83     }
  84 
  85     /**
  86      * Returns this integer attribute's integer value.
  87      *
  88      * @return the integer value
  89      */
  90     public int getValue() {
  91         return value;
  92     }
  93 
  94     /**
  95      * Returns whether this integer attribute is equivalent to the passed in
  96      * object. To be equivalent, all of the following conditions must be true:
  97      * <ol type=1>
  98      *   <li>{@code object} is not {@code null}.
  99      *   <li>{@code object} is an instance of class {@code IntegerSyntax}.
 100      *   <li>This integer attribute's value and {@code object}'s value are



 101      *   equal.
 102      * </ol>


 103      *
 104      * @param  object {@code Object} to compare to
 105      * @return {@code true} if {@code object} is equivalent to this integer
 106      *         attribute, {@code false} otherwise
 107      */
 108     public boolean equals(Object object) {
 109 
 110         return (object != null && object instanceof IntegerSyntax &&
 111                 value == ((IntegerSyntax) object).value);
 112     }
 113 
 114     /**
 115      * Returns a hash code value for this integer attribute. The hash code is
 116      * just this integer attribute's integer value.
 117      */
 118     public int hashCode() {
 119         return value;
 120     }
 121 
 122     /**
 123      * Returns a string value corresponding to this integer attribute. The
 124      * string value is just this integer attribute's integer value converted to
 125      * a string.
 126      */
< prev index next >