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/standard/PageRanges.java
41171 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.standard;
27
28
import java.io.Serial;
29
30
import javax.print.attribute.Attribute;
31
import javax.print.attribute.DocAttribute;
32
import javax.print.attribute.PrintJobAttribute;
33
import javax.print.attribute.PrintRequestAttribute;
34
import javax.print.attribute.SetOfIntegerSyntax;
35
36
/**
37
* Class {@code PageRanges} is a printing attribute class, a set of integers,
38
* that identifies the range(s) of print-stream pages that the Printer object
39
* uses for each copy of each document which are to be printed. Nothing is
40
* printed for any pages identified that do not exist in the document(s). The
41
* attribute is associated with <i>print-stream</i> pages, not
42
* application-numbered pages (for example, the page numbers found in the
43
* headers and or footers for certain word processing applications).
44
* <p>
45
* In most cases, the exact pages to be printed will be generated by a device
46
* driver and this attribute would not be required. However, when printing an
47
* archived document which has already been formatted, the end user may elect to
48
* print just a subset of the pages contained in the document. In this case, if
49
* a page range of <code>"<i>n</i>-<i>m</i>"</code> is specified, the first page
50
* to be printed will be page <i>n.</i> All subsequent pages of the document
51
* will be printed through and including page <i>m.</i>
52
* <p>
53
* If a {@code PageRanges} attribute is not specified for a print job, all pages
54
* of the document will be printed. In other words, the default value for the
55
* {@code PageRanges} attribute is always {@code {{1, Integer.MAX_VALUE}}}.
56
* <p>
57
* The effect of a {@code PageRanges} attribute on a multidoc print job (a job
58
* with multiple documents) depends on whether all the docs have the same page
59
* ranges specified or whether different docs have different page ranges
60
* specified, and on the (perhaps defaulted) value of the
61
* {@link MultipleDocumentHandling MultipleDocumentHandling} attribute.
62
* <ul>
63
* <li>If all the docs have the same page ranges specified, then any value of
64
* {@link MultipleDocumentHandling MultipleDocumentHandling} makes sense, and
65
* the printer's processing depends on the
66
* {@link MultipleDocumentHandling MultipleDocumentHandling} value:
67
* <ul>
68
* <li>{@code SINGLE_DOCUMENT} -- All the input docs will be combined
69
* together into one output document. The specified page ranges of that
70
* output document will be printed.
71
* <li>{@code SINGLE_DOCUMENT_NEW_SHEET} -- All the input docs will be
72
* combined together into one output document, and the first impression of
73
* each input doc will always start on a new media sheet. The specified page
74
* ranges of that output document will be printed.
75
* <li>{@code SEPARATE_DOCUMENTS_UNCOLLATED_COPIES} -- For each separate
76
* input doc, the specified page ranges will be printed.
77
* <li>{@code SEPARATE_DOCUMENTS_COLLATED_COPIES} -- For each separate input
78
* doc, the specified page ranges will be printed.
79
* </ul>
80
* <ul>
81
* <li>{@code SEPARATE_DOCUMENTS_UNCOLLATED_COPIES} -- For each separate
82
* input doc, its own specified page ranges will be printed.
83
* <li>{@code SEPARATE_DOCUMENTS_COLLATED_COPIES} -- For each separate input
84
* doc, its own specified page ranges will be printed.
85
* </ul>
86
* </ul>
87
* <p>
88
* <b>IPP Compatibility:</b> The PageRanges attribute's canonical array form
89
* gives the lower and upper bound for each range of pages to be included in and
90
* IPP "page-ranges" attribute. See class
91
* {@link SetOfIntegerSyntax SetOfIntegerSyntax} for an explanation of canonical
92
* array form. The category name returned by {@code getName()} gives the IPP
93
* attribute name.
94
*
95
* @author David Mendenhall
96
* @author Alan Kaminsky
97
*/
98
public final class PageRanges extends SetOfIntegerSyntax
99
implements DocAttribute, PrintRequestAttribute, PrintJobAttribute {
100
101
/**
102
* Use serialVersionUID from JDK 1.4 for interoperability.
103
*/
104
@Serial
105
private static final long serialVersionUID = 8639895197656148392L;
106
107
/**
108
* Construct a new page ranges attribute with the given members. The members
109
* are specified in "array form;" see class
110
* {@link SetOfIntegerSyntax SetOfIntegerSyntax} for an explanation of array
111
* form.
112
*
113
* @param members set members in array form
114
* @throws NullPointerException if {@code members} is {@code null} or any
115
* element of {@code members} is {@code null}
116
* @throws IllegalArgumentException if any element of {@code members} is not
117
* a length-one or length-two array. Also if {@code members} is a
118
* zero-length array or if any member of the set is less than 1.
119
*/
120
public PageRanges(int[][] members) {
121
super (members);
122
if (members == null) {
123
throw new NullPointerException("members is null");
124
}
125
myPageRanges();
126
}
127
128
/**
129
* Construct a new page ranges attribute with the given members in string
130
* form. See class {@link SetOfIntegerSyntax SetOfIntegerSyntax} for
131
* explanation of the syntax.
132
*
133
* @param members set members in string form
134
* @throws NullPointerException if {@code members} is {@code null} or any
135
* element of {@code members} is {@code null}
136
* @throws IllegalArgumentException if {@code members} does not obey the
137
* proper syntax. Also if the constructed set-of-integer is a
138
* zero-length array or if any member of the set is less than 1.
139
*/
140
public PageRanges(String members) {
141
super(members);
142
if (members == null) {
143
throw new NullPointerException("members is null");
144
}
145
myPageRanges();
146
}
147
148
/**
149
* Validates the page ranges.
150
*/
151
private void myPageRanges() {
152
int[][] myMembers = getMembers();
153
int n = myMembers.length;
154
if (n == 0) {
155
throw new IllegalArgumentException("members is zero-length");
156
}
157
int i;
158
for (i = 0; i < n; ++ i) {
159
if (myMembers[i][0] < 1) {
160
throw new IllegalArgumentException("Page value < 1 specified");
161
}
162
}
163
}
164
165
/**
166
* Construct a new page ranges attribute containing a single integer. That
167
* is, only the one page is to be printed.
168
*
169
* @param member set member
170
* @throws IllegalArgumentException if {@code member < 1}
171
*/
172
public PageRanges(int member) {
173
super (member);
174
if (member < 1) {
175
throw new IllegalArgumentException("Page value < 1 specified");
176
}
177
}
178
179
/**
180
* Construct a new page ranges attribute containing a single range of
181
* integers. That is, only those pages in the one range are to be printed.
182
*
183
* @param lowerBound lower bound of the range
184
* @param upperBound upper bound of the range
185
* @throws IllegalArgumentException if a {@code null} range is specified or
186
* if a {@code non-null} range is specified with {@code lowerBound}
187
* less than 1
188
*/
189
public PageRanges(int lowerBound, int upperBound) {
190
super (lowerBound, upperBound);
191
if (lowerBound > upperBound) {
192
throw new IllegalArgumentException("Null range specified");
193
} else if (lowerBound < 1) {
194
throw new IllegalArgumentException("Page value < 1 specified");
195
}
196
}
197
198
/**
199
* Returns whether this page ranges attribute is equivalent to the passed in
200
* object. To be equivalent, all of the following conditions must be true:
201
* <ol type=1>
202
* <li>{@code object} is not {@code null}.
203
* <li>{@code object} is an instance of class {@code PageRanges}.
204
* <li>This page ranges attribute's members and {@code object}'s members
205
* are the same.
206
* </ol>
207
*
208
* @param object {@code Object} to compare to
209
* @return {@code true} if {@code object} is equivalent to this page ranges
210
* attribute, {@code false} otherwise
211
*/
212
public boolean equals(Object object) {
213
return (super.equals(object) && object instanceof PageRanges);
214
}
215
216
/**
217
* Get the printing attribute class which is to be used as the "category"
218
* for this printing attribute value.
219
* <p>
220
* For class {@code PageRanges}, the category is class
221
* {@code PageRanges} itself.
222
*
223
* @return printing attribute class (category), an instance of class
224
* {@link Class java.lang.Class}
225
*/
226
public final Class<? extends Attribute> getCategory() {
227
return PageRanges.class;
228
}
229
230
/**
231
* Get the name of the category of which this attribute value is an
232
* instance.
233
* <p>
234
* For class {@code PageRanges}, the category name is {@code "page-ranges"}.
235
*
236
* @return attribute category name
237
*/
238
public final String getName() {
239
return "page-ranges";
240
}
241
}
242
243