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

Last change on this file since 1 was 1, checked in by sherbold, 13 years ago
File size: 2.3 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       
29
30        private String idInfo = null;
31       
32        public Event(String type) {
33                this.type = type;
34        }
35
36        @Override
37        public boolean equals(Object other) {
38                if( this==other ) {
39                        return true;
40                }
41                if (other instanceof Event<?>) {
42                        Event<?> otherToken = (Event<?>) other;
43                        return otherToken.type.equals(this.type)
44                                        && otherToken.target.equals(this.target);
45                } else {
46                        return false;
47                }
48        }
49
50        public String getIdInfo() {
51                return idInfo;
52        }
53
54        public String getShortId() {
55                String shortId = null;
56                if (targetShort!=null) {
57                        shortId = targetShort+"."+getType();
58                        if (idInfo!=null) {
59                                shortId += "."+idInfo;
60                        }
61                }
62                return shortId;
63        }
64
65        public String getStandardId() {
66                String id = target + "." + getType();
67                if ( idInfo!=null ) {
68                        id += "." + idInfo;
69                }
70                return id;
71        }
72
73        public String getTarget() {
74                return target;
75        }
76       
77        public String getTargetShort() {
78                return targetShort;
79        }
80
81        public String getType() {
82                return type;
83        }
84
85        @Override
86        public int hashCode() {
87                int multiplier = 17;
88                int hash = 42;
89                hash = multiplier * hash + type.hashCode();
90                if( target!=null ) {
91                        hash = multiplier * hash + target.hashCode();
92                }
93
94                return hash;
95        }
96
97        public void setIdInfo(String info) {
98                idInfo = info;
99        }
100       
101        /**
102         * <p>
103         * Sets the target of the event. Once set, the target cannot be changed.
104         * </p>
105         * @param target target of the event
106         * @return true, if target was changed, false otherwise
107         */
108        public boolean setTarget(String target) {
109                if( this.target!=null ) {
110                        return false;
111                }
112                this.target = target;
113                return true;
114        }
115       
116        /**
117         * <p>
118         * Sets the short description of the event target. Once set, the target cannot be changed.
119         * </p>
120         * @param targetShort short target description
121         * @return true, if target was changed, false otherwise
122         */
123        public boolean setTargetShort(String targetShort) {
124                if( this.targetShort!=null ) {
125                        return false;
126                }
127                this.targetShort = targetShort;
128                return true;
129        }
130}
Note: See TracBrowser for help on using the repository browser.