ss.tests: Add unit test for intervals before start time
[deliverable/tracecompass.git] / statesystem / org.eclipse.tracecompass.statesystem.core.tests / stubs / org / eclipse / tracecompass / statesystem / core / tests / stubs / backend / HistoryTreeStub.java
CommitLineData
f3476b68
GB
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
5eb1b4b0 10package org.eclipse.tracecompass.statesystem.core.tests.stubs.backend;
f3476b68
GB
11
12import static org.eclipse.tracecompass.common.core.NonNullUtils.checkNotNull;
13
068641fa 14import java.io.File;
f3476b68
GB
15import java.io.IOException;
16import java.util.List;
17
18import org.eclipse.tracecompass.internal.statesystem.core.backend.historytree.HTConfig;
19import org.eclipse.tracecompass.internal.statesystem.core.backend.historytree.HTNode;
20import org.eclipse.tracecompass.internal.statesystem.core.backend.historytree.HistoryTree;
21
22import com.google.common.collect.Iterables;
23
24/**
25 * Stub class to unit test the history tree. You can set the size of the
26 * interval section before using the tree, in order to fine-tune the test.
27 *
28 * Note to developers: This tree is not meant to be used with a backend. It just
29 * exposes some info from the history tree.
30 *
31 * @author Geneviève Bastien
32 */
33public class HistoryTreeStub extends HistoryTree {
34
35 /**
36 * Constructor for this history tree stub
37 *
38 * @param conf
39 * The config to use for this History Tree.
40 * @throws IOException
41 * If an error happens trying to open/write to the file
42 * specified in the config
43 */
44 public HistoryTreeStub(HTConfig conf) throws IOException {
45 super(conf);
46 }
47
068641fa
GB
48 /**
49 * "Reader" constructor : instantiate a SHTree from an existing tree file on
50 * disk
51 *
52 * @param existingStateFile
53 * Path/filename of the history-file we are to open
54 * @param expProviderVersion
55 * The expected version of the state provider
56 * @throws IOException
57 * If an error happens reading the file
58 */
59 public HistoryTreeStub(File existingStateFile, int expProviderVersion) throws IOException {
60 super(existingStateFile, expProviderVersion);
61 }
62
b2ca67ca
PT
63 @Override
64 public List<HTNode> getLatestBranch() {
65 return checkNotNull(super.getLatestBranch());
66 }
67
f3476b68
GB
68 /**
69 * Get the latest leaf of the tree
70 *
71 * @return The current leaf node of the tree
72 */
73 public HTNode getLatestLeaf() {
74 List<HTNode> latest = getLatestBranch();
0e4f957e 75 return Iterables.getLast(latest);
f3476b68
GB
76 }
77
78 /**
79 * Get the node from the latest branch at a given position, 0 being the root
80 * and <size of latest branch - 1> being a leaf node.
81 *
82 * @param pos
83 * The position at which to return the node
84 * @return The node at position pos
85 */
86 public HTNode getNodeAt(int pos) {
87 List<HTNode> latest = getLatestBranch();
0e4f957e 88 return latest.get(pos);
f3476b68
GB
89 }
90
7c247a0f
GB
91 /**
92 * Get the depth of the tree
93 *
94 * @return The depth of the tree
95 */
96 public int getDepth() {
97 return getLatestBranch().size();
98 }
99
f3476b68 100}
This page took 0.037624 seconds and 5 git commands to generate.