1 package com.wutka.dtd;
2
3 import java.util.*;
4 import java.io.*;
5
6 /*** Represents an enumeration of attribute values
7 *
8 * @author Mark Wutka
9 * @version $Revision: 1.16 $ $Date: 2002/07/19 01:20:11 $ by $Author: wutka $
10 */
11 public class DTDEnumeration implements DTDOutput
12 {
13 protected Vector items;
14
15 /*** Creates a new enumeration */
16 public DTDEnumeration()
17 {
18 items = new Vector();
19 }
20
21 /*** Adds a new value to the list of values */
22 public void add(String item)
23 {
24 items.addElement(item);
25 }
26
27 /*** Removes a value from the list of values */
28 public void remove(String item)
29 {
30 items.removeElement(item);
31 }
32
33 /*** Returns the values as an array */
34 public String[] getItems()
35 {
36 String[] retval = new String[items.size()];
37 items.copyInto(retval);
38
39 return retval;
40 }
41
42 /*** Returns the values as a vector (not a clone!) */
43 public Vector getItemsVec()
44 {
45 return items;
46 }
47
48 /*** Writes out a declaration for this enumeration */
49 public void write(PrintWriter out)
50 throws IOException
51 {
52 out.print("( ");
53 Enumeration e = getItemsVec().elements();
54
55 boolean isFirst = true;
56 while (e.hasMoreElements())
57 {
58 if (!isFirst) out.print(" | ");
59 isFirst = false;
60
61 out.print(e.nextElement());
62 }
63 out.print(")");
64 }
65
66 public boolean equals(Object ob)
67 {
68 if (ob == this) return true;
69 if (!(ob instanceof DTDEnumeration)) return false;
70
71 DTDEnumeration other = (DTDEnumeration) ob;
72 return items.equals(other.items);
73 }
74
75 /*** Returns the items in the enumeration */
76 public String[] getItem() { return getItems(); }
77
78 /*** Sets the items in the enumeration */
79 public void setItem(String[] newItems)
80 {
81 items = new Vector(newItems.length);
82 for (int i=0; i < newItems.length; i++)
83 {
84 items.addElement(newItems[i]);
85 }
86 }
87
88 /*** Stores an item in the enumeration */
89 public void setItem(String item, int i)
90 {
91 items.setElementAt(item, i);
92 }
93
94 /*** Retrieves an item from the enumeration */
95 public String getItem(int i)
96 {
97 return (String) items.elementAt(i);
98 }
99 }