Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/src/java.desktop/share/classes/javax/print/attribute/TextSyntax.java
41159 views
1
/*
2
* Copyright (c) 2000, 2021, 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
package javax.print.attribute;
27
28
import java.io.Serial;
29
import java.io.Serializable;
30
import java.util.Locale;
31
32
/**
33
* Class {@code 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
*
39
* @author David Mendenhall
40
* @author Alan Kaminsky
41
*/
42
public abstract class TextSyntax implements Serializable, Cloneable {
43
44
/**
45
* Use serialVersionUID from JDK 1.4 for interoperability.
46
*/
47
@Serial
48
private static final long serialVersionUID = -8130648736378144102L;
49
50
/**
51
* String value of this text attribute.
52
*
53
* @serial
54
*/
55
private String value;
56
57
/**
58
* Locale of this text attribute.
59
*
60
* @serial
61
*/
62
private Locale locale;
63
64
/**
65
* Constructs a {@code TextAttribute} with the specified string and locale.
66
*
67
* @param value text string
68
* @param locale natural language of the text string. {@code null} is
69
* interpreted to mean the default locale for as returned by
70
* {@code Locale.getDefault()}
71
* @throws NullPointerException if {@code value} is {@code null}
72
*/
73
protected TextSyntax(String value, Locale locale) {
74
this.value = verify (value);
75
this.locale = verify (locale);
76
}
77
78
private static String verify(String value) {
79
if (value == null) {
80
throw new NullPointerException(" value is null");
81
}
82
return value;
83
}
84
85
private static Locale verify(Locale locale) {
86
if (locale == null) {
87
return Locale.getDefault();
88
}
89
return locale;
90
}
91
92
/**
93
* Returns this text attribute's text string.
94
*
95
* @return the text string
96
*/
97
public String getValue() {
98
return value;
99
}
100
101
/**
102
* Returns this text attribute's text string's natural language (locale).
103
*
104
* @return the locale
105
*/
106
public Locale getLocale() {
107
return locale;
108
}
109
110
/**
111
* Returns a hashcode for this text attribute.
112
*
113
* @return a hashcode value for this object
114
*/
115
public int hashCode() {
116
return value.hashCode() ^ locale.hashCode();
117
}
118
119
/**
120
* Returns whether this text attribute is equivalent to the passed in
121
* object. To be equivalent, all of the following conditions must be true:
122
* <ol type=1>
123
* <li>{@code object} is not {@code null}.
124
* <li>{@code object} is an instance of class {@code TextSyntax}.
125
* <li>This text attribute's underlying string and {@code object}'s
126
* underlying string are equal.
127
* <li>This text attribute's locale and {@code object}'s locale are equal.
128
* </ol>
129
*
130
* @param object {@code Object} to compare to
131
* @return {@code true} if {@code object} is equivalent to this text
132
* attribute, {@code false} otherwise
133
*/
134
public boolean equals(Object object) {
135
return(object != null &&
136
object instanceof TextSyntax &&
137
this.value.equals (((TextSyntax) object).value) &&
138
this.locale.equals (((TextSyntax) object).locale));
139
}
140
141
/**
142
* Returns a {@code String} identifying this text attribute. The
143
* {@code String} is the attribute's underlying text string.
144
*
145
* @return a {@code String} identifying this object
146
*/
147
public String toString(){
148
return value;
149
}
150
}
151
152