1 /*
2 * Created on 04.03.2004
3 */
4 package org.xpcards.model;
5
6 import java.io.Serializable;
7 import java.util.Enumeration;
8 import java.util.Hashtable;
9
10 /***
11 * Model Elements Collection to track Model Elements by ID
12 *
13 * @author galu02
14 */
15 public class Collection implements Serializable {
16
17 private Hashtable collection = null;
18 private String category = null;
19 private Object parent = null;
20
21 public Collection(Object parent) {
22 this.parent = parent;
23 }
24
25 public Object getParent() {
26 return parent;
27 }
28
29 public String createUniqueIndex(String prefix) {
30
31 if (collection == null) {
32 return prefix + " " + 0;
33 }
34
35 int i = 0;
36 String s = null;
37 do {
38 s = prefix + " " + (i++);
39 } while ( containsKey(s));
40 return s;
41 }
42
43
44 public void putElement(IIDProvider element) {
45 if ( collection == null ) {
46 collection = new Hashtable();
47 }
48 collection.put(element.getId(), element);
49 }
50
51 public void removeElement(IIDProvider element) {
52 if ( collection != null ) {
53 collection.remove(element.getId());
54 }
55 }
56
57 /***
58 * @param arg0
59 * @return
60 */
61 public boolean containsKey(Object arg0) {
62 if ( collection == null ) {
63 return false;
64 }
65 return collection.containsKey(arg0);
66 }
67
68 /***
69 * @param arg0
70 * @return
71 */
72 public boolean containsValue(Object arg0) {
73 if ( collection == null ) {
74 return false;
75 }
76 return collection.containsValue(arg0);
77 }
78
79 /***
80 * @return
81 */
82 public Enumeration elements() {
83 if ( collection == null ) {
84 return null;
85 }
86 return collection.elements();
87 }
88
89 public Object[] toArray() {
90 if ( collection != null ) {
91 return collection.values().toArray();
92 }
93 return null;
94 }
95
96
97 /***
98 * @return
99 */
100 public int size() {
101 if ( collection == null ) {
102 return 0;
103 }
104
105 return collection.size();
106 }
107
108 /***
109 * @return
110 */
111 public String getCategory() {
112 return category;
113 }
114
115 /***
116 * @param string
117 */
118 public void setCategory(String string) {
119 category = string;
120 }
121
122 }
This page was automatically generated by Maven