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/IntegerSyntax.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
31
/**
32
* Class {@code IntegerSyntax} is an abstract base class providing the common
33
* implementation of all attributes with integer values.
34
* <p>
35
* Under the hood, an integer attribute is just an integer. You can get an
36
* integer attribute's integer value by calling {@link #getValue() getValue()}.
37
* An integer attribute's integer value is established when it is constructed
38
* (see {@link #IntegerSyntax(int) IntegerSyntax(int)}). Once constructed, an
39
* integer attribute's value is immutable.
40
*
41
* @author David Mendenhall
42
* @author Alan Kaminsky
43
*/
44
public abstract class IntegerSyntax implements Serializable, Cloneable {
45
46
/**
47
* Use serialVersionUID from JDK 1.4 for interoperability.
48
*/
49
@Serial
50
private static final long serialVersionUID = 3644574816328081943L;
51
52
/**
53
* This integer attribute's integer value.
54
*
55
* @serial
56
*/
57
private int value;
58
59
/**
60
* Construct a new integer attribute with the given integer value.
61
*
62
* @param value Integer value
63
*/
64
protected IntegerSyntax(int value) {
65
this.value = value;
66
}
67
68
/**
69
* Construct a new integer attribute with the given integer value, which
70
* must lie within the given range.
71
*
72
* @param value Integer value
73
* @param lowerBound Lower bound
74
* @param upperBound Upper bound
75
* @throws IllegalArgumentException if {@code value} is less than
76
* {@code lowerBound} or greater than {@code upperBound}
77
*/
78
protected IntegerSyntax(int value, int lowerBound, int upperBound) {
79
if (lowerBound > value || value > upperBound) {
80
throw new IllegalArgumentException("Value " + value +
81
" not in range " + lowerBound +
82
".." + upperBound);
83
}
84
this.value = value;
85
}
86
87
/**
88
* Returns this integer attribute's integer value.
89
*
90
* @return the integer value
91
*/
92
public int getValue() {
93
return value;
94
}
95
96
/**
97
* Returns whether this integer attribute is equivalent to the passed in
98
* object. To be equivalent, all of the following conditions must be true:
99
* <ol type=1>
100
* <li>{@code object} is not {@code null}.
101
* <li>{@code object} is an instance of class {@code IntegerSyntax}.
102
* <li>This integer attribute's value and {@code object}'s value are
103
* equal.
104
* </ol>
105
*
106
* @param object {@code Object} to compare to
107
* @return {@code true} if {@code object} is equivalent to this integer
108
* attribute, {@code false} otherwise
109
*/
110
public boolean equals(Object object) {
111
112
return (object != null && object instanceof IntegerSyntax &&
113
value == ((IntegerSyntax) object).value);
114
}
115
116
/**
117
* Returns a hash code value for this integer attribute. The hash code is
118
* just this integer attribute's integer value.
119
*/
120
public int hashCode() {
121
return value;
122
}
123
124
/**
125
* Returns a string value corresponding to this integer attribute. The
126
* string value is just this integer attribute's integer value converted to
127
* a string.
128
*/
129
public String toString() {
130
return "" + value;
131
}
132
}
133
134