lttng: Add the dependency graph model and handlers for an LTTng kernel
[deliverable/tracecompass.git] / lttng / org.eclipse.tracecompass.lttng2.kernel.core / src / org / eclipse / tracecompass / internal / lttng2 / kernel / core / analysis / graph / model / EventField.java
1 /*******************************************************************************
2 * Copyright (c) 2015 École Polytechnique de Montréal
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
10 package org.eclipse.tracecompass.internal.lttng2.kernel.core.analysis.graph.model;
11
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;
15
16 /**
17 * Type casting for getting field values
18 *
19 * @author Francis Giraldeau
20 * @author Geneviève Bastien
21 */
22 public class EventField {
23
24 /**
25 * Get int field
26 *
27 * @param event
28 * the event
29 * @param name
30 * the field name
31 * @return the long value
32 */
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());
38 }
39 return NonNullUtils.checkNotNull((Integer) value);
40 }
41
42 /**
43 * Get long field
44 *
45 * @param event
46 * the event
47 * @param name
48 * the field name
49 * @return the long value
50 */
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());
54 }
55
56 /**
57 * Get string field
58 *
59 * @param event
60 * the event
61 * @param name
62 * the field name
63 * @return the string value
64 */
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());
68 }
69
70 /**
71 * Get float field
72 *
73 * @param event
74 * the event
75 * @param name
76 * the field name
77 * @return the float value
78 */
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());
82 }
83
84 /**
85 * Get string field with default value
86 *
87 * @param event
88 * the event
89 * @param name
90 * the field name
91 * @param def
92 * the default value to return if the field does not exists
93 * @return the long value
94 */
95 public static String getOrDefault(ITmfEvent event, String name, String def) {
96 ITmfEventField field = event.getContent().getField(name);
97 if (field == null) {
98 return def;
99 }
100 return NonNullUtils.checkNotNull((String) field.getValue());
101 }
102 }
This page took 0.032783 seconds and 5 git commands to generate.