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

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 package net.sourceforge.demetrix.properties;
31 import java.io.Serializable;
32 import org.apache.log4j.Logger;
33 import net.sourceforge.demetrix.util.ObjectComparator;
34 /**
35  * @author Dimitri Pissarenko
36  *
37  */
38 public abstract class DemetrixProperty implements Serializable {
39     private String name;
40     private Object value;
41     private boolean readOnly;
42     private boolean mustBeEntered;
43     private Logger logger = Logger.getLogger(getClass());
44216    public DemetrixProperty() {
45216        this.readOnly = false;
46216        this.mustBeEntered = false;
47216    }
48     public String getName() {
49310        return name;
50     }
51     public void setName(String string) {
52194        name = string;
53194    }
54     /**
55      * @return
56      */
57     public Object getValue() {
58348        return value;
59     }
60     /**
61      * @param object
62      */
63     public abstract void setValue(Object object);
64     protected void setAllowedValue(Object newValue, Class allowedValueClass) {
65     
66486        if (newValue == null) {
6727            this.value = null;
68         } else {
69459            if (allowedValueClass.isAssignableFrom(newValue.getClass())) {
70453                this.value = newValue;
71             } else {
726                throw this.createClassNotCompatibleException(
73                     getClass(),
74                     allowedValueClass,
75                     newValue.getClass());
76             }
77         }
78480    }
79     /* (non-Javadoc)
80      * @see java.lang.Object#toString()
81      */
82     public String toString() {
836        return this.name + " [" + this.value + "]";
84     }
85     /**
86      * @return
87      */
88     public boolean isReadOnly() {
8973        return readOnly;
90     }
91     /**
92      * @param b
93      */
94     public void setReadOnly(boolean b) {
9525        readOnly = b;
9625    }
97     protected RuntimeException createClassNotCompatibleException(
98         Class propertyClass,
99         Class allowedValueClass,
100         Class actualValueClass) {
1016        return new RuntimeException(
102             propertyClass
103                 + " can only store instances of class \""
104                 + allowedValueClass
105                 + "\" as value, but not those of class \""
106                 + actualValueClass
107                 + "\"");
108     }
109     /**
110      * @return
111      */
112     public boolean isMustBeEntered() {
1131        return mustBeEntered;
114     }
115     /**
116      * @param b
117      */
118     public void setMustBeEntered(boolean b) {
1193        mustBeEntered = b;
1203    }
121     /* (non-Javadoc)
122      * @see java.lang.Object#equals(java.lang.Object)
123      */
124     public boolean equals(Object anotherObject) {
125561        boolean isEqual = false;
126561        DemetrixProperty anotherProperty = null;
127561        if (anotherObject == null) {
1286            return false;
129         }
130  
131555        if (anotherObject instanceof DemetrixProperty) {
132549            anotherProperty = (DemetrixProperty) anotherObject;
133549            isEqual = true;
134  
135549            if (anotherProperty.mustBeEntered != this.mustBeEntered) {
1362                isEqual = false;
137             }
138549            if (isEqual && (anotherProperty.readOnly != this.readOnly)) {
1392                isEqual = false;
140             }
141549            if (isEqual
142                 && (!ObjectComparator
143                     .areEqual(this.name, anotherProperty.name))) {
14450                isEqual = false;
145             }
146549            if (isEqual
147                 && (!ObjectComparator
148                     .areEqual(this.value, anotherProperty.value))) {
149326                isEqual = false;
150             }
151549            return isEqual;
152         } else {
1536            return false;
154         }
155     }
156     /* (non-Javadoc)
157      * @see java.lang.Object#hashCode()
158      */
159     public int hashCode() {
1604        int hashCode=0;
1614        if (this.getName()!=null)
162         {
1632            hashCode+=this.getName().hashCode();
164         }
1654        if (this.getValue()!=null)
166         {
1672            hashCode+=this.getValue().hashCode();
168         }
1694        return hashCode;
170     }
171 }

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.