| 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 | @Override |
| 48 | public List<HTNode> getLatestBranch() { |
| 49 | return checkNotNull(super.getLatestBranch()); |
| 50 | } |
| 51 | |
| 52 | /** |
| 53 | * Get the latest leaf of the tree |
| 54 | * |
| 55 | * @return The current leaf node of the tree |
| 56 | */ |
| 57 | public HTNode getLatestLeaf() { |
| 58 | List<HTNode> latest = getLatestBranch(); |
| 59 | return checkNotNull(Iterables.getLast(latest)); |
| 60 | } |
| 61 | |
| 62 | /** |
| 63 | * Get the node from the latest branch at a given position, 0 being the root |
| 64 | * and <size of latest branch - 1> being a leaf node. |
| 65 | * |
| 66 | * @param pos |
| 67 | * The position at which to return the node |
| 68 | * @return The node at position pos |
| 69 | */ |
| 70 | public HTNode getNodeAt(int pos) { |
| 71 | List<HTNode> latest = getLatestBranch(); |
| 72 | return checkNotNull(latest.get(pos)); |
| 73 | } |
| 74 | |
| 75 | /** |
| 76 | * Get the depth of the tree |
| 77 | * |
| 78 | * @return The depth of the tree |
| 79 | */ |
| 80 | public int getDepth() { |
| 81 | return getLatestBranch().size(); |
| 82 | } |
| 83 | |
| 84 | } |