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
60 * incorrect unless explicitly documented on the method as having a meaningful
61 * interpretation. Usage to the contrary is incorrect coding and may result in
62 * a run time exception either immediately
63 * or at some later time. IllegalArgumentException and NullPointerException
64 * are examples of typical and acceptable run time exceptions for such cases.
65 *
66 * @author Alan Kaminsky
67 */
68 public final class AttributeSetUtilities {
69
70 /* Suppress default constructor, ensuring non-instantiability.
71 */
72 private AttributeSetUtilities() {
73 }
74
75 /**
76 * @serial include
77 */
78 private static class UnmodifiableAttributeSet
79 implements AttributeSet, Serializable {
80
81 private AttributeSet attrset;
82
83 /* Unmodifiable view of the underlying attribute set.
84 */
85 public UnmodifiableAttributeSet(AttributeSet attributeSet) {
86
87 attrset = attributeSet;
88 }
89
90 public Attribute get(Class<?> key) {
91 return attrset.get(key);
92 }
93
94 public boolean add(Attribute attribute) {
95 throw new UnmodifiableSetException();
96 }
97
98 public synchronized boolean remove(Class<?> category) {
99 throw new UnmodifiableSetException();
130 public boolean isEmpty() {
131 return attrset.isEmpty();
132 }
133
134 public boolean equals(Object o) {
135 return attrset.equals (o);
136 }
137
138 public int hashCode() {
139 return attrset.hashCode();
140 }
141
142 }
143
144 /**
145 * @serial include
146 */
147 private static class UnmodifiableDocAttributeSet
148 extends UnmodifiableAttributeSet
149 implements DocAttributeSet, Serializable {
150
151 public UnmodifiableDocAttributeSet(DocAttributeSet attributeSet) {
152
153 super (attributeSet);
154 }
155 }
156
157 /**
158 * @serial include
159 */
160 private static class UnmodifiablePrintRequestAttributeSet
161 extends UnmodifiableAttributeSet
162 implements PrintRequestAttributeSet, Serializable
163 {
164 public UnmodifiablePrintRequestAttributeSet
165 (PrintRequestAttributeSet attributeSet) {
166
167 super (attributeSet);
168 }
169 }
170
171 /**
172 * @serial include
173 */
174 private static class UnmodifiablePrintJobAttributeSet
175 extends UnmodifiableAttributeSet
176 implements PrintJobAttributeSet, Serializable
177 {
178 public UnmodifiablePrintJobAttributeSet
179 (PrintJobAttributeSet attributeSet) {
180
181 super (attributeSet);
182 }
183 }
184
185 /**
186 * @serial include
187 */
188 private static class UnmodifiablePrintServiceAttributeSet
189 extends UnmodifiableAttributeSet
190 implements PrintServiceAttributeSet, Serializable
191 {
192 public UnmodifiablePrintServiceAttributeSet
193 (PrintServiceAttributeSet attributeSet) {
194
195 super (attributeSet);
196 }
197 }
198
199 /**
200 * Creates an unmodifiable view of the given attribute set.
201 *
202 * @param attributeSet Underlying attribute set.
203 *
204 * @return Unmodifiable view of <CODE>attributeSet</CODE>.
205 *
206 * @exception NullPointerException
207 * Thrown if <CODE>attributeSet</CODE> is null. Null is never a
208 */
209 public static AttributeSet unmodifiableView(AttributeSet attributeSet) {
210 if (attributeSet == null) {
211 throw new NullPointerException();
274 * @param attributeSet Underlying print service attribute set.
275 *
276 * @return Unmodifiable view of <CODE>attributeSet</CODE>.
277 *
278 * @exception NullPointerException
279 * Thrown if <CODE>attributeSet</CODE> is null.
280 */
281 public static PrintServiceAttributeSet
282 unmodifiableView(PrintServiceAttributeSet attributeSet) {
283 if (attributeSet == null) {
284 throw new NullPointerException();
285 }
286 return new UnmodifiablePrintServiceAttributeSet (attributeSet);
287 }
288
289 /**
290 * @serial include
291 */
292 private static class SynchronizedAttributeSet
293 implements AttributeSet, Serializable {
294
295 private AttributeSet attrset;
296
297 public SynchronizedAttributeSet(AttributeSet attributeSet) {
298 attrset = attributeSet;
299 }
300
301 public synchronized Attribute get(Class<?> category) {
302 return attrset.get(category);
303 }
304
305 public synchronized boolean add(Attribute attribute) {
306 return attrset.add(attribute);
307 }
308
309 public synchronized boolean remove(Class<?> category) {
310 return attrset.remove(category);
311 }
312
313 public synchronized boolean remove(Attribute attribute) {
340
341 public synchronized boolean isEmpty() {
342 return attrset.isEmpty();
343 }
344
345 public synchronized boolean equals(Object o) {
346 return attrset.equals (o);
347 }
348
349 public synchronized int hashCode() {
350 return attrset.hashCode();
351 }
352 }
353
354 /**
355 * @serial include
356 */
357 private static class SynchronizedDocAttributeSet
358 extends SynchronizedAttributeSet
359 implements DocAttributeSet, Serializable {
360
361 public SynchronizedDocAttributeSet(DocAttributeSet attributeSet) {
362 super(attributeSet);
363 }
364 }
365
366 /**
367 * @serial include
368 */
369 private static class SynchronizedPrintRequestAttributeSet
370 extends SynchronizedAttributeSet
371 implements PrintRequestAttributeSet, Serializable {
372
373 public SynchronizedPrintRequestAttributeSet
374 (PrintRequestAttributeSet attributeSet) {
375 super(attributeSet);
376 }
377 }
378
379 /**
380 * @serial include
381 */
382 private static class SynchronizedPrintJobAttributeSet
383 extends SynchronizedAttributeSet
384 implements PrintJobAttributeSet, Serializable {
385
386 public SynchronizedPrintJobAttributeSet
387 (PrintJobAttributeSet attributeSet) {
388 super(attributeSet);
389 }
390 }
391
392 /**
393 * @serial include
394 */
395 private static class SynchronizedPrintServiceAttributeSet
396 extends SynchronizedAttributeSet
397 implements PrintServiceAttributeSet, Serializable {
398 public SynchronizedPrintServiceAttributeSet
399 (PrintServiceAttributeSet attributeSet) {
400 super(attributeSet);
401 }
402 }
403
404 /**
405 * Creates a synchronized view of the given attribute set.
406 *
407 * @param attributeSet Underlying attribute set.
408 *
409 * @return Synchronized view of <CODE>attributeSet</CODE>.
410 *
411 * @exception NullPointerException
412 * Thrown if <CODE>attributeSet</CODE> is null.
413 */
414 public static AttributeSet synchronizedView
415 (AttributeSet attributeSet) {
416 if (attributeSet == null) {
417 throw new NullPointerException();
|
1 /*
2 * Copyright (c) 2000, 2014, 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
60 * incorrect unless explicitly documented on the method as having a meaningful
61 * interpretation. Usage to the contrary is incorrect coding and may result in
62 * a run time exception either immediately
63 * or at some later time. IllegalArgumentException and NullPointerException
64 * are examples of typical and acceptable run time exceptions for such cases.
65 *
66 * @author Alan Kaminsky
67 */
68 public final class AttributeSetUtilities {
69
70 /* Suppress default constructor, ensuring non-instantiability.
71 */
72 private AttributeSetUtilities() {
73 }
74
75 /**
76 * @serial include
77 */
78 private static class UnmodifiableAttributeSet
79 implements AttributeSet, Serializable {
80 private static final long serialVersionUID = -6131802583863447813L;
81
82 private AttributeSet attrset;
83
84 /* Unmodifiable view of the underlying attribute set.
85 */
86 public UnmodifiableAttributeSet(AttributeSet attributeSet) {
87
88 attrset = attributeSet;
89 }
90
91 public Attribute get(Class<?> key) {
92 return attrset.get(key);
93 }
94
95 public boolean add(Attribute attribute) {
96 throw new UnmodifiableSetException();
97 }
98
99 public synchronized boolean remove(Class<?> category) {
100 throw new UnmodifiableSetException();
131 public boolean isEmpty() {
132 return attrset.isEmpty();
133 }
134
135 public boolean equals(Object o) {
136 return attrset.equals (o);
137 }
138
139 public int hashCode() {
140 return attrset.hashCode();
141 }
142
143 }
144
145 /**
146 * @serial include
147 */
148 private static class UnmodifiableDocAttributeSet
149 extends UnmodifiableAttributeSet
150 implements DocAttributeSet, Serializable {
151 private static final long serialVersionUID = -6349408326066898956L;
152
153 public UnmodifiableDocAttributeSet(DocAttributeSet attributeSet) {
154
155 super (attributeSet);
156 }
157 }
158
159 /**
160 * @serial include
161 */
162 private static class UnmodifiablePrintRequestAttributeSet
163 extends UnmodifiableAttributeSet
164 implements PrintRequestAttributeSet, Serializable
165 {
166 private static final long serialVersionUID = 7799373532614825073L;
167 public UnmodifiablePrintRequestAttributeSet
168 (PrintRequestAttributeSet attributeSet) {
169
170 super (attributeSet);
171 }
172 }
173
174 /**
175 * @serial include
176 */
177 private static class UnmodifiablePrintJobAttributeSet
178 extends UnmodifiableAttributeSet
179 implements PrintJobAttributeSet, Serializable
180 {
181 private static final long serialVersionUID = -8002245296274522112L;
182 public UnmodifiablePrintJobAttributeSet
183 (PrintJobAttributeSet attributeSet) {
184
185 super (attributeSet);
186 }
187 }
188
189 /**
190 * @serial include
191 */
192 private static class UnmodifiablePrintServiceAttributeSet
193 extends UnmodifiableAttributeSet
194 implements PrintServiceAttributeSet, Serializable
195 {
196 private static final long serialVersionUID = -7112165137107826819L;
197 public UnmodifiablePrintServiceAttributeSet
198 (PrintServiceAttributeSet attributeSet) {
199
200 super (attributeSet);
201 }
202 }
203
204 /**
205 * Creates an unmodifiable view of the given attribute set.
206 *
207 * @param attributeSet Underlying attribute set.
208 *
209 * @return Unmodifiable view of <CODE>attributeSet</CODE>.
210 *
211 * @exception NullPointerException
212 * Thrown if <CODE>attributeSet</CODE> is null. Null is never a
213 */
214 public static AttributeSet unmodifiableView(AttributeSet attributeSet) {
215 if (attributeSet == null) {
216 throw new NullPointerException();
279 * @param attributeSet Underlying print service attribute set.
280 *
281 * @return Unmodifiable view of <CODE>attributeSet</CODE>.
282 *
283 * @exception NullPointerException
284 * Thrown if <CODE>attributeSet</CODE> is null.
285 */
286 public static PrintServiceAttributeSet
287 unmodifiableView(PrintServiceAttributeSet attributeSet) {
288 if (attributeSet == null) {
289 throw new NullPointerException();
290 }
291 return new UnmodifiablePrintServiceAttributeSet (attributeSet);
292 }
293
294 /**
295 * @serial include
296 */
297 private static class SynchronizedAttributeSet
298 implements AttributeSet, Serializable {
299 private static final long serialVersionUID = 8365731020128564925L;
300
301 private AttributeSet attrset;
302
303 public SynchronizedAttributeSet(AttributeSet attributeSet) {
304 attrset = attributeSet;
305 }
306
307 public synchronized Attribute get(Class<?> category) {
308 return attrset.get(category);
309 }
310
311 public synchronized boolean add(Attribute attribute) {
312 return attrset.add(attribute);
313 }
314
315 public synchronized boolean remove(Class<?> category) {
316 return attrset.remove(category);
317 }
318
319 public synchronized boolean remove(Attribute attribute) {
346
347 public synchronized boolean isEmpty() {
348 return attrset.isEmpty();
349 }
350
351 public synchronized boolean equals(Object o) {
352 return attrset.equals (o);
353 }
354
355 public synchronized int hashCode() {
356 return attrset.hashCode();
357 }
358 }
359
360 /**
361 * @serial include
362 */
363 private static class SynchronizedDocAttributeSet
364 extends SynchronizedAttributeSet
365 implements DocAttributeSet, Serializable {
366 private static final long serialVersionUID = 6455869095246629354L;
367
368 public SynchronizedDocAttributeSet(DocAttributeSet attributeSet) {
369 super(attributeSet);
370 }
371 }
372
373 /**
374 * @serial include
375 */
376 private static class SynchronizedPrintRequestAttributeSet
377 extends SynchronizedAttributeSet
378 implements PrintRequestAttributeSet, Serializable {
379 private static final long serialVersionUID = 5671237023971169027L;
380
381 public SynchronizedPrintRequestAttributeSet
382 (PrintRequestAttributeSet attributeSet) {
383 super(attributeSet);
384 }
385 }
386
387 /**
388 * @serial include
389 */
390 private static class SynchronizedPrintJobAttributeSet
391 extends SynchronizedAttributeSet
392 implements PrintJobAttributeSet, Serializable {
393 private static final long serialVersionUID = 2117188707856965749L;
394
395 public SynchronizedPrintJobAttributeSet
396 (PrintJobAttributeSet attributeSet) {
397 super(attributeSet);
398 }
399 }
400
401 /**
402 * @serial include
403 */
404 private static class SynchronizedPrintServiceAttributeSet
405 extends SynchronizedAttributeSet
406 implements PrintServiceAttributeSet, Serializable {
407 private static final long serialVersionUID = -2830705374001675073L;
408
409 public SynchronizedPrintServiceAttributeSet
410 (PrintServiceAttributeSet attributeSet) {
411 super(attributeSet);
412 }
413 }
414
415 /**
416 * Creates a synchronized view of the given attribute set.
417 *
418 * @param attributeSet Underlying attribute set.
419 *
420 * @return Synchronized view of <CODE>attributeSet</CODE>.
421 *
422 * @exception NullPointerException
423 * Thrown if <CODE>attributeSet</CODE> is null.
424 */
425 public static AttributeSet synchronizedView
426 (AttributeSet attributeSet) {
427 if (attributeSet == null) {
428 throw new NullPointerException();
|