Fix some null warnings
[deliverable/tracecompass.git] / ctf / org.eclipse.tracecompass.ctf.core / src / org / eclipse / tracecompass / internal / ctf / core / event / types / composite / EventHeaderDefinition.java
CommitLineData
6c7592e1
MK
1/*******************************************************************************
2 * Copyright (c) 2014 Ericsson
3 *
4 * All rights reserved. This program and the accompanying materials are made
5 * 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
11 *******************************************************************************/
12
f357bcd4 13package org.eclipse.tracecompass.internal.ctf.core.event.types.composite;
6c7592e1
MK
14
15import java.util.List;
16
17import org.eclipse.jdt.annotation.NonNull;
fbe6fa6f 18import org.eclipse.tracecompass.ctf.core.event.scope.ILexicalScope;
f357bcd4
AM
19import org.eclipse.tracecompass.ctf.core.event.types.Declaration;
20import org.eclipse.tracecompass.ctf.core.event.types.Definition;
21import org.eclipse.tracecompass.ctf.core.event.types.ICompositeDefinition;
22import org.eclipse.tracecompass.ctf.core.event.types.IEventHeaderDeclaration;
23import org.eclipse.tracecompass.ctf.core.event.types.IntegerDeclaration;
24import org.eclipse.tracecompass.ctf.core.event.types.IntegerDefinition;
6c7592e1
MK
25
26import com.google.common.collect.ImmutableList;
27
28/**
29 * An event header definition, as shown in the example of the CTF spec examples
30 * section 6.1.1
31 *
32 * @author Matthew Khouzam
33 */
34public final class EventHeaderDefinition extends Definition implements ICompositeDefinition {
35
aa353506 36 private static final @NonNull List<String> FIELD_NAMES = ImmutableList.of(
6c7592e1
MK
37 IEventHeaderDeclaration.ID,
38 IEventHeaderDeclaration.TIMESTAMP
39 );
40
41 private final int fId;
42 private final long fTimestamp;
43 private final int fTimestampLength;
44
45 /**
46 * Event header defintion
47 *
48 * @param id
49 * the event id
50 * @param timestamp
51 * the timestamp
52 * @param eventHeaderDecl
53 * The declaration of this defintion
54 * @param timestampLength
55 * the number of bits valid in the timestamp
56 */
57 public EventHeaderDefinition(@NonNull Declaration eventHeaderDecl, int id, long timestamp, int timestampLength) {
fbe6fa6f 58 super(eventHeaderDecl, null, ILexicalScope.EVENT_HEADER.getPath(), ILexicalScope.EVENT_HEADER);
6c7592e1
MK
59 fId = id;
60 fTimestamp = timestamp;
61 fTimestampLength = timestampLength;
62 }
63
64 /**
65 * Gets the timestamp declaration
66 *
67 * @return the timestamp declaration
68 */
69 public int getTimestampLength() {
70 return fTimestampLength;
71 }
72
73 /**
74 * Get the event id
75 *
76 * @return the event id
77 */
78 public int getId() {
79 return fId;
80 }
81
82 /**
83 * Get the timestamp
84 *
85 * @return the timestamp
86 */
87 public long getTimestamp() {
88 return fTimestamp;
89 }
90
91 @Override
92 public Definition getDefinition(String fieldName) {
93 if (fieldName.equals(IEventHeaderDeclaration.ID)) {
94 return new IntegerDefinition(IntegerDeclaration.INT_32B_DECL, null, IEventHeaderDeclaration.ID, getId());
95 } else if (fieldName.equals(IEventHeaderDeclaration.TIMESTAMP)) {
96 return new IntegerDefinition(IntegerDeclaration.INT_64B_DECL, null, IEventHeaderDeclaration.TIMESTAMP, getTimestamp());
97 }
98 return null;
99 }
100
101 @Override
aa353506 102 public @NonNull List<String> getFieldNames() {
6c7592e1
MK
103 return FIELD_NAMES;
104 }
105}
This page took 0.058864 seconds and 5 git commands to generate.