Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/share/classes/javax/print/attribute/TextSyntax.java
38918 views
/*1* Copyright (c) 2000, 2004, 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*/242526package javax.print.attribute;2728import java.io.Serializable;29import java.util.Locale;3031/**32* Class TextSyntax is an abstract base class providing the common33* implementation of all attributes whose value is a string. The text attribute34* includes a locale to indicate the natural language. Thus, a text attribute35* always represents a localized string. Once constructed, a text attribute's36* value is immutable.37* <P>38*39* @author David Mendenhall40* @author Alan Kaminsky41*/42public abstract class TextSyntax implements Serializable, Cloneable {4344private static final long serialVersionUID = -8130648736378144102L;4546/**47* String value of this text attribute.48* @serial49*/50private String value;5152/**53* Locale of this text attribute.54* @serial55*/56private Locale locale;5758/**59* Constructs a TextAttribute with the specified string and locale.60*61* @param value Text string.62* @param locale Natural language of the text string. null63* is interpreted to mean the default locale for as returned64* by <code>Locale.getDefault()</code>65*66* @exception NullPointerException67* (unchecked exception) Thrown if <CODE>value</CODE> is null.68*/69protected TextSyntax(String value, Locale locale) {70this.value = verify (value);71this.locale = verify (locale);72}7374private static String verify(String value) {75if (value == null) {76throw new NullPointerException(" value is null");77}78return value;79}8081private static Locale verify(Locale locale) {82if (locale == null) {83return Locale.getDefault();84}85return locale;86}8788/**89* Returns this text attribute's text string.90* @return the text string.91*/92public String getValue() {93return value;94}9596/**97* Returns this text attribute's text string's natural language (locale).98* @return the locale99*/100public Locale getLocale() {101return locale;102}103104/**105* Returns a hashcode for this text attribute.106*107* @return A hashcode value for this object.108*/109public int hashCode() {110return value.hashCode() ^ locale.hashCode();111}112113/**114* Returns whether this text attribute is equivalent to the passed in115* object. To be equivalent, all of the following conditions must be true:116* <OL TYPE=1>117* <LI>118* <CODE>object</CODE> is not null.119* <LI>120* <CODE>object</CODE> is an instance of class TextSyntax.121* <LI>122* This text attribute's underlying string and <CODE>object</CODE>'s123* underlying string are equal.124* <LI>125* This text attribute's locale and <CODE>object</CODE>'s locale are126* equal.127* </OL>128*129* @param object Object to compare to.130*131* @return True if <CODE>object</CODE> is equivalent to this text132* attribute, false otherwise.133*/134public boolean equals(Object object) {135return(object != null &&136object instanceof TextSyntax &&137this.value.equals (((TextSyntax) object).value) &&138this.locale.equals (((TextSyntax) object).locale));139}140141/**142* Returns a String identifying this text attribute. The String is143* the attribute's underlying text string.144*145* @return A String identifying this object.146*/147public String toString(){148return value;149}150151}152153154