Use the NonNull utility methods where we can
[deliverable/tracecompass.git] / org.eclipse.tracecompass.ctf.core / src / org / eclipse / tracecompass / internal / ctf / core / event / types / ArrayDefinition.java
CommitLineData
7b4f13e6
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;
7b4f13e6 14
5db5a3a4
AM
15import static org.eclipse.tracecompass.common.core.NonNullUtils.checkNotNull;
16
7b4f13e6
MK
17import java.util.List;
18
7b4f13e6
MK
19import org.eclipse.jdt.annotation.NonNullByDefault;
20import org.eclipse.jdt.annotation.Nullable;
f357bcd4
AM
21import org.eclipse.tracecompass.ctf.core.event.scope.IDefinitionScope;
22import org.eclipse.tracecompass.ctf.core.event.types.AbstractArrayDefinition;
23import org.eclipse.tracecompass.ctf.core.event.types.CompoundDeclaration;
24import org.eclipse.tracecompass.ctf.core.event.types.Definition;
7b4f13e6
MK
25
26import com.google.common.base.Joiner;
27import com.google.common.collect.ImmutableList;
28
29/**
30 * A CTF array definition
31 *
32 * Arrays are fixed-length. Their length is declared in the type declaration
33 * within the meta-data. They contain an array of "inner type" elements, which
34 * can refer to any type not containing the type of the array being declared (no
35 * circular dependency). The length is the number of elements in an array.
36 *
37 * @version 1.0
38 * @author Matthew Khouzam
39 * @since 3.1
40 */
41@NonNullByDefault
42public final class ArrayDefinition extends AbstractArrayDefinition {
43
44 // ------------------------------------------------------------------------
45 // Attributes
46 // ------------------------------------------------------------------------
47
5db5a3a4 48 private final List<Definition> fDefinitions;
7b4f13e6
MK
49
50 // ------------------------------------------------------------------------
51 // Constructors
52 // ------------------------------------------------------------------------
53
54 /**
55 * Constructor
56 *
57 * @param declaration
58 * the parent declaration
59 * @param definitionScope
60 * the parent scope
61 * @param fieldName
62 * the field name
63 * @param definitions
64 * the content of the array
65 */
66 public ArrayDefinition(CompoundDeclaration declaration,
67 @Nullable IDefinitionScope definitionScope,
68 String fieldName,
69 List<Definition> definitions) {
70 super(declaration, definitionScope, fieldName);
5db5a3a4 71 fDefinitions = checkNotNull(ImmutableList.copyOf(definitions));
7b4f13e6
MK
72 }
73
74 // ------------------------------------------------------------------------
75 // Getters/Setters/Predicates
76 // ------------------------------------------------------------------------
77
78 @Override
79 public List<Definition> getDefinitions() {
80 return fDefinitions;
81 }
82
83 /**
84 * Get the the number of elements in the array
85 *
86 * @return how many elements in the array
87 */
88 public int getLength() {
89 return fDefinitions.size();
90 }
91
92 // ------------------------------------------------------------------------
93 // Operations
94 // ------------------------------------------------------------------------
95
96 @Override
97 public String toString() {
98 StringBuilder b = new StringBuilder();
99 b.append('[');
100 Joiner joiner = Joiner.on(", ").skipNulls(); //$NON-NLS-1$
101 b.append(joiner.join(fDefinitions));
102 b.append(']');
5db5a3a4 103 return checkNotNull(b.toString());
7b4f13e6
MK
104 }
105}
This page took 0.039105 seconds and 5 git commands to generate.