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