Update formatter settings for all plugins
[deliverable/tracecompass.git] / tmf / org.eclipse.tracecompass.tmf.core / src / org / eclipse / tracecompass / tmf / core / parsers / custom / CustomTxtEvent.java
CommitLineData
6151d86c 1/*******************************************************************************
60ae41e1 2 * Copyright (c) 2010, 2014 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;
21import org.eclipse.tracecompass.tmf.core.parsers.custom.CustomTxtTraceDefinition.InputData;
22import org.eclipse.tracecompass.tmf.core.parsers.custom.CustomTxtTraceDefinition.InputLine;
23import org.eclipse.tracecompass.tmf.core.timestamp.ITmfTimestamp;
24import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace;
6151d86c 25
a0a88f65
AM
26/**
27 * Trace event for custom text parsers.
28 *
29 * @author Patrick Tassé
30 */
6151d86c
PT
31public class CustomTxtEvent extends CustomEvent {
32
a0a88f65
AM
33 /**
34 * Constructor
35 *
36 * @param definition
37 * Trace definition
38 */
6151d86c
PT
39 public CustomTxtEvent(CustomTxtTraceDefinition definition) {
40 super(definition);
41 setType(new CustomTxtEventType(definition));
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) {
d5efe032
AF
87 if (input.columns == null) {
88 return;
89 }
6151d86c
PT
90 for (int i = 0; i < input.columns.size(); i++) {
91 InputData column = input.columns.get(i);
92 if (i < matcher.groupCount() && matcher.group(i + 1) != null) {
93 String value = matcher.group(i + 1).trim();
94 if (value.length() == 0) {
95 continue;
96 }
97 String name = column.name;
98 if (column.action == CustomTraceDefinition.ACTION_SET) {
99 fData.put(name, value);
100 if (name.equals(CustomTraceDefinition.TAG_TIMESTAMP)) {
101 fData.put(TIMESTAMP_INPUT_FORMAT_KEY, column.format);
102 }
103 } else if (column.action == CustomTraceDefinition.ACTION_APPEND) {
104 String s = fData.get(name);
105 if (s != null) {
106 fData.put(name, s + value);
107 } else {
108 fData.put(name, value);
109 }
110 if (name.equals(CustomTraceDefinition.TAG_TIMESTAMP)) {
111 String timeStampInputFormat = fData.get(TIMESTAMP_INPUT_FORMAT_KEY);
112 if (timeStampInputFormat != null) {
113 fData.put(TIMESTAMP_INPUT_FORMAT_KEY, timeStampInputFormat + column.format);
114 } else {
115 fData.put(TIMESTAMP_INPUT_FORMAT_KEY, column.format);
116 }
117 }
118 } else if (column.action == CustomTraceDefinition.ACTION_APPEND_WITH_SEPARATOR) {
119 String s = fData.get(name);
120 if (s != null) {
121 fData.put(name, s + " | " + value); //$NON-NLS-1$
122 } else {
123 fData.put(name, value);
124 }
125 if (name.equals(CustomTraceDefinition.TAG_TIMESTAMP)) {
126 String timeStampInputFormat = fData.get(TIMESTAMP_INPUT_FORMAT_KEY);
127 if (timeStampInputFormat != null) {
128 fData.put(TIMESTAMP_INPUT_FORMAT_KEY, timeStampInputFormat + " | " + column.format); //$NON-NLS-1$
129 } else {
130 fData.put(TIMESTAMP_INPUT_FORMAT_KEY, column.format);
131 }
132 }
133 }
134 }
135 }
136 }
137
138}
This page took 0.136039 seconds and 5 git commands to generate.