Commit | Line | Data |
---|---|---|
a0a88f65 | 1 | /******************************************************************************* |
53f17e49 | 2 | * Copyright (c) 2010, 2016 Ericsson |
a0a88f65 AM |
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 Tassé - Initial API and implementation | |
11 | *******************************************************************************/ | |
12 | ||
2bdf0193 | 13 | package org.eclipse.tracecompass.tmf.core.parsers.custom; |
be222f56 | 14 | |
53f17e49 | 15 | import org.eclipse.jdt.annotation.NonNull; |
2bdf0193 AM |
16 | import org.eclipse.tracecompass.tmf.core.event.ITmfEventField; |
17 | import org.eclipse.tracecompass.tmf.core.event.TmfEventField; | |
18 | import org.eclipse.tracecompass.tmf.core.event.TmfEventType; | |
be222f56 | 19 | |
a0a88f65 AM |
20 | /** |
21 | * Event type for custom text parsers. | |
22 | * | |
23 | * @author Patrick Tassé | |
24 | */ | |
be222f56 | 25 | public abstract class CustomEventType extends TmfEventType { |
a0a88f65 | 26 | |
53f17e49 GB |
27 | private static final @NonNull String EMPTY = ""; //$NON-NLS-1$ |
28 | private @NonNull String fEventName; | |
29 | ||
53f17e49 GB |
30 | /** |
31 | * Constructor | |
32 | * | |
33 | * @param eventName | |
34 | * the event name | |
35 | * @param root | |
36 | * the root field | |
37 | * @since 2.1 | |
38 | */ | |
39 | public CustomEventType(@NonNull String eventName, ITmfEventField root) { | |
40 | super(EMPTY, root); | |
41 | fEventName = eventName; | |
42 | } | |
43 | ||
44 | @Override | |
45 | public @NonNull String getName() { | |
46 | return fEventName; | |
47 | } | |
48 | ||
49 | /** | |
50 | * Set the event name. | |
51 | * | |
52 | * @param eventName | |
53 | * the event name | |
54 | * @since 2.1 | |
55 | */ | |
56 | public void setName(@NonNull String eventName) { | |
57 | fEventName = eventName; | |
be222f56 PT |
58 | } |
59 | ||
53f17e49 | 60 | static ITmfEventField getRootField(CustomTraceDefinition definition) { |
be222f56 PT |
61 | ITmfEventField[] fields = new ITmfEventField[definition.outputs.size()]; |
62 | for (int i = 0; i < fields.length; i++) { | |
214cc822 | 63 | fields[i] = new TmfEventField(definition.outputs.get(i).name, null, null); |
be222f56 | 64 | } |
214cc822 | 65 | ITmfEventField rootField = new TmfEventField(ITmfEventField.ROOT_FIELD_ID, null, fields); |
be222f56 PT |
66 | return rootField; |
67 | } | |
68 | ||
53f17e49 GB |
69 | @Override |
70 | public int hashCode() { | |
71 | int result = super.hashCode(); | |
72 | result += fEventName.hashCode(); | |
73 | return result; | |
74 | } | |
75 | ||
76 | @Override | |
77 | public boolean equals(Object obj) { | |
78 | if (super.equals(obj) && (obj.getClass().equals(getClass()))) { | |
79 | return fEventName.equals(((CustomEventType) obj).fEventName); | |
80 | } | |
81 | return false; | |
82 | } | |
83 | ||
84 | @Override | |
85 | public String toString() { | |
86 | return fEventName; | |
87 | } | |
be222f56 | 88 | } |