1 package fulmine.event;
2
3 import fulmine.util.Utils;
4 import fulmine.util.reference.is;
5
6
7
8
9
10
11
12
13
14 public final class EventQueueItem<EVENT>
15 {
16
17
18 private final EVENT event;
19
20
21 private final long createTimeMicro = System.nanoTime() / 1000;
22
23
24
25
26
27 private final boolean statisticsEvent;
28
29
30
31
32
33
34 public static ThreadLocal<Boolean> isStatisticsEvent =
35 new ThreadLocal<Boolean>();
36
37
38
39
40
41
42
43 public EventQueueItem(EVENT event)
44 {
45 super();
46 this.event = event;
47 final Boolean isStatistics = isStatisticsEvent.get();
48 if (isStatistics != null)
49 {
50 this.statisticsEvent = isStatistics.booleanValue();
51 }
52 else
53 {
54 this.statisticsEvent = false;
55 }
56 }
57
58
59
60
61
62
63 public EVENT getEvent()
64 {
65 return this.event;
66 }
67
68
69
70
71
72
73 public long getCreateTimeMicro()
74 {
75 return this.createTimeMicro;
76 }
77
78
79
80
81
82
83
84 public boolean isStatisticsEvent()
85 {
86 return this.statisticsEvent;
87 }
88
89
90
91
92
93
94
95
96 public long getElapsedTimeMicro()
97 {
98 return (System.nanoTime() / 1000) - getCreateTimeMicro();
99 }
100
101 @Override
102 public int hashCode()
103 {
104 final int prime = 31;
105 int result = 1;
106 result =
107 prime * result + (int) (createTimeMicro ^ (createTimeMicro >>> 32));
108 result = prime * result + ((event == null) ? 0 : event.hashCode());
109 return result;
110 }
111
112 @SuppressWarnings("unchecked")
113 @Override
114 public boolean equals(Object obj)
115 {
116 if (is.same(this, obj))
117 {
118 return true;
119 }
120 if (is.differentClass(this, obj))
121 {
122 return false;
123 }
124 EventQueueItem other = (EventQueueItem) obj;
125 return is.eq(this.createTimeMicro, other.createTimeMicro)
126 && is.eq(this.event, other.event);
127 }
128
129 @Override
130 public String toString()
131 {
132 return Utils.string(this, "createTimeMicro=" + getCreateTimeMicro()
133 + ", event=" + getEvent());
134 }
135 }