1 /*******************************************************************************
2 * Copyright (c) 2010 Ericsson
4 * All rights reserved. This program and the accompanying materials are
5 * made available under the terms of the Eclipse Public License v1.0 which
6 * accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
10 * Patrick Tasse - Initial API and implementation
11 *******************************************************************************/
13 package org
.eclipse
.linuxtools
.internal
.tmf
.ui
.parsers
.custom
;
15 import java
.text
.ParseException
;
16 import java
.text
.SimpleDateFormat
;
17 import java
.util
.Arrays
;
18 import java
.util
.Date
;
19 import java
.util
.HashMap
;
22 import org
.eclipse
.linuxtools
.internal
.tmf
.ui
.parsers
.custom
.CustomTraceDefinition
.OutputColumn
;
23 import org
.eclipse
.linuxtools
.tmf
.core
.event
.ITmfTimestamp
;
24 import org
.eclipse
.linuxtools
.tmf
.core
.event
.TmfEvent
;
25 import org
.eclipse
.linuxtools
.tmf
.core
.event
.TmfEventField
;
26 import org
.eclipse
.linuxtools
.tmf
.core
.event
.TmfEventType
;
27 import org
.eclipse
.linuxtools
.tmf
.core
.event
.TmfTimestamp
;
28 import org
.eclipse
.linuxtools
.tmf
.core
.trace
.ITmfTrace
;
30 public class CustomEvent
extends TmfEvent
{
32 protected static final String TIMESTAMP_INPUT_FORMAT_KEY
= "CE_TS_I_F"; //$NON-NLS-1$
33 protected static final String NO_MESSAGE
= ""; //$NON-NLS-1$
34 public static final byte TIMESTAMP_SCALE
= -3;
36 protected CustomTraceDefinition fDefinition
;
37 protected Map
<String
, String
> fData
;
38 private TmfEventField
[] fColumnData
;
40 public CustomEvent(CustomTraceDefinition definition
) {
41 fDefinition
= definition
;
42 fData
= new HashMap
<String
, String
>();
45 public CustomEvent(CustomTraceDefinition definition
, TmfEvent other
) {
47 fDefinition
= definition
;
48 fData
= new HashMap
<String
, String
>();
51 public CustomEvent(CustomTraceDefinition definition
, ITmfTrace
<?
> parentTrace
, ITmfTimestamp timestamp
, String source
, TmfEventType type
, String reference
) {
52 super(parentTrace
, timestamp
, source
, type
, reference
);
53 fDefinition
= definition
;
54 fData
= new HashMap
<String
, String
>();
58 public ITmfTimestamp
getTimestamp() {
59 if (fData
!= null) processData();
60 return super.getTimestamp();
63 public TmfEventField
[] extractItemFields() {
64 if (fData
!= null) processData();
65 return Arrays
.copyOf(fColumnData
, fColumnData
.length
);
68 private void processData() {
69 String timeStampString
= fData
.get(CustomTraceDefinition
.TAG_TIMESTAMP
);
70 String timeStampInputFormat
= fData
.get(TIMESTAMP_INPUT_FORMAT_KEY
);
72 if (timeStampInputFormat
!= null && timeStampString
!= null) {
73 SimpleDateFormat dateFormat
= new SimpleDateFormat(timeStampInputFormat
);
75 date
= dateFormat
.parse(timeStampString
);
76 setTimestamp(new TmfTimestamp(date
.getTime(), TIMESTAMP_SCALE
));
77 } catch (ParseException e
) {
78 setTimestamp(TmfTimestamp
.ZERO
);
81 setTimestamp(TmfTimestamp
.ZERO
);
85 fColumnData
= new TmfEventField
[fDefinition
.outputs
.size()];
86 for (OutputColumn outputColumn
: fDefinition
.outputs
) {
87 String value
= fData
.get(outputColumn
.name
);
88 if (outputColumn
.name
.equals(CustomTraceDefinition
.TAG_TIMESTAMP
) && date
!= null) {
89 SimpleDateFormat dateFormat
= new SimpleDateFormat(fDefinition
.timeStampOutputFormat
);
90 fColumnData
[i
++] = new TmfEventField(outputColumn
.name
, dateFormat
.format(date
));
92 fColumnData
[i
++] = new TmfEventField(outputColumn
.name
, (value
!= null ? value
: "")); //$NON-NLS-1$
99 * @see java.lang.Object#hashCode()
102 public int hashCode() {
103 final int prime
= 31;
104 int result
= super.hashCode();
105 result
= prime
* result
+ ((fDefinition
== null) ?
0 : fDefinition
.hashCode());
110 * @see java.lang.Object#equals(java.lang.Object)
113 public boolean equals(Object obj
) {
117 if (!super.equals(obj
)) {
120 if (!(obj
instanceof CustomEvent
)) {
123 CustomEvent other
= (CustomEvent
) obj
;
124 if (fDefinition
== null) {
125 if (other
.fDefinition
!= null) {
128 } else if (!fDefinition
.equals(other
.fDefinition
)) {