Remove all existing @since annotations
[deliverable/tracecompass.git] / org.eclipse.tracecompass.tmf.core / src / org / eclipse / tracecompass / tmf / core / project / model / TraceTypeHelper.java
CommitLineData
d04ec5a7 1/*******************************************************************************
38d284eb 2 * Copyright (c) 2013, 2015 Ericsson
d04ec5a7
MK
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 * Matthew Khouzam - Initial API and implementation
d8aba2e2 11 * Bernd Hufmann - Handling of directory traces types
376fdfbd 12 * Geneviève Bastien - Added support of experiment types
38d284eb 13 * Patrick Tasse - Renamed trace type id
d04ec5a7
MK
14 *******************************************************************************/
15
2bdf0193 16package org.eclipse.tracecompass.tmf.core.project.model;
d04ec5a7 17
350cae41 18import org.eclipse.core.runtime.IStatus;
a8ddd783 19import org.eclipse.jdt.annotation.NonNull;
2bdf0193
AM
20import org.eclipse.tracecompass.tmf.core.project.model.TmfTraceType.TraceElementType;
21import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace;
22import org.eclipse.tracecompass.tmf.core.trace.TraceValidationStatus;
d04ec5a7
MK
23
24/**
d8aba2e2 25 * TraceTypeHelper, a helper that can link a few names to a configuration element
d04ec5a7
MK
26 * and a trace
27 *
28 * @author Matthew Khouzam
d04ec5a7
MK
29 */
30public class TraceTypeHelper {
31
2b0005f0
PT
32 private static final String SEP = " : "; //$NON-NLS-1$
33
d04ec5a7
MK
34 private final String fName;
35 private final String fCategoryName;
38d284eb 36 private final String fTraceTypeId;
376fdfbd 37 private final TraceElementType fElementType;
a8ddd783 38 @NonNull
d04ec5a7 39 private final ITmfTrace fTrace;
d8aba2e2 40 private final boolean fIsDirectory;
d04ec5a7
MK
41
42 /**
38d284eb
PT
43 * Constructor for a trace type helper. It is a link between a trace type
44 * id, a category name, a name and a trace object.
d04ec5a7 45 *
38d284eb
PT
46 * @param traceTypeId
47 * the trace type id
d04ec5a7
MK
48 * @param categoryName
49 * the category of the trace type
50 * @param name
38d284eb 51 * the name of the trace type
d04ec5a7
MK
52 * @param trace
53 * an object of the trace type
d8aba2e2 54 * @param isDir
38d284eb
PT
55 * flag indicating whether the trace type is for a directory or
56 * file trace
376fdfbd
GB
57 * @param elementType
58 * True if this helper is for an experiment type
d04ec5a7 59 */
38d284eb 60 public TraceTypeHelper(String traceTypeId, String categoryName, String name, @NonNull ITmfTrace trace, boolean isDir, TraceElementType elementType) {
d04ec5a7
MK
61 fName = name;
62 fCategoryName = categoryName;
38d284eb 63 fTraceTypeId = traceTypeId;
d04ec5a7 64 fTrace = trace;
d8aba2e2 65 fIsDirectory = isDir;
376fdfbd 66 fElementType = elementType;
d04ec5a7
MK
67 }
68
69 /**
70 * Get the name
71 *
72 * @return the name
73 */
74 public String getName() {
75 return fName;
76 }
77
78 /**
79 * Get the category name
80 *
81 * @return the category name
82 */
83 public String getCategoryName() {
84 return fCategoryName;
85 }
86
87 /**
2b0005f0
PT
88 * Get the trace type label "category : name".
89 *
90 * @return the trace type label
91 */
92 public String getLabel() {
93 if (fCategoryName.isEmpty()) {
94 return fName;
95 }
96 return fCategoryName + SEP + fName;
97 }
98
99 /**
38d284eb 100 * Get the trace type id
d04ec5a7 101 *
38d284eb 102 * @return the trace type id
d04ec5a7 103 */
38d284eb
PT
104 public String getTraceTypeId() {
105 return fTraceTypeId;
d04ec5a7
MK
106 }
107
108 /**
109 * Is the trace of this type?
110 *
111 * @param path
112 * the trace to validate
113 * @return whether it passes the validation
114 */
a8ddd783
GB
115 public IStatus validate(String path) {
116 return fTrace.validate(null, path);
d04ec5a7
MK
117 }
118
350cae41
PT
119 /**
120 * Validate a trace against this trace type with confidence level
121 *
122 * @param path
123 * the trace to validate
124 * @return the confidence level (0 is lowest) or -1 if validation fails
350cae41
PT
125 */
126 public int validateWithConfidence(String path) {
127 int result = -1;
a8ddd783
GB
128 IStatus status = fTrace.validate(null, path);
129 if (status.isOK()) {
130 result = 0;
131 if (status instanceof TraceValidationStatus) {
132 result = ((TraceValidationStatus) status).getConfidence();
350cae41
PT
133 }
134 }
135 return result;
136 }
137
76fccfb0
MK
138 /**
139 * Get an object of the trace type
140 * @return an object of the trace type
76fccfb0 141 */
0a19e2d1 142 public ITmfTrace getTrace() {
76fccfb0
MK
143 return fTrace;
144 }
145
376fdfbd
GB
146 /**
147 * Return whether this helper applies to a trace type or experiment type
148 *
149 * @return True if experiment type, false otherwise
150 */
151 public boolean isExperimentType() {
152 return fElementType == TraceElementType.EXPERIMENT;
153 }
154
c068a752
GB
155 /**
156 * Get the class associated with this trace type
157 *
158 * @return The trace class
c068a752
GB
159 */
160 public Class<? extends ITmfTrace> getTraceClass() {
161 return fTrace.getClass();
162 }
163
d8aba2e2
BH
164 /**
165 * Returns whether trace type is for a directory trace or a single file trace
166 * @return <code>true</code> if trace type is for a directory trace else <code>false</code>
167 */
168 public boolean isDirectoryTraceType() {
169 return fIsDirectory;
170 }
171
172
d04ec5a7
MK
173 @Override
174 public String toString() {
175 return fName;
176 }
177
bcb8c2cb 178}
This page took 0.066647 seconds and 5 git commands to generate.