Path: blob/master/src/java.desktop/share/classes/javax/print/attribute/TextSyntax.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;29import java.util.Locale;3031/**32* Class {@code 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*38* @author David Mendenhall39* @author Alan Kaminsky40*/41public abstract class TextSyntax implements Serializable, Cloneable {4243/**44* Use serialVersionUID from JDK 1.4 for interoperability.45*/46@Serial47private static final long serialVersionUID = -8130648736378144102L;4849/**50* String value of this text attribute.51*52* @serial53*/54private String value;5556/**57* Locale of this text attribute.58*59* @serial60*/61private Locale locale;6263/**64* Constructs a {@code TextAttribute} with the specified string and locale.65*66* @param value text string67* @param locale natural language of the text string. {@code null} is68* interpreted to mean the default locale for as returned by69* {@code Locale.getDefault()}70* @throws NullPointerException if {@code value} is {@code null}71*/72protected TextSyntax(String value, Locale locale) {73this.value = verify (value);74this.locale = verify (locale);75}7677private static String verify(String value) {78if (value == null) {79throw new NullPointerException(" value is null");80}81return value;82}8384private static Locale verify(Locale locale) {85if (locale == null) {86return Locale.getDefault();87}88return locale;89}9091/**92* Returns this text attribute's text string.93*94* @return the text string95*/96public String getValue() {97return value;98}99100/**101* Returns this text attribute's text string's natural language (locale).102*103* @return the locale104*/105public Locale getLocale() {106return locale;107}108109/**110* Returns a hashcode for this text attribute.111*112* @return a hashcode value for this object113*/114public int hashCode() {115return value.hashCode() ^ locale.hashCode();116}117118/**119* Returns whether this text attribute is equivalent to the passed in120* object. To be equivalent, all of the following conditions must be true:121* <ol type=1>122* <li>{@code object} is not {@code null}.123* <li>{@code object} is an instance of class {@code TextSyntax}.124* <li>This text attribute's underlying string and {@code object}'s125* underlying string are equal.126* <li>This text attribute's locale and {@code object}'s locale are equal.127* </ol>128*129* @param object {@code Object} to compare to130* @return {@code true} if {@code object} is equivalent to this text131* attribute, {@code false} otherwise132*/133public boolean equals(Object object) {134return(object != null &&135object instanceof TextSyntax &&136this.value.equals (((TextSyntax) object).value) &&137this.locale.equals (((TextSyntax) object).locale));138}139140/**141* Returns a {@code String} identifying this text attribute. The142* {@code String} is the attribute's underlying text string.143*144* @return a {@code String} identifying this object145*/146public String toString(){147return value;148}149}150151152