Path: blob/master/src/java.desktop/share/classes/javax/print/attribute/IntegerSyntax.java
41159 views
/*1* Copyright (c) 2000, 2021, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package javax.print.attribute;2627import java.io.Serial;28import java.io.Serializable;2930/**31* Class {@code IntegerSyntax} is an abstract base class providing the common32* implementation of all attributes with integer values.33* <p>34* Under the hood, an integer attribute is just an integer. You can get an35* integer attribute's integer value by calling {@link #getValue() getValue()}.36* An integer attribute's integer value is established when it is constructed37* (see {@link #IntegerSyntax(int) IntegerSyntax(int)}). Once constructed, an38* integer attribute's value is immutable.39*40* @author David Mendenhall41* @author Alan Kaminsky42*/43public abstract class IntegerSyntax implements Serializable, Cloneable {4445/**46* Use serialVersionUID from JDK 1.4 for interoperability.47*/48@Serial49private static final long serialVersionUID = 3644574816328081943L;5051/**52* This integer attribute's integer value.53*54* @serial55*/56private int value;5758/**59* Construct a new integer attribute with the given integer value.60*61* @param value Integer value62*/63protected IntegerSyntax(int value) {64this.value = value;65}6667/**68* Construct a new integer attribute with the given integer value, which69* must lie within the given range.70*71* @param value Integer value72* @param lowerBound Lower bound73* @param upperBound Upper bound74* @throws IllegalArgumentException if {@code value} is less than75* {@code lowerBound} or greater than {@code upperBound}76*/77protected IntegerSyntax(int value, int lowerBound, int upperBound) {78if (lowerBound > value || value > upperBound) {79throw new IllegalArgumentException("Value " + value +80" not in range " + lowerBound +81".." + upperBound);82}83this.value = value;84}8586/**87* Returns this integer attribute's integer value.88*89* @return the integer value90*/91public int getValue() {92return value;93}9495/**96* Returns whether this integer attribute is equivalent to the passed in97* object. To be equivalent, all of the following conditions must be true:98* <ol type=1>99* <li>{@code object} is not {@code null}.100* <li>{@code object} is an instance of class {@code IntegerSyntax}.101* <li>This integer attribute's value and {@code object}'s value are102* equal.103* </ol>104*105* @param object {@code Object} to compare to106* @return {@code true} if {@code object} is equivalent to this integer107* attribute, {@code false} otherwise108*/109public boolean equals(Object object) {110111return (object != null && object instanceof IntegerSyntax &&112value == ((IntegerSyntax) object).value);113}114115/**116* Returns a hash code value for this integer attribute. The hash code is117* just this integer attribute's integer value.118*/119public int hashCode() {120return value;121}122123/**124* Returns a string value corresponding to this integer attribute. The125* string value is just this integer attribute's integer value converted to126* a string.127*/128public String toString() {129return "" + value;130}131}132133134