1 /* SetOfIntegerSyntax.java --
2 Copyright (C) 2003, 2004 Free Software Foundation, Inc.
4 This file is part of GNU Classpath.
6 GNU Classpath is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
11 GNU Classpath is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU Classpath; see the file COPYING. If not, write to the
18 Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
21 Linking this library statically or dynamically with other modules is
22 making a combined work based on this library. Thus, the terms and
23 conditions of the GNU General Public License cover the whole
26 As a special exception, the copyright holders of this library give you
27 permission to link this library with independent modules to produce an
28 executable, regardless of the license terms of these independent
29 modules, and to copy and distribute the resulting executable under
30 terms of your choice, provided that you also meet, for each linked
31 independent module, the terms and conditions of the license of that
32 module. An independent module is a module which is not derived from
33 or based on this library. If you modify this library, you may extend
34 this exception to your version of the library, but you are not
35 obligated to do so. If you do not wish to do so, delete this
36 exception statement from your version. */
38 package javax.print.attribute;
40 import java.io.Serializable;
41 import java.util.Vector;
44 * @author Michael Koch
46 public abstract class SetOfIntegerSyntax
47 implements Cloneable, Serializable
49 private static final long serialVersionUID = 3666874174847632203L;
51 private int[][] members;
53 private static int[][] normalize(Vector vecMembers)
55 // XXX: Perhaps we should merge ranges that overlap.
58 int[][] members = new int[vecMembers.size()][];
60 while (vecMembers.size() > 0)
62 // Search the lowest range.
63 int[] range = (int[]) vecMembers.elementAt(0);
65 for (int index = 1; index < vecMembers.size(); index++)
67 int[] tmp = (int[]) vecMembers.elementAt(index);
70 || (range[0] == tmp[0]
71 && range[0] > tmp[0]))
75 members[current] = range;
83 * Creates a <code>SetOfIntegerSyntax</code> object.
85 * @param member the member value
87 * @exception IllegalArgumentException if member is < 0
89 protected SetOfIntegerSyntax(int member)
92 throw new IllegalArgumentException("member may not be less than 0");
94 this.members = new int[][]{{member, member}};
98 * Creates a <code>SetOfIntegerSyntax</code> object.
100 * @param members the members to use in this set
102 * @exception IllegalArgumentException if any element is invalid
103 * @exception NullPointerException if any element of members is null
105 protected SetOfIntegerSyntax(int[][] members)
107 Vector vecMembers = new Vector();
111 for (int index = 0; index < members.length; index++)
116 if (members[index].length == 1)
118 lower = members[index][0];
119 upper = members[index][0];
121 else if (members[index].length == 2)
123 lower = members[index][0];
124 upper = members[index][1];
127 throw new IllegalArgumentException("invalid member element");
129 if (lower <= upper && lower < 0)
130 throw new IllegalArgumentException("invalid member element");
134 int[] range = new int[2];
137 vecMembers.add(range);
142 this.members = normalize(vecMembers);
146 * Creates a <code>SetOfIntegerSyntax</code> object.
148 * @param lowerBound the lower bound value
149 * @param upperBound the upper bound value
151 * @exception IllegalArgumentException if lowerBound <= upperbound
152 * and lowerBound < 0
154 protected SetOfIntegerSyntax(int lowerBound, int upperBound)
156 if (lowerBound <= upperBound
158 throw new IllegalArgumentException();
160 members = (lowerBound <= upperBound ? new int[][]{{lowerBound, upperBound}}
165 * Checks if this set contains value.
167 * @param value the value to test for
169 * @return true if this set contains value, false otherwise
171 public boolean contains(int value)
173 // This only works on a normalized member array.
174 for (int index = 0; index < members.length; index++)
176 if (value < members[index][0])
178 else if (value < members[index][1])
186 * Checks if this set contains value.
188 * @param value the value to test for
190 * @return true if this set contains value, false otherwise
192 public boolean contains(IntegerSyntax value)
194 return contains(value.getValue());
198 * Tests of obj is equal to this object.
200 * @param obj the object to test
202 * @return true if both objects are equal, false otherwise.
204 public boolean equals(Object obj)
206 if (! (obj instanceof SetOfIntegerSyntax))
209 throw new Error("not implemented");
213 * Returns an array describing the members included in this set.
215 * @return the array with the members
217 public int[][] getMembers()
219 throw new Error("not implemented");
223 * Returns the hashcode for this object.
225 * @return the hashcode
227 public int hashCode()
229 throw new Error("not implemented");
233 * Returns the smallest value that is greater then x.
235 * @param x an integer value
237 * @return the next value
239 public int next(int x)
241 throw new Error("not implemented");
245 * Returns the string representation for this object.
247 * @return the string representation
249 public String toString()
251 throw new Error("not implemented");