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