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
, null, reference
);
53 fDefinition
= definition
;
54 fData
= new HashMap
<String
, String
>();
58 public ITmfTimestamp
getTimestamp() {
62 return super.getTimestamp();
65 public TmfEventField
[] extractItemFields() {
69 return Arrays
.copyOf(fColumnData
, fColumnData
.length
);
72 private void processData() {
73 String timeStampString
= fData
.get(CustomTraceDefinition
.TAG_TIMESTAMP
);
74 String timeStampInputFormat
= fData
.get(TIMESTAMP_INPUT_FORMAT_KEY
);
76 if (timeStampInputFormat
!= null && timeStampString
!= null) {
77 SimpleDateFormat dateFormat
= new SimpleDateFormat(timeStampInputFormat
);
79 date
= dateFormat
.parse(timeStampString
);
80 setTimestamp(new TmfTimestamp(date
.getTime(), TIMESTAMP_SCALE
));
81 } catch (ParseException e
) {
82 setTimestamp(TmfTimestamp
.ZERO
);
85 setTimestamp(TmfTimestamp
.ZERO
);
89 fColumnData
= new TmfEventField
[fDefinition
.outputs
.size()];
90 for (OutputColumn outputColumn
: fDefinition
.outputs
) {
91 String value
= fData
.get(outputColumn
.name
);
92 if (outputColumn
.name
.equals(CustomTraceDefinition
.TAG_TIMESTAMP
) && date
!= null) {
93 SimpleDateFormat dateFormat
= new SimpleDateFormat(fDefinition
.timeStampOutputFormat
);
94 fColumnData
[i
++] = new TmfEventField(outputColumn
.name
, dateFormat
.format(date
));
96 fColumnData
[i
++] = new TmfEventField(outputColumn
.name
, (value
!= null ? value
: "")); //$NON-NLS-1$
99 CustomEventContent content
= (CustomEventContent
) getContent();
100 content
.setFields(fColumnData
);
105 * @see java.lang.Object#hashCode()
108 public int hashCode() {
109 final int prime
= 31;
110 int result
= super.hashCode();
111 result
= prime
* result
+ ((fDefinition
== null) ?
0 : fDefinition
.hashCode());
116 * @see java.lang.Object#equals(java.lang.Object)
119 public boolean equals(Object obj
) {
123 if (!super.equals(obj
)) {
126 if (!(obj
instanceof CustomEvent
)) {
129 CustomEvent other
= (CustomEvent
) obj
;
130 if (fDefinition
== null) {
131 if (other
.fDefinition
!= null) {
134 } else if (!fDefinition
.equals(other
.fDefinition
)) {