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