Coverage details for net.sourceforge.demetrix.properties.DemetrixPropertiesStorage

LineHitsSource
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  
63118    public DemetrixPropertiesStorage() {
64  
65118        this.propertiesByName = new Hashtable();
66  
67118    }
68  
69     public void addProperty(DemetrixProperty property) {
70172        this.propertiesByName.put(property.getName(), property);
71172    }
72  
73     public DemetrixProperty getProperty(String name) {
74  
75239        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  
8530        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  
951        return this.propertiesByName.keys();
96  
97     }
98  
99     public void removeProperty(String propertyName) {
100  
1010        this.propertiesByName.remove(propertyName);
102  
1030    }
104  
105     public static ArrayList getAllPropertyNames(ArrayList propertiesHolders) {
106  
1072        ArrayList allPropertyNames = null;
108  
1092        allPropertyNames = new ArrayList();
110  
1112        DemetrixPropertiesStorage.storeAllPropertyNames(
112             propertiesHolders,
113             allPropertyNames);
114  
1152        return allPropertyNames;
116  
117     }
118  
119     public static Vector getAllPropertyNames(Vector propertiesHolders) {
120  
1210        Vector allPropertyNames = null;
122  
1230        allPropertyNames = new Vector();
124  
1250        DemetrixPropertiesStorage.storeAllPropertyNames(
126             propertiesHolders,
127             allPropertyNames);
128  
1290        return allPropertyNames;
130  
131     }
132  
133     public static void storeAllPropertyNames(
134         Collection propertiesHolders,
135         Collection allPropertyNames) {
136  
1372        Iterator holders = null;
138  
1392        DemetrixPropertiesHolder holder = null;
140  
1412        Enumeration propertyNames = null;
142  
1432        String currentPropertyName = null;
144  
1452        holders = propertiesHolders.iterator();
146  
1472        while (holders.hasNext()) {
148  
1490            holder = (DemetrixPropertiesHolder) holders.next();
150  
1510            propertyNames = holder.getAllPropertyNames();
152  
1530            while (propertyNames.hasMoreElements()) {
154  
1550                currentPropertyName = propertyNames.nextElement().toString();
156  
1570                if (!allPropertyNames.contains(currentPropertyName)) {
158  
1590                    allPropertyNames.add(currentPropertyName);
160  
161                 }
162  
163             }
164  
165         }
166  
1672    }
168  
169     /* (non-Javadoc)
170      * @see java.lang.Object#equals(java.lang.Object)
171      */
172     public boolean equals(Object anotherObject) {
173394        DemetrixPropertiesStorage anotherStorage=null;
174394        if (anotherObject==null)
175         {
1760            return false;
177         }
178394        if (anotherObject instanceof DemetrixPropertiesStorage)
179         {
180394            anotherStorage=(DemetrixPropertiesStorage)anotherObject;
181394            if (ObjectComparator.areEqualIrrespectiveOfOrder(this.propertiesByName.values(), anotherStorage.propertiesByName.values()))
182             {
18368                return true;
184             }
185             else
186             {
187326                return false;
188             }
189         }
190         else
191         {
1920            return false;
193         }
194     }
195  
196     /* (non-Javadoc)
197      * @see net.sourceforge.demetrix.properties.DemetrixPropertiesHolder#getPropertiesStorage()
198      */
199     public DemetrixPropertiesHolder getPropertiesStorage() {
2000        return this;
201     }
202  
203     /* (non-Javadoc)
204      * @see java.lang.Object#hashCode()
205      */
206     public int hashCode() {
207504        Iterator iterator=null;
208504        int sum=0;
209  
210504        iterator=this.propertiesByName.keySet().iterator();
2111008        while (iterator.hasNext())
212         {
213504            sum += iterator.next().hashCode();
214         }
215         
216504        return sum;
217     }
218  
219 }

this report was generated by version 1.0.5 of jcoverage.
visit www.jcoverage.com for updates.

copyright © 2003, jcoverage ltd. all rights reserved.
Java is a trademark of Sun Microsystems, Inc. in the United States and other countries.