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.tracecompasss.statesystem.core.tests.stubs.backend;
12 import static org.eclipse.tracecompass.common.core.NonNullUtils.checkNotNull;
14 import java.io.IOException;
15 import java.util.List;
17 import org.eclipse.tracecompass.internal.statesystem.core.backend.historytree.HTConfig;
18 import org.eclipse.tracecompass.internal.statesystem.core.backend.historytree.HTNode;
19 import org.eclipse.tracecompass.internal.statesystem.core.backend.historytree.HistoryTree;
21 import com.google.common.collect.Iterables;
24 * Stub class to unit test the history tree. You can set the size of the
25 * interval section before using the tree, in order to fine-tune the test.
27 * Note to developers: This tree is not meant to be used with a backend. It just
28 * exposes some info from the history tree.
30 * @author Geneviève Bastien
32 public class HistoryTreeStub extends HistoryTree {
35 * Constructor for this history tree stub
38 * The config to use for this History Tree.
40 * If an error happens trying to open/write to the file
41 * specified in the config
43 public HistoryTreeStub(HTConfig conf) throws IOException {
48 * Get the latest leaf of the tree
50 * @return The current leaf node of the tree
52 public HTNode getLatestLeaf() {
53 List<HTNode> latest = getLatestBranch();
54 return checkNotNull(Iterables.getLast(latest));
58 * Get the node from the latest branch at a given position, 0 being the root
59 * and <size of latest branch - 1> being a leaf node.
62 * The position at which to return the node
63 * @return The node at position pos
65 public HTNode getNodeAt(int pos) {
66 List<HTNode> latest = getLatestBranch();
67 return checkNotNull(latest.get(pos));