1 /*******************************************************************************
2 * Copyright (c) 2015 École Polytechnique de Montréal
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 *******************************************************************************/
10 package org
.eclipse
.tracecompass
.internal
.lttng2
.kernel
.core
.analysis
.graph
.model
;
12 import org
.eclipse
.tracecompass
.common
.core
.NonNullUtils
;
13 import org
.eclipse
.tracecompass
.tmf
.core
.event
.ITmfEvent
;
14 import org
.eclipse
.tracecompass
.tmf
.core
.event
.ITmfEventField
;
17 * Type casting for getting field values
19 * @author Francis Giraldeau
20 * @author Geneviève Bastien
22 public class EventField
{
31 * @return the long value
33 public static Integer
getInt(ITmfEvent event
, String name
) {
34 ITmfEventField field
= NonNullUtils
.checkNotNull(event
.getContent().getField(name
));
35 Object value
= field
.getValue();
36 if (value
instanceof Long
) {
37 return NonNullUtils
.checkNotNull(((Long
) value
).intValue());
39 return NonNullUtils
.checkNotNull((Integer
) value
);
49 * @return the long value
51 public static Long
getLong(ITmfEvent event
, String name
) {
52 ITmfEventField field
= NonNullUtils
.checkNotNull(event
.getContent().getField(name
));
53 return NonNullUtils
.checkNotNull((Long
) field
.getValue());
63 * @return the string value
65 public static String
getString(ITmfEvent event
, String name
) {
66 ITmfEventField field
= NonNullUtils
.checkNotNull(event
.getContent().getField(name
));
67 return NonNullUtils
.checkNotNull((String
) field
.getValue());
77 * @return the float value
79 public static double getFloat(ITmfEvent event
, String name
) {
80 ITmfEventField field
= NonNullUtils
.checkNotNull(event
.getContent().getField(name
));
81 return NonNullUtils
.checkNotNull((Double
) field
.getValue());
85 * Get string field with default value
92 * the default value to return if the field does not exists
93 * @return the long value
95 public static String
getOrDefault(ITmfEvent event
, String name
, String def
) {
96 ITmfEventField field
= event
.getContent().getField(name
);
100 return NonNullUtils
.checkNotNull((String
) field
.getValue());
This page took 0.036123 seconds and 5 git commands to generate.