| 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 | 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()); | |
| 44 | 216 | public DemetrixProperty() { |
| 45 | 216 | this.readOnly = false; |
| 46 | 216 | this.mustBeEntered = false; |
| 47 | 216 | } |
| 48 | public String getName() { | |
| 49 | 310 | return name; |
| 50 | } | |
| 51 | public void setName(String string) { | |
| 52 | 194 | name = string; |
| 53 | 194 | } |
| 54 | /** | |
| 55 | * @return | |
| 56 | */ | |
| 57 | public Object getValue() { | |
| 58 | 348 | return value; |
| 59 | } | |
| 60 | /** | |
| 61 | * @param object | |
| 62 | */ | |
| 63 | public abstract void setValue(Object object); | |
| 64 | protected void setAllowedValue(Object newValue, Class allowedValueClass) { | |
| 65 | ||
| 66 | 486 | if (newValue == null) { |
| 67 | 27 | this.value = null; |
| 68 | } else { | |
| 69 | 459 | if (allowedValueClass.isAssignableFrom(newValue.getClass())) { |
| 70 | 453 | this.value = newValue; |
| 71 | } else { | |
| 72 | 6 | throw this.createClassNotCompatibleException( |
| 73 | getClass(), | |
| 74 | allowedValueClass, | |
| 75 | newValue.getClass()); | |
| 76 | } | |
| 77 | } | |
| 78 | 480 | } |
| 79 | /* (non-Javadoc) | |
| 80 | * @see java.lang.Object#toString() | |
| 81 | */ | |
| 82 | public String toString() { | |
| 83 | 6 | return this.name + " [" + this.value + "]"; |
| 84 | } | |
| 85 | /** | |
| 86 | * @return | |
| 87 | */ | |
| 88 | public boolean isReadOnly() { | |
| 89 | 73 | return readOnly; |
| 90 | } | |
| 91 | /** | |
| 92 | * @param b | |
| 93 | */ | |
| 94 | public void setReadOnly(boolean b) { | |
| 95 | 25 | readOnly = b; |
| 96 | 25 | } |
| 97 | protected RuntimeException createClassNotCompatibleException( | |
| 98 | Class propertyClass, | |
| 99 | Class allowedValueClass, | |
| 100 | Class actualValueClass) { | |
| 101 | 6 | 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() { | |
| 113 | 1 | return mustBeEntered; |
| 114 | } | |
| 115 | /** | |
| 116 | * @param b | |
| 117 | */ | |
| 118 | public void setMustBeEntered(boolean b) { | |
| 119 | 3 | mustBeEntered = b; |
| 120 | 3 | } |
| 121 | /* (non-Javadoc) | |
| 122 | * @see java.lang.Object#equals(java.lang.Object) | |
| 123 | */ | |
| 124 | public boolean equals(Object anotherObject) { | |
| 125 | 561 | boolean isEqual = false; |
| 126 | 561 | DemetrixProperty anotherProperty = null; |
| 127 | 561 | if (anotherObject == null) { |
| 128 | 6 | return false; |
| 129 | } | |
| 130 | ||
| 131 | 555 | if (anotherObject instanceof DemetrixProperty) { |
| 132 | 549 | anotherProperty = (DemetrixProperty) anotherObject; |
| 133 | 549 | isEqual = true; |
| 134 | ||
| 135 | 549 | if (anotherProperty.mustBeEntered != this.mustBeEntered) { |
| 136 | 2 | isEqual = false; |
| 137 | } | |
| 138 | 549 | if (isEqual && (anotherProperty.readOnly != this.readOnly)) { |
| 139 | 2 | isEqual = false; |
| 140 | } | |
| 141 | 549 | if (isEqual |
| 142 | && (!ObjectComparator | |
| 143 | .areEqual(this.name, anotherProperty.name))) { | |
| 144 | 50 | isEqual = false; |
| 145 | } | |
| 146 | 549 | if (isEqual |
| 147 | && (!ObjectComparator | |
| 148 | .areEqual(this.value, anotherProperty.value))) { | |
| 149 | 326 | isEqual = false; |
| 150 | } | |
| 151 | 549 | return isEqual; |
| 152 | } else { | |
| 153 | 6 | return false; |
| 154 | } | |
| 155 | } | |
| 156 | /* (non-Javadoc) | |
| 157 | * @see java.lang.Object#hashCode() | |
| 158 | */ | |
| 159 | public int hashCode() { | |
| 160 | 4 | int hashCode=0; |
| 161 | 4 | if (this.getName()!=null) |
| 162 | { | |
| 163 | 2 | hashCode+=this.getName().hashCode(); |
| 164 | } | |
| 165 | 4 | if (this.getValue()!=null) |
| 166 | { | |
| 167 | 2 | hashCode+=this.getValue().hashCode(); |
| 168 | } | |
| 169 | 4 | return hashCode; |
| 170 | } | |
| 171 | } |
|
this report was generated by version 1.0.5 of jcoverage. |
copyright © 2003, jcoverage ltd. all rights reserved. |