0N/A/*
2362N/A * Copyright (c) 2000, 2004, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
2362N/A * published by the Free Software Foundation. Oracle designates this
0N/A * particular file as subject to the "Classpath" exception as provided
2362N/A * by Oracle in the LICENSE file that accompanied this code.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
0N/A */
0N/A
0N/A
0N/Apackage javax.print.attribute;
0N/A
0N/Aimport java.io.Serializable;
0N/Aimport java.util.Locale;
0N/A
0N/A/**
0N/A * Class TextSyntax is an abstract base class providing the common
0N/A * implementation of all attributes whose value is a string. The text attribute
0N/A * includes a locale to indicate the natural language. Thus, a text attribute
0N/A * always represents a localized string. Once constructed, a text attribute's
0N/A * value is immutable.
0N/A * <P>
0N/A *
0N/A * @author David Mendenhall
0N/A * @author Alan Kaminsky
0N/A */
0N/Apublic abstract class TextSyntax implements Serializable, Cloneable {
0N/A
0N/A private static final long serialVersionUID = -8130648736378144102L;
0N/A
0N/A /**
0N/A * String value of this text attribute.
0N/A * @serial
0N/A */
0N/A private String value;
0N/A
0N/A /**
0N/A * Locale of this text attribute.
0N/A * @serial
0N/A */
0N/A private Locale locale;
0N/A
0N/A /**
0N/A * Constructs a TextAttribute with the specified string and locale.
0N/A *
0N/A * @param value Text string.
0N/A * @param locale Natural language of the text string. null
0N/A * is interpreted to mean the default locale for as returned
0N/A * by <code>Locale.getDefault()</code>
0N/A *
0N/A * @exception NullPointerException
0N/A * (unchecked exception) Thrown if <CODE>value</CODE> is null.
0N/A */
0N/A protected TextSyntax(String value, Locale locale) {
0N/A this.value = verify (value);
0N/A this.locale = verify (locale);
0N/A }
0N/A
0N/A private static String verify(String value) {
0N/A if (value == null) {
0N/A throw new NullPointerException(" value is null");
0N/A }
0N/A return value;
0N/A }
0N/A
0N/A private static Locale verify(Locale locale) {
0N/A if (locale == null) {
0N/A return Locale.getDefault();
0N/A }
0N/A return locale;
0N/A }
0N/A
0N/A /**
0N/A * Returns this text attribute's text string.
0N/A * @return the text string.
0N/A */
0N/A public String getValue() {
0N/A return value;
0N/A }
0N/A
0N/A /**
0N/A * Returns this text attribute's text string's natural language (locale).
0N/A * @return the locale
0N/A */
0N/A public Locale getLocale() {
0N/A return locale;
0N/A }
0N/A
0N/A /**
0N/A * Returns a hashcode for this text attribute.
0N/A *
0N/A * @return A hashcode value for this object.
0N/A */
0N/A public int hashCode() {
0N/A return value.hashCode() ^ locale.hashCode();
0N/A }
0N/A
0N/A /**
0N/A * Returns whether this text attribute is equivalent to the passed in
0N/A * object. To be equivalent, all of the following conditions must be true:
0N/A * <OL TYPE=1>
0N/A * <LI>
0N/A * <CODE>object</CODE> is not null.
0N/A * <LI>
0N/A * <CODE>object</CODE> is an instance of class TextSyntax.
0N/A * <LI>
0N/A * This text attribute's underlying string and <CODE>object</CODE>'s
0N/A * underlying string are equal.
0N/A * <LI>
0N/A * This text attribute's locale and <CODE>object</CODE>'s locale are
0N/A * equal.
0N/A * </OL>
0N/A *
0N/A * @param object Object to compare to.
0N/A *
0N/A * @return True if <CODE>object</CODE> is equivalent to this text
0N/A * attribute, false otherwise.
0N/A */
0N/A public boolean equals(Object object) {
0N/A return(object != null &&
0N/A object instanceof TextSyntax &&
0N/A this.value.equals (((TextSyntax) object).value) &&
0N/A this.locale.equals (((TextSyntax) object).locale));
0N/A }
0N/A
0N/A /**
0N/A * Returns a String identifying this text attribute. The String is
0N/A * the attribute's underlying text string.
0N/A *
0N/A * @return A String identifying this object.
0N/A */
0N/A public String toString(){
0N/A return value;
0N/A }
0N/A
0N/A}