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

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

+ added class TrieBasedModel? as base class for all usage models that calculate probabilities based on a trie
+ extracted everything except the probability calculation from PPM to TrieBasedModel?
+ added HighOrderMarkovModel? based on TrieBasedModel?

File size: 2.8 KB
Line 
1package de.ugoe.cs.eventbench.data;
2
3import java.security.InvalidParameterException;
4
5
6
7public class Event<T> {
8       
9        public static final Event<Object> STARTEVENT = new Event<Object>("START");
10        public static final Event<Object> ENDEVENT = new Event<Object>("END");
11       
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
33        private String idInfo = "";
34       
35        public Event(String type) {
36                if( type==null ) {
37                        throw new InvalidParameterException("Event type must not be null");
38                }
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<?>) {
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)
54                                        && target==otherEvent.target;
55                        }
56                } else {
57                        return false;
58                }
59        }
60       
61        @Override
62        public String toString() {
63                return getStandardId();
64        }
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();
74                        if (idInfo!="") {
75                                shortId += "."+idInfo;
76                        }
77                }
78                return shortId;
79        }
80
81        public String getStandardId() {
82                String id = "";
83                if( target!=null ) {
84                        id += target + ".";
85                }
86                id += getType();
87                if ( idInfo!="" ) {
88                        id += "." + idInfo;
89                }
90                return id;
91        }
92
93        public String getTarget() {
94                return target;
95        }
96       
97        public String getTargetShort() {
98                return targetShort;
99        }
100
101        public String getType() {
102                return type;
103        }
104
105        @Override
106        public int hashCode() {
107                int multiplier = 17;
108                int hash = 42;
109                hash = multiplier * hash + type.hashCode();
110                if( target!=null ) {
111                        hash = multiplier * hash + target.hashCode();
112                }
113
114                return hash;
115        }
116
117        public void setIdInfo(String info) {
118                idInfo = info;
119        }
120       
121        /**
122         * <p>
123         * Sets the target of the event. Once set, the target cannot be changed.
124         * </p>
125         * @param target target of the event
126         * @return true, if target was changed, false otherwise
127         */
128        public boolean setTarget(String target) {
129                if( this.target!=null ) {
130                        return false;
131                }
132                this.target = target;
133                return true;
134        }
135       
136        /**
137         * <p>
138         * Sets the short description of the event target. Once set, the target cannot be changed.
139         * </p>
140         * @param targetShort short target description
141         * @return true, if target was changed, false otherwise
142         */
143        public boolean setTargetShort(String targetShort) {
144                if( this.targetShort!=null ) {
145                        return false;
146                }
147                this.targetShort = targetShort;
148                return true;
149        }
150}
Note: See TracBrowser for help on using the repository browser.