1 /*******************************************************************************
2 * Copyright (c) 2011, 2013 Ericsson, Ecole Polytechnique de Montreal and others
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
9 * Contributors: Matthew Khouzam - Initial API and implementation
10 * Contributors: Simon Marchi - Initial API and implementation
11 *******************************************************************************/
13 package org
.eclipse
.linuxtools
.ctf
.core
.event
.types
;
15 import java
.util
.List
;
17 import org
.eclipse
.jdt
.annotation
.NonNull
;
18 import org
.eclipse
.linuxtools
.ctf
.core
.event
.scope
.IDefinitionScope
;
20 import com
.google
.common
.base
.Joiner
;
21 import com
.google
.common
.collect
.ImmutableList
;
24 * A CTF sequence definition (a fixed-size array).
26 * An array where the size is fixed but declared in the trace, unlike array
27 * where it is declared with a literal
30 * @author Matthew Khouzam
31 * @author Simon Marchi
33 public final class SequenceDefinition
extends Definition
{
35 // TODO: investigate merging with arraydefinition
37 // ------------------------------------------------------------------------
39 // ------------------------------------------------------------------------
41 private final ImmutableList
<Definition
> fDefinitions
;
43 // ------------------------------------------------------------------------
45 // ------------------------------------------------------------------------
51 * the parent declaration
52 * @param definitionScope
60 public SequenceDefinition(@NonNull SequenceDeclaration declaration
, IDefinitionScope definitionScope
, @NonNull String fieldName
, List
<Definition
> definitions
) {
61 super(declaration
, definitionScope
, fieldName
);
62 fDefinitions
= ImmutableList
.copyOf(definitions
);
65 // ------------------------------------------------------------------------
66 // Getters/Setters/Predicates
67 // ------------------------------------------------------------------------
70 public SequenceDeclaration
getDeclaration() {
71 return (SequenceDeclaration
) super.getDeclaration();
75 * The length of the sequence in number of elements so a sequence of 5
76 * GIANT_rediculous_long_ints is the same as a sequence of 5 bits. (5)
78 * @return the length of the sequence
80 public int getLength() {
81 return fDefinitions
.size();
85 * Get the element at i
88 * the index (cannot be negative)
89 * @return The element at I, if I > length, null, if I < 0, the method
90 * throws an out of bounds exception
92 public Definition
getElem(int i
) {
93 if (i
> fDefinitions
.size()) {
96 return fDefinitions
.get(i
);
99 // ------------------------------------------------------------------------
101 // ------------------------------------------------------------------------
104 public String
toString() {
105 StringBuilder b
= new StringBuilder();
107 if (getDeclaration().isString()) {
108 for (Definition def
: fDefinitions
) {
109 IntegerDefinition character
= (IntegerDefinition
) def
;
111 if (character
.getValue() == 0) {
115 b
.append(character
.toString());
119 Joiner joiner
= Joiner
.on(", ").skipNulls(); //$NON-NLS-1$
120 b
.append(joiner
.join(fDefinitions
));