Fix javadoc warning
[deliverable/tracecompass.git] / tmf / org.eclipse.tracecompass.tmf.core / src / org / eclipse / tracecompass / tmf / core / parsers / custom / CustomTxtEvent.java
CommitLineData
6151d86c 1/*******************************************************************************
53f17e49 2 * Copyright (c) 2010, 2016 Ericsson
6151d86c
PT
3 *
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
8 *
9 * Contributors:
10 * Patrick Tasse - Initial API and implementation
11 *******************************************************************************/
12
2bdf0193 13package org.eclipse.tracecompass.tmf.core.parsers.custom;
6151d86c
PT
14
15import java.util.regex.Matcher;
16
ca5b04ad 17import org.eclipse.jdt.annotation.NonNull;
2bdf0193
AM
18import org.eclipse.tracecompass.tmf.core.event.ITmfEventField;
19import org.eclipse.tracecompass.tmf.core.event.TmfEvent;
20import org.eclipse.tracecompass.tmf.core.event.TmfEventType;
f5cc6ed1 21import org.eclipse.tracecompass.tmf.core.parsers.custom.CustomTraceDefinition.Tag;
2bdf0193
AM
22import org.eclipse.tracecompass.tmf.core.parsers.custom.CustomTxtTraceDefinition.InputData;
23import org.eclipse.tracecompass.tmf.core.parsers.custom.CustomTxtTraceDefinition.InputLine;
24import org.eclipse.tracecompass.tmf.core.timestamp.ITmfTimestamp;
25import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace;
6151d86c 26
a0a88f65
AM
27/**
28 * Trace event for custom text parsers.
29 *
30 * @author Patrick Tassé
31 */
6151d86c
PT
32public class CustomTxtEvent extends CustomEvent {
33
a0a88f65
AM
34 /**
35 * Constructor
36 *
37 * @param definition
38 * Trace definition
39 */
6151d86c
PT
40 public CustomTxtEvent(CustomTxtTraceDefinition definition) {
41 super(definition);
6151d86c
PT
42 }
43
a0a88f65
AM
44 /**
45 * Construct a custom text event from an existing TmfEvent.
46 *
47 * @param definition
48 * Trace definition
49 * @param other
50 * The TmfEvent object to copy
51 */
ca5b04ad 52 public CustomTxtEvent(CustomTxtTraceDefinition definition, @NonNull TmfEvent other) {
6151d86c
PT
53 super(definition, other);
54 }
55
a0a88f65
AM
56 /**
57 * Full constructor.
58 *
59 * @param definition
60 * Trace definition
61 * @param parentTrace
62 * Parent trace object
63 * @param timestamp
64 * Timestamp of this event
a0a88f65
AM
65 * @param type
66 * Event type
a0a88f65
AM
67 */
68 public CustomTxtEvent(CustomTxtTraceDefinition definition,
e1de2fd4
AM
69 ITmfTrace parentTrace, ITmfTimestamp timestamp, TmfEventType type) {
70 super(definition, parentTrace, timestamp, type);
6151d86c
PT
71 }
72
73 @Override
74 public void setContent(ITmfEventField content) {
75 super.setContent(content);
76 }
77
a0a88f65
AM
78 /**
79 * Process an entry in the trace file
80 *
81 * @param input
82 * The input line to read
83 * @param matcher
84 * The regex matcher to use
85 */
6151d86c 86 public void processGroups(InputLine input, Matcher matcher) {
eddf2682 87 if (input.eventType != null) {
f5cc6ed1 88 fData.put(Tag.EVENT_TYPE, input.eventType);
eddf2682 89 }
d5efe032
AF
90 if (input.columns == null) {
91 return;
92 }
6151d86c
PT
93 for (int i = 0; i < input.columns.size(); i++) {
94 InputData column = input.columns.get(i);
95 if (i < matcher.groupCount() && matcher.group(i + 1) != null) {
96 String value = matcher.group(i + 1).trim();
97 if (value.length() == 0) {
98 continue;
99 }
f5cc6ed1 100 Object key = (column.tag.equals(Tag.OTHER) ? column.name : column.tag);
6151d86c 101 if (column.action == CustomTraceDefinition.ACTION_SET) {
f5cc6ed1
PT
102 fData.put(key, value);
103 if (key.equals(Tag.TIMESTAMP)) {
104 fData.put(Key.TIMESTAMP_INPUT_FORMAT, column.format);
6151d86c
PT
105 }
106 } else if (column.action == CustomTraceDefinition.ACTION_APPEND) {
f5cc6ed1 107 String s = fData.get(key);
6151d86c 108 if (s != null) {
f5cc6ed1 109 fData.put(key, s + value);
6151d86c 110 } else {
f5cc6ed1 111 fData.put(key, value);
6151d86c 112 }
f5cc6ed1
PT
113 if (key.equals(Tag.TIMESTAMP)) {
114 String timeStampInputFormat = fData.get(Key.TIMESTAMP_INPUT_FORMAT);
6151d86c 115 if (timeStampInputFormat != null) {
f5cc6ed1 116 fData.put(Key.TIMESTAMP_INPUT_FORMAT, timeStampInputFormat + column.format);
6151d86c 117 } else {
f5cc6ed1 118 fData.put(Key.TIMESTAMP_INPUT_FORMAT, column.format);
6151d86c
PT
119 }
120 }
121 } else if (column.action == CustomTraceDefinition.ACTION_APPEND_WITH_SEPARATOR) {
f5cc6ed1 122 String s = fData.get(key);
6151d86c 123 if (s != null) {
f5cc6ed1 124 fData.put(key, s + " | " + value); //$NON-NLS-1$
6151d86c 125 } else {
f5cc6ed1 126 fData.put(key, value);
6151d86c 127 }
f5cc6ed1
PT
128 if (key.equals(Tag.TIMESTAMP)) {
129 String timeStampInputFormat = fData.get(Key.TIMESTAMP_INPUT_FORMAT);
6151d86c 130 if (timeStampInputFormat != null) {
f5cc6ed1 131 fData.put(Key.TIMESTAMP_INPUT_FORMAT, timeStampInputFormat + " | " + column.format); //$NON-NLS-1$
6151d86c 132 } else {
f5cc6ed1 133 fData.put(Key.TIMESTAMP_INPUT_FORMAT, column.format);
6151d86c
PT
134 }
135 }
136 }
137 }
138 }
139 }
140
141}
This page took 0.102548 seconds and 5 git commands to generate.