History

My first initial commit with all of mine experimental changes.

Dmitry Kabak (userdima committed 13 years ago

Commit d37b88d1 parent 3f5b46618352 files · +2598093 −-8690Browse files

Showing the changes to java/pkg/javax/print/attribute/TextSyntax.java (1 of 18352 files). Show all

Unified · Split

java/pkg/javax/print/attribute/TextSyntax.java+152−0
@@ -0,0 +1,152 @@
1+/*
2+ * Copyright (c) 2000, 2004, Oracle and/or its affiliates. All rights reserved.
3+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+ *
5+ * This code is free software; you can redistribute it and/or modify it
6+ * under the terms of the GNU General Public License version 2 only, as
7+ * published by the Free Software Foundation. Oracle designates this
8+ * particular file as subject to the "Classpath" exception as provided
9+ * by Oracle in the LICENSE file that accompanied this code.
10+ *
11+ * This code is distributed in the hope that it will be useful, but WITHOUT
12+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14+ * version 2 for more details (a copy is included in the LICENSE file that
15+ * accompanied this code).
16+ *
17+ * You should have received a copy of the GNU General Public License version
18+ * 2 along with this work; if not, write to the Free Software Foundation,
19+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20+ *
21+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22+ * or visit www.oracle.com if you need additional information or have any
23+ * questions.
24+ */
25+
26+
27+package javax.print.attribute;
28+
29+import java.io.Serializable;
30+import java.util.Locale;
31+
32+/**
33+ * Class TextSyntax is an abstract base class providing the common
34+ * implementation of all attributes whose value is a string. The text attribute
35+ * includes a locale to indicate the natural language. Thus, a text attribute
36+ * always represents a localized string. Once constructed, a text attribute's
37+ * value is immutable.
38+ * <P>
39+ *
40+ * @author David Mendenhall
41+ * @author Alan Kaminsky
42+ */
43+public abstract class TextSyntax implements Serializable, Cloneable {
44+
45+ private static final long serialVersionUID = -8130648736378144102L;
46+
47+ /**
48+ * String value of this text attribute.
49+ * @serial
50+ */
51+ private String value;
52+
53+ /**
54+ * Locale of this text attribute.
55+ * @serial
56+ */
57+ private Locale locale;
58+
59+ /**
60+ * Constructs a TextAttribute with the specified string and locale.
61+ *
62+ * @param value Text string.
63+ * @param locale Natural language of the text string. null
64+ * is interpreted to mean the default locale for as returned
65+ * by <code>Locale.getDefault()</code>
66+ *
67+ * @exception NullPointerException
68+ * (unchecked exception) Thrown if <CODE>value</CODE> is null.
69+ */
70+ protected TextSyntax(String value, Locale locale) {
71+ this.value = verify (value);
72+ this.locale = verify (locale);
73+ }
74+
75+ private static String verify(String value) {
76+ if (value == null) {
77+ throw new NullPointerException(" value is null");
78+ }
79+ return value;
80+ }
81+
82+ private static Locale verify(Locale locale) {
83+ if (locale == null) {
84+ return Locale.getDefault();
85+ }
86+ return locale;
87+ }
88+
89+ /**
90+ * Returns this text attribute's text string.
91+ * @return the text string.
92+ */
93+ public String getValue() {
94+ return value;
95+ }
96+
97+ /**
98+ * Returns this text attribute's text string's natural language (locale).
99+ * @return the locale
100+ */
101+ public Locale getLocale() {
102+ return locale;
103+ }
104+
105+ /**
106+ * Returns a hashcode for this text attribute.
107+ *
108+ * @return A hashcode value for this object.
109+ */
110+ public int hashCode() {
111+ return value.hashCode() ^ locale.hashCode();
112+ }
113+
114+ /**
115+ * Returns whether this text attribute is equivalent to the passed in
116+ * object. To be equivalent, all of the following conditions must be true:
117+ * <OL TYPE=1>
118+ * <LI>
119+ * <CODE>object</CODE> is not null.
120+ * <LI>
121+ * <CODE>object</CODE> is an instance of class TextSyntax.
122+ * <LI>
123+ * This text attribute's underlying string and <CODE>object</CODE>'s
124+ * underlying string are equal.
125+ * <LI>
126+ * This text attribute's locale and <CODE>object</CODE>'s locale are
127+ * equal.
128+ * </OL>
129+ *
130+ * @param object Object to compare to.
131+ *
132+ * @return True if <CODE>object</CODE> is equivalent to this text
133+ * attribute, false otherwise.
134+ */
135+ public boolean equals(Object object) {
136+ return(object != null &&
137+ object instanceof TextSyntax &&
138+ this.value.equals (((TextSyntax) object).value) &&
139+ this.locale.equals (((TextSyntax) object).locale));
140+ }
141+
142+ /**
143+ * Returns a String identifying this text attribute. The String is
144+ * the attribute's underlying text string.
145+ *
146+ * @return A String identifying this object.
147+ */
148+ public String toString(){
149+ return value;
150+ }
151+
152+}