01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17:
18: package javax.print.attribute.standard;
19:
20: import javax.print.attribute.Attribute;
21: import javax.print.attribute.DocAttribute;
22: import javax.print.attribute.PrintJobAttribute;
23: import javax.print.attribute.PrintRequestAttribute;
24: import javax.print.attribute.SetOfIntegerSyntax;
25:
26: public final class PageRanges extends SetOfIntegerSyntax implements
27: DocAttribute, PrintJobAttribute, PrintRequestAttribute {
28: private static final long serialVersionUID = 8639895197656148392L;
29:
30: public PageRanges(int value) {
31: super (value);
32: if (value < 1) {
33: throw new IllegalArgumentException("Value" + value
34: + "is less than 1");
35: }
36: }
37:
38: public PageRanges(int lowerBound, int upperBound) {
39: super (lowerBound, upperBound);
40: if (lowerBound > upperBound) {
41: throw new IllegalArgumentException(
42: "Null range: lowerBound " + "> upperBound");
43: } else if (lowerBound < 1) {
44: throw new IllegalArgumentException("Lower bound "
45: + lowerBound + " is less than 1");
46: }
47: }
48:
49: public PageRanges(int[][] members) {
50: super (members);
51: if (members == null) {
52: throw new NullPointerException("Null int[][] parameter");
53: }
54: precisionCheck();
55: }
56:
57: public PageRanges(String string) {
58: super (string);
59: if (string == null) {
60: throw new NullPointerException("Null string parameter");
61: }
62: precisionCheck();
63: }
64:
65: private void precisionCheck() {
66: int[][] canonicalArray = getMembers();
67: if (canonicalArray.length == 0) {
68: throw new IllegalArgumentException("Zero-length array");
69: }
70: for (int i = 0; i < canonicalArray.length; i++) {
71: if (canonicalArray[i][0] < 1) {
72: throw new IllegalArgumentException(
73: "Valid values are not " + "less than 1");
74: }
75: }
76: }
77:
78: @Override
79: public boolean equals(Object object) {
80: if (!(object instanceof PageRanges)) {
81: return false;
82: }
83: return super .equals(object);
84: }
85:
86: public Class<? extends Attribute> getCategory() {
87: return PageRanges.class;
88: }
89:
90: public String getName() {
91: return "page-ranges";
92: }
93: }
|