Line | Hits | Source |
---|---|---|
1 | /******************************************************************************* | |
2 | * Demetrix process modelling system | |
3 | * | |
4 | * Copyright (c) 2003, 2004 Dimitri A. Pissarenko | |
5 | * | |
6 | * This file is part of Demetrix. | |
7 | * | |
8 | * Demetrix is free software; you can redistribute it and/or modify | |
9 | * it under the terms of the GNU General Public License as published by | |
10 | * the Free Software Foundation; either version 2.1 of the License, or | |
11 | * (at your option) any later version. | |
12 | * | |
13 | * Demetrix is distributed in the hope that it will be useful, | |
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 | * GNU General Public License for more details. | |
17 | * | |
18 | * You should have received a copy of the GNU General Public License | |
19 | * along with Demetrix; if not, write to the Free Software | |
20 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
21 | * | |
22 | * For further information you may | |
23 | * | |
24 | * - send an e-mail in Russian, German or English to dimitri.pissarenko@gmx.net | |
25 | * - look at http://sourceforge.net/projects/demetrix/ | |
26 | * - look at http://demetrix.sourceforge.net/ | |
27 | * - look at http://members.inode.at/d.pissarenko/ | |
28 | * | |
29 | *****************************************************************************/ | |
30 | ||
31 | package net.sourceforge.demetrix.properties; | |
32 | ||
33 | import java.io.Serializable; | |
34 | ||
35 | import java.util.ArrayList; | |
36 | ||
37 | import java.util.Collection; | |
38 | ||
39 | import java.util.Enumeration; | |
40 | ||
41 | import java.util.Hashtable; | |
42 | ||
43 | import java.util.Iterator; | |
44 | ||
45 | import java.util.Vector; | |
46 | ||
47 | import net.sourceforge.demetrix.util.ObjectComparator; | |
48 | ||
49 | import org.apache.log4j.Logger; | |
50 | ||
51 | /** | |
52 | * @author Dimitri Pissarenko | |
53 | * | |
54 | */ | |
55 | ||
56 | public class DemetrixPropertiesStorage | |
57 | implements DemetrixPropertiesHolder, Serializable { | |
58 | ||
59 | private Logger logger = Logger.getLogger(getClass()); | |
60 | ||
61 | private Hashtable propertiesByName; | |
62 | ||
63 | 118 | public DemetrixPropertiesStorage() { |
64 | ||
65 | 118 | this.propertiesByName = new Hashtable(); |
66 | ||
67 | 118 | } |
68 | ||
69 | public void addProperty(DemetrixProperty property) { | |
70 | 172 | this.propertiesByName.put(property.getName(), property); |
71 | 172 | } |
72 | ||
73 | public DemetrixProperty getProperty(String name) { | |
74 | ||
75 | 239 | return (DemetrixProperty) this.propertiesByName.get(name); |
76 | ||
77 | } | |
78 | ||
79 | /* (non-Javadoc) | |
80 | * @see net.sourceforge.demetrix.properties.DemetrixPropertiesHolder#getAllProperties() | |
81 | */ | |
82 | ||
83 | public Iterator getAllProperties() { | |
84 | ||
85 | 30 | return this.propertiesByName.values().iterator(); |
86 | ||
87 | } | |
88 | ||
89 | /* (non-Javadoc) | |
90 | * @see net.sourceforge.demetrix.properties.DemetrixPropertiesHolder#getAllPropertyNames() | |
91 | */ | |
92 | ||
93 | public Enumeration getAllPropertyNames() { | |
94 | ||
95 | 1 | return this.propertiesByName.keys(); |
96 | ||
97 | } | |
98 | ||
99 | public void removeProperty(String propertyName) { | |
100 | ||
101 | 0 | this.propertiesByName.remove(propertyName); |
102 | ||
103 | 0 | } |
104 | ||
105 | public static ArrayList getAllPropertyNames(ArrayList propertiesHolders) { | |
106 | ||
107 | 2 | ArrayList allPropertyNames = null; |
108 | ||
109 | 2 | allPropertyNames = new ArrayList(); |
110 | ||
111 | 2 | DemetrixPropertiesStorage.storeAllPropertyNames( |
112 | propertiesHolders, | |
113 | allPropertyNames); | |
114 | ||
115 | 2 | return allPropertyNames; |
116 | ||
117 | } | |
118 | ||
119 | public static Vector getAllPropertyNames(Vector propertiesHolders) { | |
120 | ||
121 | 0 | Vector allPropertyNames = null; |
122 | ||
123 | 0 | allPropertyNames = new Vector(); |
124 | ||
125 | 0 | DemetrixPropertiesStorage.storeAllPropertyNames( |
126 | propertiesHolders, | |
127 | allPropertyNames); | |
128 | ||
129 | 0 | return allPropertyNames; |
130 | ||
131 | } | |
132 | ||
133 | public static void storeAllPropertyNames( | |
134 | Collection propertiesHolders, | |
135 | Collection allPropertyNames) { | |
136 | ||
137 | 2 | Iterator holders = null; |
138 | ||
139 | 2 | DemetrixPropertiesHolder holder = null; |
140 | ||
141 | 2 | Enumeration propertyNames = null; |
142 | ||
143 | 2 | String currentPropertyName = null; |
144 | ||
145 | 2 | holders = propertiesHolders.iterator(); |
146 | ||
147 | 2 | while (holders.hasNext()) { |
148 | ||
149 | 0 | holder = (DemetrixPropertiesHolder) holders.next(); |
150 | ||
151 | 0 | propertyNames = holder.getAllPropertyNames(); |
152 | ||
153 | 0 | while (propertyNames.hasMoreElements()) { |
154 | ||
155 | 0 | currentPropertyName = propertyNames.nextElement().toString(); |
156 | ||
157 | 0 | if (!allPropertyNames.contains(currentPropertyName)) { |
158 | ||
159 | 0 | allPropertyNames.add(currentPropertyName); |
160 | ||
161 | } | |
162 | ||
163 | } | |
164 | ||
165 | } | |
166 | ||
167 | 2 | } |
168 | ||
169 | /* (non-Javadoc) | |
170 | * @see java.lang.Object#equals(java.lang.Object) | |
171 | */ | |
172 | public boolean equals(Object anotherObject) { | |
173 | 394 | DemetrixPropertiesStorage anotherStorage=null; |
174 | 394 | if (anotherObject==null) |
175 | { | |
176 | 0 | return false; |
177 | } | |
178 | 394 | if (anotherObject instanceof DemetrixPropertiesStorage) |
179 | { | |
180 | 394 | anotherStorage=(DemetrixPropertiesStorage)anotherObject; |
181 | 394 | if (ObjectComparator.areEqualIrrespectiveOfOrder(this.propertiesByName.values(), anotherStorage.propertiesByName.values())) |
182 | { | |
183 | 68 | return true; |
184 | } | |
185 | else | |
186 | { | |
187 | 326 | return false; |
188 | } | |
189 | } | |
190 | else | |
191 | { | |
192 | 0 | return false; |
193 | } | |
194 | } | |
195 | ||
196 | /* (non-Javadoc) | |
197 | * @see net.sourceforge.demetrix.properties.DemetrixPropertiesHolder#getPropertiesStorage() | |
198 | */ | |
199 | public DemetrixPropertiesHolder getPropertiesStorage() { | |
200 | 0 | return this; |
201 | } | |
202 | ||
203 | /* (non-Javadoc) | |
204 | * @see java.lang.Object#hashCode() | |
205 | */ | |
206 | public int hashCode() { | |
207 | 504 | Iterator iterator=null; |
208 | 504 | int sum=0; |
209 | ||
210 | 504 | iterator=this.propertiesByName.keySet().iterator(); |
211 | 1008 | while (iterator.hasNext()) |
212 | { | |
213 | 504 | sum += iterator.next().hashCode(); |
214 | } | |
215 | ||
216 | 504 | return sum; |
217 | } | |
218 | ||
219 | } |
this report was generated by version 1.0.5 of jcoverage. |
copyright © 2003, jcoverage ltd. all rights reserved. |