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