1 /*******************************************************************************
2 * Copyright (c) 2009, 2010 Ericsson
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
10 * Francois Chouinard - Initial API and implementation
11 *******************************************************************************/
13 package org
.eclipse
.linuxtools
.tmf
.event
;
15 import java
.util
.HashMap
;
19 * <b><u>TmfEventType</u></b>
23 public class TmfEventType
{
25 // ------------------------------------------------------------------------
27 // ------------------------------------------------------------------------
29 public static final String DEFAULT_TYPE_ID
= "TMF Default Type";
30 public static final String
[] DEFAULT_LABELS
= new String
[] { "Content" };
32 // ------------------------------------------------------------------------
34 // ------------------------------------------------------------------------
36 private final String fTypeId
;
37 private final String
[] fFieldLabels
;
38 private final int fNbFields
;
39 private final Map
<String
, Integer
> fFieldMap
;
41 // ------------------------------------------------------------------------
43 // ------------------------------------------------------------------------
48 public TmfEventType() {
49 this(DEFAULT_TYPE_ID
, DEFAULT_LABELS
);
56 public TmfEventType(String typeId
, String
[] labels
) {
57 if (typeId
== null || labels
== null)
58 throw new IllegalArgumentException();
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
);
72 public TmfEventType(TmfEventType other
) {
74 throw new IllegalArgumentException();
75 fTypeId
= other
.fTypeId
;
76 fFieldLabels
= other
.fFieldLabels
;
77 fNbFields
= other
.fNbFields
;
78 fFieldMap
= other
.fFieldMap
;
81 // ------------------------------------------------------------------------
83 // ------------------------------------------------------------------------
88 public String
getTypeId() {
95 public int getNbFields() {
102 public int getFieldIndex(String id
) throws TmfNoSuchFieldException
{
103 Integer index
= fFieldMap
.get(id
);
105 throw(new TmfNoSuchFieldException(id
));
112 public String
[] getLabels() {
119 public String
getLabel(int i
) throws TmfNoSuchFieldException
{
120 if (i
>= 0 && i
< fNbFields
)
121 return fFieldLabels
[i
];
122 throw new TmfNoSuchFieldException("Bad index (" + i
+ ")");
125 // ------------------------------------------------------------------------
127 // ------------------------------------------------------------------------
130 public int hashCode() {
131 return fTypeId
.hashCode();
135 public boolean equals(Object other
) {
136 if (!(other
instanceof TmfEventType
))
138 TmfEventType o
= (TmfEventType
) other
;
139 return fTypeId
.equals(o
.fTypeId
);
143 public String
toString() {
144 return "[TmfEventType:" + fTypeId
+ "]";
This page took 0.032785 seconds and 5 git commands to generate.