Commit | Line | Data |
---|---|---|
8c8bf09f | 1 | /******************************************************************************* |
cbbcc354 | 2 | * Copyright (c) 2009, 2012 Ericsson |
8c8bf09f ASL |
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: | |
1f506a43 | 10 | * Francois Chouinard - Initial API and implementation |
cbbcc354 | 11 | * Francois Chouinard - Updated as per TMF Event Model 1.0 |
8c8bf09f ASL |
12 | *******************************************************************************/ |
13 | ||
6c13869b | 14 | package org.eclipse.linuxtools.tmf.core.event; |
8c8bf09f | 15 | |
8c8bf09f | 16 | /** |
cbbcc354 | 17 | * A basic implementation of ITmfEventType. |
b9e37ffd | 18 | * |
b9e37ffd FC |
19 | * @version 1.0 |
20 | * @author Francois Chouinard | |
f7703ed6 | 21 | * |
b9e37ffd | 22 | * @see ITmfEvent |
f7703ed6 | 23 | * @see ITmfEventField |
8c8bf09f | 24 | */ |
0316808c | 25 | public class TmfEventType implements ITmfEventType, Cloneable { |
8c8bf09f | 26 | |
cbd4ad82 | 27 | // ------------------------------------------------------------------------ |
8c8bf09f | 28 | // Attributes |
cbd4ad82 | 29 | // ------------------------------------------------------------------------ |
8c8bf09f | 30 | |
085d898f FC |
31 | private String fContext; |
32 | private String fTypeId; | |
33 | private ITmfEventField fRootField; | |
8c8bf09f | 34 | |
cbd4ad82 | 35 | // ------------------------------------------------------------------------ |
8c8bf09f | 36 | // Constructors |
cbd4ad82 | 37 | // ------------------------------------------------------------------------ |
8c8bf09f | 38 | |
085d898f FC |
39 | /** |
40 | * Default constructor | |
41 | */ | |
42 | public TmfEventType() { | |
43 | this(DEFAULT_CONTEXT_ID, DEFAULT_TYPE_ID, null); | |
44 | } | |
28b94d61 | 45 | |
4c564a2d FC |
46 | /** |
47 | * Full constructor | |
48 | * | |
49 | * @param context the type context | |
50 | * @param typeId the type name | |
51 | * @param root the root field | |
52 | */ | |
085d898f | 53 | public TmfEventType(final String context, final String typeId, final ITmfEventField root) { |
b9e37ffd | 54 | if (context == null || typeId == null) { |
4c564a2d | 55 | throw new IllegalArgumentException(); |
b9e37ffd | 56 | } |
4c564a2d FC |
57 | fContext = context; |
58 | fTypeId = typeId; | |
59 | fRootField = root; | |
60 | ||
61 | // Register to the event type manager | |
62 | TmfEventTypeManager.getInstance().add(context, this); | |
63 | } | |
28b94d61 | 64 | |
085d898f FC |
65 | /** |
66 | * Copy constructor | |
67 | * | |
68 | * @param type the other type | |
69 | */ | |
70 | public TmfEventType(final ITmfEventType type) { | |
b9e37ffd | 71 | if (type == null) { |
085d898f | 72 | throw new IllegalArgumentException(); |
b9e37ffd | 73 | } |
085d898f FC |
74 | fContext = type.getContext(); |
75 | fTypeId = type.getName(); | |
76 | fRootField = type.getRootField(); | |
77 | } | |
8c8bf09f | 78 | |
cbd4ad82 | 79 | // ------------------------------------------------------------------------ |
cbbcc354 | 80 | // ITmfEventType |
cbd4ad82 | 81 | // ------------------------------------------------------------------------ |
8c8bf09f | 82 | |
d7dbf09a FC |
83 | /* (non-Javadoc) |
84 | * @see org.eclipse.linuxtools.tmf.core.event.ITmfEventType#getContext() | |
85 | */ | |
86 | @Override | |
085d898f FC |
87 | public String getContext() { |
88 | return fContext; | |
89 | } | |
8c8bf09f | 90 | |
d7dbf09a FC |
91 | /* (non-Javadoc) |
92 | * @see org.eclipse.linuxtools.tmf.core.event.ITmfEventType#getName() | |
93 | */ | |
94 | @Override | |
4c564a2d | 95 | public String getName() { |
cbbcc354 | 96 | return fTypeId; |
97 | } | |
98 | ||
d7dbf09a FC |
99 | /* (non-Javadoc) |
100 | * @see org.eclipse.linuxtools.tmf.core.event.ITmfEventType#getRootField() | |
101 | */ | |
102 | @Override | |
4c564a2d FC |
103 | public ITmfEventField getRootField() { |
104 | return fRootField; | |
cbbcc354 | 105 | } |
28b94d61 | 106 | |
d7dbf09a FC |
107 | /* (non-Javadoc) |
108 | * @see org.eclipse.linuxtools.tmf.core.event.ITmfEventType#getFieldNames() | |
109 | */ | |
110 | @Override | |
4c564a2d | 111 | public String[] getFieldNames() { |
b9e37ffd | 112 | return (fRootField != null) ? fRootField.getFieldNames() : null; |
cbbcc354 | 113 | } |
28b94d61 | 114 | |
d7dbf09a FC |
115 | /* (non-Javadoc) |
116 | * @see org.eclipse.linuxtools.tmf.core.event.ITmfEventType#getFieldName(int) | |
117 | */ | |
118 | @Override | |
085d898f | 119 | public String getFieldName(final int index) { |
b9e37ffd | 120 | return (fRootField != null) ? fRootField.getFieldName(index) : null; |
cbbcc354 | 121 | } |
122 | ||
123 | // ------------------------------------------------------------------------ | |
124 | // Cloneable | |
125 | // ------------------------------------------------------------------------ | |
126 | ||
d7dbf09a FC |
127 | /* (non-Javadoc) |
128 | * @see java.lang.Object#clone() | |
129 | */ | |
cbbcc354 | 130 | @Override |
8c149234 | 131 | public TmfEventType clone() { |
cbbcc354 | 132 | TmfEventType clone = null; |
133 | try { | |
134 | clone = (TmfEventType) super.clone(); | |
135 | clone.fContext = fContext; | |
136 | clone.fTypeId = fTypeId; | |
4c564a2d | 137 | clone.fRootField = (fRootField != null) ? fRootField.clone() : null; |
cbbcc354 | 138 | } |
085d898f | 139 | catch (final CloneNotSupportedException e) { |
cbbcc354 | 140 | } |
141 | return clone; | |
142 | } | |
8c8bf09f | 143 | |
cbd4ad82 FC |
144 | // ------------------------------------------------------------------------ |
145 | // Object | |
146 | // ------------------------------------------------------------------------ | |
1f506a43 | 147 | |
d7dbf09a FC |
148 | /* (non-Javadoc) |
149 | * @see java.lang.Object#hashCode() | |
150 | */ | |
cbbcc354 | 151 | @Override |
cbd4ad82 | 152 | public int hashCode() { |
cbbcc354 | 153 | final int prime = 31; |
154 | int result = 1; | |
9ee9135e FC |
155 | result = prime * result + fContext.hashCode(); |
156 | result = prime * result + fTypeId.hashCode(); | |
cbbcc354 | 157 | return result; |
cbd4ad82 FC |
158 | } |
159 | ||
d7dbf09a FC |
160 | /* (non-Javadoc) |
161 | * @see java.lang.Object#equals(java.lang.Object) | |
162 | */ | |
cbbcc354 | 163 | @Override |
085d898f | 164 | public boolean equals(final Object obj) { |
b9e37ffd | 165 | if (this == obj) { |
cbbcc354 | 166 | return true; |
b9e37ffd FC |
167 | } |
168 | if (obj == null) { | |
cbbcc354 | 169 | return false; |
b9e37ffd FC |
170 | } |
171 | if (!(obj instanceof TmfEventType)) { | |
cbbcc354 | 172 | return false; |
b9e37ffd | 173 | } |
085d898f | 174 | final TmfEventType other = (TmfEventType) obj; |
b9e37ffd | 175 | if (!fContext.equals(other.fContext)) { |
cbbcc354 | 176 | return false; |
b9e37ffd FC |
177 | } |
178 | if (!fTypeId.equals(other.fTypeId)) { | |
cbbcc354 | 179 | return false; |
b9e37ffd | 180 | } |
cbbcc354 | 181 | return true; |
28b94d61 FC |
182 | } |
183 | ||
d7dbf09a FC |
184 | /* (non-Javadoc) |
185 | * @see java.lang.Object#toString() | |
186 | */ | |
1f506a43 | 187 | @Override |
3b38ea61 | 188 | @SuppressWarnings("nls") |
1f506a43 | 189 | public String toString() { |
4c564a2d | 190 | return "TmfEventType [fContext=" + fContext + ", fTypeId=" + fTypeId + "]"; |
1f506a43 FC |
191 | } |
192 | ||
28b94d61 | 193 | } |