Commit | Line | Data |
---|---|---|
c3c5c786 FC |
1 | /*******************************************************************************\r |
2 | * Copyright (c) 2010 Ericsson\r | |
6256d8ad | 3 | *\r |
c3c5c786 FC |
4 | * All rights reserved. This program and the accompanying materials are\r |
5 | * made available under the terms of the Eclipse Public License v1.0 which\r | |
6 | * accompanies this distribution, and is available at\r | |
7 | * http://www.eclipse.org/legal/epl-v10.html\r | |
6256d8ad | 8 | *\r |
c3c5c786 FC |
9 | * Contributors:\r |
10 | * Patrick Tasse - Initial API and implementation\r | |
11 | *******************************************************************************/\r | |
12 | \r | |
d34665f9 | 13 | package org.eclipse.linuxtools.internal.tmf.ui.parsers.custom;\r |
c3c5c786 FC |
14 | \r |
15 | import java.text.ParseException;\r | |
16 | import java.text.SimpleDateFormat;\r | |
5a5c2fc7 | 17 | import java.util.Arrays;\r |
c3c5c786 FC |
18 | import java.util.Date;\r |
19 | import java.util.HashMap;\r | |
20 | import java.util.Map;\r | |
21 | \r | |
d34665f9 | 22 | import org.eclipse.linuxtools.internal.tmf.ui.parsers.custom.CustomTraceDefinition.OutputColumn;\r |
4df4581d | 23 | import org.eclipse.linuxtools.tmf.core.event.ITmfTimestamp;\r |
6c13869b | 24 | import org.eclipse.linuxtools.tmf.core.event.TmfEvent;\r |
5d3e8747 | 25 | import org.eclipse.linuxtools.tmf.core.event.TmfEventField;\r |
6c13869b FC |
26 | import org.eclipse.linuxtools.tmf.core.event.TmfEventType;\r |
27 | import org.eclipse.linuxtools.tmf.core.event.TmfTimestamp;\r | |
28 | import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace;\r | |
c3c5c786 FC |
29 | \r |
30 | public class CustomEvent extends TmfEvent {\r | |
31 | \r | |
3b38ea61 FC |
32 | protected static final String TIMESTAMP_INPUT_FORMAT_KEY = "CE_TS_I_F"; //$NON-NLS-1$\r |
33 | protected static final String NO_MESSAGE = ""; //$NON-NLS-1$\r | |
c3c5c786 | 34 | public static final byte TIMESTAMP_SCALE = -3;\r |
6256d8ad | 35 | \r |
c3c5c786 FC |
36 | protected CustomTraceDefinition fDefinition;\r |
37 | protected Map<String, String> fData;\r | |
5d3e8747 | 38 | private TmfEventField[] fColumnData;\r |
c3c5c786 | 39 | \r |
4bf17f4a | 40 | public CustomEvent(CustomTraceDefinition definition) {\r |
41 | fDefinition = definition;\r | |
42 | fData = new HashMap<String, String>();\r | |
43 | }\r | |
44 | \r | |
c3c5c786 FC |
45 | public CustomEvent(CustomTraceDefinition definition, TmfEvent other) {\r |
46 | super(other);\r | |
47 | fDefinition = definition;\r | |
48 | fData = new HashMap<String, String>();\r | |
49 | }\r | |
50 | \r | |
6256d8ad | 51 | public CustomEvent(CustomTraceDefinition definition, ITmfTrace parentTrace, ITmfTimestamp timestamp, String source, TmfEventType type, String reference) {\r |
f7703ed6 | 52 | super(parentTrace, timestamp, source, type, null, reference);\r |
c3c5c786 FC |
53 | fDefinition = definition;\r |
54 | fData = new HashMap<String, String>();\r | |
55 | }\r | |
56 | \r | |
c3c5c786 | 57 | @Override\r |
4df4581d | 58 | public ITmfTimestamp getTimestamp() {\r |
6256d8ad AM |
59 | if (fData != null) {\r |
60 | processData();\r | |
61 | }\r | |
c3c5c786 FC |
62 | return super.getTimestamp();\r |
63 | }\r | |
64 | \r | |
5d3e8747 | 65 | public TmfEventField[] extractItemFields() {\r |
6256d8ad AM |
66 | if (fData != null) {\r |
67 | processData();\r | |
68 | }\r | |
5a5c2fc7 | 69 | return Arrays.copyOf(fColumnData, fColumnData.length);\r |
c3c5c786 FC |
70 | }\r |
71 | \r | |
72 | private void processData() {\r | |
73 | String timeStampString = fData.get(CustomTraceDefinition.TAG_TIMESTAMP);\r | |
74 | String timeStampInputFormat = fData.get(TIMESTAMP_INPUT_FORMAT_KEY);\r | |
75 | Date date = null;\r | |
76 | if (timeStampInputFormat != null && timeStampString != null) {\r | |
77 | SimpleDateFormat dateFormat = new SimpleDateFormat(timeStampInputFormat);\r | |
78 | try {\r | |
79 | date = dateFormat.parse(timeStampString);\r | |
7b477cc3 | 80 | setTimestamp(new TmfTimestamp(date.getTime(), TIMESTAMP_SCALE));\r |
c3c5c786 | 81 | } catch (ParseException e) {\r |
a4115405 | 82 | setTimestamp(TmfTimestamp.ZERO);\r |
c3c5c786 FC |
83 | }\r |
84 | } else {\r | |
a4115405 | 85 | setTimestamp(TmfTimestamp.ZERO);\r |
c3c5c786 | 86 | }\r |
6256d8ad | 87 | \r |
c3c5c786 | 88 | int i = 0;\r |
5d3e8747 | 89 | fColumnData = new TmfEventField[fDefinition.outputs.size()];\r |
c3c5c786 FC |
90 | for (OutputColumn outputColumn : fDefinition.outputs) {\r |
91 | String value = fData.get(outputColumn.name);\r | |
92 | if (outputColumn.name.equals(CustomTraceDefinition.TAG_TIMESTAMP) && date != null) {\r | |
93 | SimpleDateFormat dateFormat = new SimpleDateFormat(fDefinition.timeStampOutputFormat);\r | |
4c564a2d | 94 | fColumnData[i++] = new TmfEventField(outputColumn.name, dateFormat.format(date));\r |
c3c5c786 | 95 | } else {\r |
4c564a2d | 96 | fColumnData[i++] = new TmfEventField(outputColumn.name, (value != null ? value : "")); //$NON-NLS-1$\r |
c3c5c786 FC |
97 | }\r |
98 | }\r | |
21ee0aa7 PT |
99 | CustomEventContent content = (CustomEventContent) getContent();\r |
100 | content.setFields(fColumnData);\r | |
c3c5c786 FC |
101 | fData = null;\r |
102 | }\r | |
6e85c58d | 103 | \r |
de126dbb FC |
104 | /* (non-Javadoc)\r |
105 | * @see java.lang.Object#hashCode()\r | |
106 | */\r | |
107 | @Override\r | |
108 | public int hashCode() {\r | |
109 | final int prime = 31;\r | |
110 | int result = super.hashCode();\r | |
111 | result = prime * result + ((fDefinition == null) ? 0 : fDefinition.hashCode());\r | |
112 | return result;\r | |
113 | }\r | |
114 | \r | |
115 | /* (non-Javadoc)\r | |
116 | * @see java.lang.Object#equals(java.lang.Object)\r | |
117 | */\r | |
118 | @Override\r | |
119 | public boolean equals(Object obj) {\r | |
120 | if (this == obj) {\r | |
121 | return true;\r | |
122 | }\r | |
123 | if (!super.equals(obj)) {\r | |
124 | return false;\r | |
125 | }\r | |
126 | if (!(obj instanceof CustomEvent)) {\r | |
127 | return false;\r | |
128 | }\r | |
129 | CustomEvent other = (CustomEvent) obj;\r | |
130 | if (fDefinition == null) {\r | |
131 | if (other.fDefinition != null) {\r | |
132 | return false;\r | |
133 | }\r | |
134 | } else if (!fDefinition.equals(other.fDefinition)) {\r | |
135 | return false;\r | |
136 | }\r | |
137 | return true;\r | |
138 | }\r | |
139 | \r | |
c3c5c786 | 140 | }\r |