source: trunk/EventBenchCore/src/de/ugoe/cs/eventbench/data/Event.java @ 2

Last change on this file since 2 was 2, checked in by sherbold, 13 years ago

+ added toString() to Event

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