[1] | 1 | package de.ugoe.cs.eventbench.data;
|
---|
| 2 |
|
---|
[12] | 3 | import java.security.InvalidParameterException;
|
---|
[1] | 4 |
|
---|
| 5 |
|
---|
[12] | 6 |
|
---|
[1] | 7 | public class Event<T> {
|
---|
[7] | 8 |
|
---|
| 9 | public static final Event<Object> STARTEVENT = new Event<Object>("START");
|
---|
| 10 | public static final Event<Object> ENDEVENT = new Event<Object>("END");
|
---|
| 11 |
|
---|
[1] | 12 | /**
|
---|
| 13 | * <p>
|
---|
| 14 | * Type of the event.
|
---|
| 15 | * </p>
|
---|
| 16 | */
|
---|
| 17 | private String type;
|
---|
| 18 |
|
---|
| 19 | /**
|
---|
| 20 | * </p>
|
---|
| 21 | * Target of the event.
|
---|
| 22 | */
|
---|
| 23 | private String target = null;
|
---|
| 24 |
|
---|
| 25 | /**
|
---|
| 26 | * <p>
|
---|
| 27 | * Short description of the event target.
|
---|
| 28 | * </p>
|
---|
| 29 | */
|
---|
| 30 | private String targetShort = null;
|
---|
| 31 |
|
---|
| 32 |
|
---|
[5] | 33 | private String idInfo = "";
|
---|
[1] | 34 |
|
---|
| 35 | public Event(String type) {
|
---|
[12] | 36 | if( type==null ) {
|
---|
| 37 | throw new InvalidParameterException("Event type must not be null");
|
---|
| 38 | }
|
---|
[1] | 39 | this.type = type;
|
---|
| 40 | }
|
---|
| 41 |
|
---|
| 42 | @Override
|
---|
| 43 | public boolean equals(Object other) {
|
---|
| 44 | if( this==other ) {
|
---|
| 45 | return true;
|
---|
| 46 | }
|
---|
| 47 | if (other instanceof Event<?>) {
|
---|
[12] | 48 | Event<?> otherEvent = (Event<?>) other;
|
---|
| 49 | if( target!=null ) {
|
---|
| 50 | return type.equals(otherEvent.type)
|
---|
| 51 | && target.equals(otherEvent.target);
|
---|
| 52 | } else {
|
---|
| 53 | return type.equals(otherEvent.type)
|
---|
[23] | 54 | && otherEvent.target==null;
|
---|
[12] | 55 | }
|
---|
[1] | 56 | } else {
|
---|
| 57 | return false;
|
---|
| 58 | }
|
---|
| 59 | }
|
---|
[2] | 60 |
|
---|
| 61 | @Override
|
---|
| 62 | public String toString() {
|
---|
| 63 | return getStandardId();
|
---|
| 64 | }
|
---|
[1] | 65 |
|
---|
| 66 | public String getIdInfo() {
|
---|
| 67 | return idInfo;
|
---|
| 68 | }
|
---|
| 69 |
|
---|
| 70 | public String getShortId() {
|
---|
| 71 | String shortId = null;
|
---|
| 72 | if (targetShort!=null) {
|
---|
| 73 | shortId = targetShort+"."+getType();
|
---|
[23] | 74 | if ( !"".equals(idInfo)) {
|
---|
[1] | 75 | shortId += "."+idInfo;
|
---|
| 76 | }
|
---|
[16] | 77 | } else {
|
---|
| 78 | shortId = getStandardId();
|
---|
[1] | 79 | }
|
---|
| 80 | return shortId;
|
---|
| 81 | }
|
---|
| 82 |
|
---|
| 83 | public String getStandardId() {
|
---|
[12] | 84 | String id = "";
|
---|
| 85 | if( target!=null ) {
|
---|
| 86 | id += target + ".";
|
---|
| 87 | }
|
---|
| 88 | id += getType();
|
---|
[23] | 89 | if ( !"".equals(idInfo) ) {
|
---|
[1] | 90 | id += "." + idInfo;
|
---|
| 91 | }
|
---|
| 92 | return id;
|
---|
| 93 | }
|
---|
| 94 |
|
---|
| 95 | public String getTarget() {
|
---|
| 96 | return target;
|
---|
| 97 | }
|
---|
| 98 |
|
---|
| 99 | public String getTargetShort() {
|
---|
| 100 | return targetShort;
|
---|
| 101 | }
|
---|
| 102 |
|
---|
| 103 | public String getType() {
|
---|
| 104 | return type;
|
---|
| 105 | }
|
---|
| 106 |
|
---|
| 107 | @Override
|
---|
| 108 | public int hashCode() {
|
---|
| 109 | int multiplier = 17;
|
---|
| 110 | int hash = 42;
|
---|
| 111 | hash = multiplier * hash + type.hashCode();
|
---|
| 112 | if( target!=null ) {
|
---|
| 113 | hash = multiplier * hash + target.hashCode();
|
---|
| 114 | }
|
---|
| 115 |
|
---|
| 116 | return hash;
|
---|
| 117 | }
|
---|
| 118 |
|
---|
| 119 | public void setIdInfo(String info) {
|
---|
| 120 | idInfo = info;
|
---|
| 121 | }
|
---|
| 122 |
|
---|
| 123 | /**
|
---|
| 124 | * <p>
|
---|
| 125 | * Sets the target of the event. Once set, the target cannot be changed.
|
---|
| 126 | * </p>
|
---|
| 127 | * @param target target of the event
|
---|
| 128 | * @return true, if target was changed, false otherwise
|
---|
| 129 | */
|
---|
| 130 | public boolean setTarget(String target) {
|
---|
| 131 | if( this.target!=null ) {
|
---|
| 132 | return false;
|
---|
| 133 | }
|
---|
| 134 | this.target = target;
|
---|
| 135 | return true;
|
---|
| 136 | }
|
---|
| 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
|
---|
| 143 | * @return true, if target was changed, false otherwise
|
---|
| 144 | */
|
---|
| 145 | public boolean setTargetShort(String targetShort) {
|
---|
| 146 | if( this.targetShort!=null ) {
|
---|
| 147 | return false;
|
---|
| 148 | }
|
---|
| 149 | this.targetShort = targetShort;
|
---|
| 150 | return true;
|
---|
| 151 | }
|
---|
| 152 | }
|
---|