ss: Move plugins to Trace Compass namespace
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.core / src / org / eclipse / linuxtools / tmf / core / event / TmfEventType.java
1 /*******************************************************************************
2 * Copyright (c) 2009, 2013 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 import java.util.Collection;
17 import java.util.Collections;
18
19 /**
20 * A basic implementation of ITmfEventType.
21 *
22 * @version 1.0
23 * @author Francois Chouinard
24 *
25 * @see ITmfEvent
26 * @see ITmfEventField
27 */
28 public class TmfEventType implements ITmfEventType {
29
30 // ------------------------------------------------------------------------
31 // Attributes
32 // ------------------------------------------------------------------------
33
34 private final String fContext;
35 private final String fTypeId;
36 private final ITmfEventField fRootField;
37
38 // ------------------------------------------------------------------------
39 // Constructors
40 // ------------------------------------------------------------------------
41
42 /**
43 * Default constructor
44 */
45 public TmfEventType() {
46 this(DEFAULT_CONTEXT_ID, DEFAULT_TYPE_ID, null);
47 }
48
49 /**
50 * Full constructor
51 *
52 * @param context the type context
53 * @param typeId the type name
54 * @param root the root field
55 */
56 public TmfEventType(final String context, final String typeId, final ITmfEventField root) {
57 if (context == null || typeId == null) {
58 throw new IllegalArgumentException();
59 }
60 fContext = context;
61 fTypeId = typeId;
62 fRootField = root;
63
64 // Register to the event type manager
65 TmfEventTypeManager.getInstance().add(context, this);
66 }
67
68 /**
69 * Copy constructor
70 *
71 * @param type the other type
72 */
73 public TmfEventType(final ITmfEventType type) {
74 if (type == null) {
75 throw new IllegalArgumentException();
76 }
77 fContext = type.getContext();
78 fTypeId = type.getName();
79 fRootField = type.getRootField();
80 }
81
82 // ------------------------------------------------------------------------
83 // ITmfEventType
84 // ------------------------------------------------------------------------
85
86 @Override
87 public String getContext() {
88 return fContext;
89 }
90
91 @Override
92 public String getName() {
93 return fTypeId;
94 }
95
96 @Override
97 public ITmfEventField getRootField() {
98 return fRootField;
99 }
100
101 /**
102 * @since 3.0
103 */
104 @Override
105 public Collection<String> getFieldNames() {
106 return (fRootField != null) ? fRootField.getFieldNames() : Collections.EMPTY_SET;
107 }
108
109 // ------------------------------------------------------------------------
110 // Object
111 // ------------------------------------------------------------------------
112
113 @Override
114 public int hashCode() {
115 final int prime = 31;
116 int result = 1;
117 result = prime * result + fContext.hashCode();
118 result = prime * result + fTypeId.hashCode();
119 return result;
120 }
121
122 @Override
123 public boolean equals(final Object obj) {
124 if (this == obj) {
125 return true;
126 }
127 if (obj == null) {
128 return false;
129 }
130 if (!(obj instanceof TmfEventType)) {
131 return false;
132 }
133 final TmfEventType other = (TmfEventType) obj;
134 if (!fContext.equals(other.fContext)) {
135 return false;
136 }
137 if (!fTypeId.equals(other.fTypeId)) {
138 return false;
139 }
140 return true;
141 }
142
143 @Override
144 @SuppressWarnings("nls")
145 public String toString() {
146 return "TmfEventType [fContext=" + fContext + ", fTypeId=" + fTypeId + "]";
147 }
148
149 }
This page took 0.034056 seconds and 5 git commands to generate.