Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/share/classes/javax/print/attribute/IntegerSyntax.java
38918 views
/*1* Copyright (c) 2000, 2013, 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.Serializable;2829/**30* Class IntegerSyntax is an abstract base class providing the common31* implementation of all attributes with integer values.32* <P>33* Under the hood, an integer attribute is just an integer. You can get an34* integer attribute's integer value by calling {@link #getValue()35* getValue()}. An integer attribute's integer value is36* established when it is constructed (see {@link #IntegerSyntax(int)37* IntegerSyntax(int)}). Once constructed, an integer attribute's38* value is immutable.39* <P>40*41* @author David Mendenhall42* @author Alan Kaminsky43*/44public abstract class IntegerSyntax implements Serializable, Cloneable {4546private static final long serialVersionUID = 3644574816328081943L;4748/**49* This integer attribute's integer value.50* @serial51*/52private int value;5354/**55* Construct a new integer attribute with the given integer value.56*57* @param value Integer value.58*/59protected IntegerSyntax(int value) {60this.value = value;61}6263/**64* Construct a new integer attribute with the given integer value, which65* 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 IllegalArgumentException72* (Unchecked exception) Thrown if <CODE>value</CODE> is less than73* <CODE>lowerBound</CODE> or greater than74* <CODE>upperBound</CODE>.75*/76protected IntegerSyntax(int value, int lowerBound, int upperBound) {77if (lowerBound > value || value > upperBound) {78throw new IllegalArgumentException("Value " + value +79" not in range " + lowerBound +80".." + upperBound);81}82this.value = value;83}8485/**86* Returns this integer attribute's integer value.87* @return the integer value88*/89public int getValue() {90return value;91}9293/**94* Returns whether this integer attribute is equivalent to the passed in95* object. To be equivalent, all of the following conditions must be true:96* <OL TYPE=1>97* <LI>98* <CODE>object</CODE> is not null.99* <LI>100* <CODE>object</CODE> is an instance of class IntegerSyntax.101* <LI>102* This integer attribute's value and <CODE>object</CODE>'s value are103* equal.104* </OL>105*106* @param object Object to compare to.107*108* @return True if <CODE>object</CODE> is equivalent to this integer109* attribute, false otherwise.110*/111public boolean equals(Object object) {112113return (object != null && object instanceof IntegerSyntax &&114value == ((IntegerSyntax) object).value);115}116117/**118* Returns a hash code value for this integer attribute. The hash code is119* just this integer attribute's integer value.120*/121public int hashCode() {122return value;123}124125/**126* Returns a string value corresponding to this integer attribute. The127* string value is just this integer attribute's integer value converted to128* a string.129*/130public String toString() {131return "" + value;132}133}134135136