- Timestamp:
- 06/21/11 11:25:45 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/EventBenchCore/src/de/ugoe/cs/eventbench/data/Event.java
r23 r79 3 3 import java.security.InvalidParameterException; 4 4 5 6 5 /** 6 * <p> 7 * Base class for all events. An event is described by its {@link #type} and its 8 * {@link #target}. 9 * </p> 10 * 11 * @author Steffen Herbold 12 * @version 1.0 13 * 14 * @param <T> 15 * Can be used to declare that events belong to a specific platform 16 * without subclassing. 17 */ 7 18 public class Event<T> { 8 19 20 /** 21 * <p> 22 * Global start event that can be used to indicate the start of a sequence. 23 * </p> 24 */ 9 25 public static final Event<Object> STARTEVENT = new Event<Object>("START"); 26 27 /** 28 * <p> 29 * Global end event that can be used to indicate the end of a sequence. 30 */ 10 31 public static final Event<Object> ENDEVENT = new Event<Object>("END"); 11 32 12 33 /** 13 34 * <p> … … 16 37 */ 17 38 private String type; 18 19 /** 20 * </p> 21 * Target of the event. 39 40 /** 41 * </p> Target of the event. 22 42 */ 23 43 private String target = null; 24 44 25 45 /** 26 46 * <p> … … 30 50 private String targetShort = null; 31 51 32 52 /** 53 * Further information about the event that shall be included in its Id. 54 */ 33 55 private String idInfo = ""; 34 56 57 /** 58 * <p> 59 * Constructor. Creates a new Event with a given type. 60 * </p> 61 * 62 * @param type 63 * type of the event 64 */ 35 65 public Event(String type) { 36 if ( type==null) {66 if (type == null) { 37 67 throw new InvalidParameterException("Event type must not be null"); 38 68 } … … 40 70 } 41 71 72 /** 73 * <p> 74 * Two events are equal, if their {@link #type} and {@link #target} are 75 * equal. 76 * </p> 77 * <p> 78 * See {@link Object#equals(Object)} for further information. 79 * </p> 80 * 81 * @param other 82 * Event that is compared to this 83 * @return true, if events are equal, false otherwise 84 */ 42 85 @Override 43 86 public boolean equals(Object other) { 44 if ( this==other) {87 if (this == other) { 45 88 return true; 46 89 } 47 90 if (other instanceof Event<?>) { 48 91 Event<?> otherEvent = (Event<?>) other; 49 if ( target!=null) {92 if (target != null) { 50 93 return type.equals(otherEvent.type) 51 && target.equals(otherEvent.target);94 && target.equals(otherEvent.target); 52 95 } else { 53 96 return type.equals(otherEvent.type) 54 && otherEvent.target==null;97 && otherEvent.target == null; 55 98 } 56 99 } else { … … 58 101 } 59 102 } 60 103 104 /** 105 * <p> 106 * Returns {@link #getStandardId()} as String representation of the event. 107 * </p> 108 * 109 * @return String represenation of the event 110 */ 61 111 @Override 62 112 public String toString() { … … 64 114 } 65 115 116 /** 117 * Informations about the event important for its Id that is neither target 118 * nor type. 119 * 120 * @return {@link #idInfo} of the event 121 */ 66 122 public String getIdInfo() { 67 123 return idInfo; 68 124 } 69 125 126 /** 127 * <p> 128 * If {@link #targetShort} is set, a shortend version of the Id is returned 129 * of the form {@link #targetShort}.{@link #type}.{@link #idInfo} is 130 * returned. Otherwise the standard Id is returned (see 131 * {@link #getStandardId()}). 132 * </p> 133 * 134 * @return if available, shortend Id string; {@link #getStandardId()} 135 * otherwise 136 */ 70 137 public String getShortId() { 71 138 String shortId = null; 72 if (targetShort !=null) {73 shortId = targetShort +"."+getType();74 if ( 75 shortId += "." +idInfo;139 if (targetShort != null) { 140 shortId = targetShort + "." + getType(); 141 if (!"".equals(idInfo)) { 142 shortId += "." + idInfo; 76 143 } 77 144 } else { … … 81 148 } 82 149 150 /** 151 * <p> 152 * Returns the Id string of the event. It has the form {@link #target}. 153 * {@link #type}.{@link #idInfo}; 154 * <p> 155 * 156 * @return Id string of the event 157 */ 83 158 public String getStandardId() { 84 159 String id = ""; 85 if ( target!=null) {160 if (target != null) { 86 161 id += target + "."; 87 162 } 88 163 id += getType(); 89 if ( !"".equals(idInfo)) {164 if (!"".equals(idInfo)) { 90 165 id += "." + idInfo; 91 166 } … … 93 168 } 94 169 170 /** 171 * <p> 172 * Returns the {@link #target} of the event. 173 * </p> 174 * 175 * @return {@link #target} of the event 176 */ 95 177 public String getTarget() { 96 178 return target; 97 179 } 98 99 public String getTargetShort() { 180 181 /** 182 * <p> 183 * Returns the {@link #targetShort} of the event. 184 * </p> 185 * 186 * @return {@link #targetShort} of the event 187 */ 188 protected String getTargetShort() { 100 189 return targetShort; 101 190 } 102 191 192 /** 193 * <p> 194 * Returns the {@link #type} of the event. 195 * </p> 196 * 197 * @return {@link #type} of the event 198 */ 103 199 public String getType() { 104 200 return type; 105 201 } 106 202 203 /* 204 * (non-Javadoc) 205 * 206 * @see java.lang.Object#hashCode() 207 */ 107 208 @Override 108 209 public int hashCode() { … … 110 211 int hash = 42; 111 212 hash = multiplier * hash + type.hashCode(); 112 if ( target!=null) {213 if (target != null) { 113 214 hash = multiplier * hash + target.hashCode(); 114 215 } … … 117 218 } 118 219 220 /** 221 * <p> 222 * Sets the {@link #idInfo} of the event. The idInfo is optional and 223 * contains information important for the event's Id that is neither target 224 * nor type. 225 * </p> 226 * 227 * @param info 228 * {@link #idInfo} of the event 229 */ 119 230 public void setIdInfo(String info) { 120 231 idInfo = info; 121 232 } 122 233 123 234 /** 124 235 * <p> 125 236 * Sets the target of the event. Once set, the target cannot be changed. 126 * </p> 127 * @param target target of the event 237 * </p> 238 * 239 * @param target 240 * target of the event 128 241 * @return true, if target was changed, false otherwise 129 242 */ 130 243 public boolean setTarget(String target) { 131 if ( this.target!=null) {244 if (this.target != null) { 132 245 return false; 133 246 } … … 135 248 return true; 136 249 } 137 138 /** 139 * <p> 140 * Sets the short description of the event target. Once set, the target cannot be changed. 141 * </p> 142 * @param targetShort short target description 250 251 /** 252 * <p> 253 * Sets the short description of the event target. Once set, the target 254 * cannot be changed. 255 * </p> 256 * 257 * @param targetShort 258 * short target description 143 259 * @return true, if target was changed, false otherwise 144 260 */ 145 261 public boolean setTargetShort(String targetShort) { 146 if ( this.targetShort!=null) {262 if (this.targetShort != null) { 147 263 return false; 148 264 }
Note: See TracChangeset
for help on using the changeset viewer.