Commit | Line | Data |
---|---|---|
8c8bf09f | 1 | /******************************************************************************* |
ed902a2b | 2 | * Copyright (c) 2009, 2014 Ericsson |
80349bf7 | 3 | * |
8c8bf09f ASL |
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 | |
80349bf7 | 8 | * |
8c8bf09f | 9 | * Contributors: |
1f506a43 | 10 | * Francois Chouinard - Initial API and implementation |
cbbcc354 | 11 | * Francois Chouinard - Updated as per TMF Event Model 1.0 |
8c8bf09f ASL |
12 | *******************************************************************************/ |
13 | ||
2bdf0193 | 14 | package org.eclipse.tracecompass.tmf.core.event; |
8c8bf09f | 15 | |
b742c196 AM |
16 | import java.util.Collection; |
17 | import java.util.Collections; | |
18 | ||
df2597e0 AM |
19 | import org.eclipse.jdt.annotation.NonNull; |
20 | ||
8c8bf09f | 21 | /** |
cbbcc354 | 22 | * A basic implementation of ITmfEventType. |
80349bf7 | 23 | * |
b9e37ffd FC |
24 | * @version 1.0 |
25 | * @author Francois Chouinard | |
80349bf7 | 26 | * |
b9e37ffd | 27 | * @see ITmfEvent |
f7703ed6 | 28 | * @see ITmfEventField |
8c8bf09f | 29 | */ |
568007fa | 30 | public class TmfEventType implements ITmfEventType { |
8c8bf09f | 31 | |
cbd4ad82 | 32 | // ------------------------------------------------------------------------ |
8c8bf09f | 33 | // Attributes |
cbd4ad82 | 34 | // ------------------------------------------------------------------------ |
8c8bf09f | 35 | |
df2597e0 | 36 | private final @NonNull String fTypeId; |
568007fa | 37 | private final ITmfEventField fRootField; |
8c8bf09f | 38 | |
cbd4ad82 | 39 | // ------------------------------------------------------------------------ |
8c8bf09f | 40 | // Constructors |
cbd4ad82 | 41 | // ------------------------------------------------------------------------ |
8c8bf09f | 42 | |
085d898f FC |
43 | /** |
44 | * Default constructor | |
45 | */ | |
46 | public TmfEventType() { | |
e600c338 | 47 | this(DEFAULT_TYPE_ID, null); |
085d898f | 48 | } |
28b94d61 | 49 | |
4c564a2d FC |
50 | /** |
51 | * Full constructor | |
80349bf7 | 52 | * |
4c564a2d FC |
53 | * @param typeId the type name |
54 | * @param root the root field | |
55 | */ | |
df2597e0 | 56 | public TmfEventType(final @NonNull String typeId, final ITmfEventField root) { |
4c564a2d FC |
57 | fTypeId = typeId; |
58 | fRootField = root; | |
4c564a2d | 59 | } |
28b94d61 | 60 | |
085d898f FC |
61 | /** |
62 | * Copy constructor | |
80349bf7 | 63 | * |
085d898f FC |
64 | * @param type the other type |
65 | */ | |
df2597e0 | 66 | public TmfEventType(@NonNull ITmfEventType type) { |
085d898f FC |
67 | fTypeId = type.getName(); |
68 | fRootField = type.getRootField(); | |
69 | } | |
8c8bf09f | 70 | |
cbd4ad82 | 71 | // ------------------------------------------------------------------------ |
cbbcc354 | 72 | // ITmfEventType |
cbd4ad82 | 73 | // ------------------------------------------------------------------------ |
8c8bf09f | 74 | |
d7dbf09a | 75 | @Override |
4c564a2d | 76 | public String getName() { |
cbbcc354 | 77 | return fTypeId; |
78 | } | |
79 | ||
d7dbf09a | 80 | @Override |
4c564a2d FC |
81 | public ITmfEventField getRootField() { |
82 | return fRootField; | |
cbbcc354 | 83 | } |
28b94d61 | 84 | |
d7dbf09a | 85 | @Override |
b742c196 AM |
86 | public Collection<String> getFieldNames() { |
87 | return (fRootField != null) ? fRootField.getFieldNames() : Collections.EMPTY_SET; | |
cbbcc354 | 88 | } |
89 | ||
cbd4ad82 FC |
90 | // ------------------------------------------------------------------------ |
91 | // Object | |
92 | // ------------------------------------------------------------------------ | |
1f506a43 | 93 | |
cbbcc354 | 94 | @Override |
cbd4ad82 | 95 | public int hashCode() { |
cbbcc354 | 96 | final int prime = 31; |
97 | int result = 1; | |
9ee9135e | 98 | result = prime * result + fTypeId.hashCode(); |
cbbcc354 | 99 | return result; |
cbd4ad82 FC |
100 | } |
101 | ||
cbbcc354 | 102 | @Override |
085d898f | 103 | public boolean equals(final Object obj) { |
b9e37ffd | 104 | if (this == obj) { |
cbbcc354 | 105 | return true; |
b9e37ffd FC |
106 | } |
107 | if (obj == null) { | |
cbbcc354 | 108 | return false; |
b9e37ffd FC |
109 | } |
110 | if (!(obj instanceof TmfEventType)) { | |
cbbcc354 | 111 | return false; |
b9e37ffd | 112 | } |
085d898f | 113 | final TmfEventType other = (TmfEventType) obj; |
b9e37ffd | 114 | if (!fTypeId.equals(other.fTypeId)) { |
cbbcc354 | 115 | return false; |
b9e37ffd | 116 | } |
cbbcc354 | 117 | return true; |
28b94d61 FC |
118 | } |
119 | ||
1f506a43 | 120 | @Override |
3b38ea61 | 121 | @SuppressWarnings("nls") |
1f506a43 | 122 | public String toString() { |
e600c338 | 123 | return "TmfEventType [fTypeId=" + fTypeId + "]"; |
1f506a43 FC |
124 | } |
125 | ||
568007fa | 126 | } |