Monster fix: TMF model update + corresponding LTTng adaptations + JUnits
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf / src / org / eclipse / linuxtools / tmf / event / TmfEventType.java
1 /*******************************************************************************
2 * Copyright (c) 2009 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 *******************************************************************************/
12
13 package org.eclipse.linuxtools.tmf.event;
14
15 import java.util.HashMap;
16 import java.util.Map;
17
18 /**
19 * <b><u>TmfEventType</u></b>
20 * <p>
21 * The event type.
22 */
23 public class TmfEventType implements Cloneable {
24
25 // ========================================================================
26 // Constants
27 // ========================================================================
28
29 public static final String DEFAULT_TYPE_ID = "TMF Default Type";
30 public static final String[] DEFAULT_LABELS = new String[] { "Content" };
31
32 // ========================================================================
33 // Attributes
34 // ========================================================================
35
36 private final String fTypeId;
37 private final String[] fFieldLabels;
38 private final int fNbFields;
39 private final Map<String, Integer> fFieldMap;
40
41 // ========================================================================
42 // Constructors
43 // ========================================================================
44
45 /**
46 *
47 */
48 public TmfEventType() {
49 this(DEFAULT_TYPE_ID, DEFAULT_LABELS);
50 }
51
52 /**
53 * @param type
54 * @param format
55 */
56 public TmfEventType(String typeId, String[] labels) {
57 assert(typeId != null);
58 assert(labels != null);
59 fTypeId = typeId;
60 fFieldLabels = labels;
61 fNbFields = fFieldLabels.length;
62 fFieldMap = new HashMap<String, Integer>();
63 for (int i = 0; i < fNbFields; i++) {
64 fFieldMap.put(fFieldLabels[i], i);
65 }
66 }
67
68 /**
69 * @param other
70 */
71 public TmfEventType(TmfEventType other) {
72 assert(other != null);
73 fTypeId = other.fTypeId;
74 fFieldLabels = other.fFieldLabels;
75 fNbFields = other.fNbFields;
76 fFieldMap = other.fFieldMap;
77 }
78
79 // ========================================================================
80 // Accessors
81 // ========================================================================
82
83 /**
84 * @return
85 */
86 public String getTypeId() {
87 return fTypeId;
88 }
89
90 /**
91 * @return
92 */
93 public int getNbFields() {
94 return fNbFields;
95 }
96
97 /**
98 * @return
99 */
100 public int getFieldIndex(String id) throws TmfNoSuchFieldException {
101 Integer index = fFieldMap.get(id);
102 if (index == null)
103 throw(new TmfNoSuchFieldException(id));
104 return index;
105 }
106
107 /**
108 * @return
109 */
110 public String[] getLabels() {
111 return fFieldLabels;
112 }
113
114 /**
115 * @return
116 */
117 public String getLabel(int i) {
118 if (i >= 0 && i < fNbFields)
119 return fFieldLabels[i];
120 return null;
121 }
122
123 // ========================================================================
124 // Operators
125 // ========================================================================
126
127 @Override
128 public TmfEventType clone() {
129 return new TmfEventType(this);
130 }
131
132 @Override
133 public String toString() {
134 return "[TmfEventType:" + fTypeId + "]";
135 }
136
137 }
This page took 0.034545 seconds and 5 git commands to generate.