75c59294a4d740c29cba55543d94263469692c07
[deliverable/tracecompass.git] / statesystem / org.eclipse.tracecompass.statesystem.core.tests / stubs / org / eclipse / tracecompasss / statesystem / core / tests / stubs / backend / HistoryTreeStub.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.tracecompasss.statesystem.core.tests.stubs.backend;
11
12 import static org.eclipse.tracecompass.common.core.NonNullUtils.checkNotNull;
13
14 import java.io.IOException;
15 import java.util.List;
16
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;
20
21 import com.google.common.collect.Iterables;
22
23 /**
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.
26 *
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.
29 *
30 * @author Geneviève Bastien
31 */
32 public class HistoryTreeStub extends HistoryTree {
33
34 /**
35 * Constructor for this history tree stub
36 *
37 * @param conf
38 * The config to use for this History Tree.
39 * @throws IOException
40 * If an error happens trying to open/write to the file
41 * specified in the config
42 */
43 public HistoryTreeStub(HTConfig conf) throws IOException {
44 super(conf);
45 }
46
47 /**
48 * Get the latest leaf of the tree
49 *
50 * @return The current leaf node of the tree
51 */
52 public HTNode getLatestLeaf() {
53 List<HTNode> latest = getLatestBranch();
54 return checkNotNull(Iterables.getLast(latest));
55 }
56
57 /**
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.
60 *
61 * @param pos
62 * The position at which to return the node
63 * @return The node at position pos
64 */
65 public HTNode getNodeAt(int pos) {
66 List<HTNode> latest = getLatestBranch();
67 return checkNotNull(latest.get(pos));
68 }
69
70 }
This page took 0.032574 seconds and 4 git commands to generate.