Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 2a408e0cdfad3b6c9afaef7c40db870b76f55217 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
/*******************************************************************************
 * Copyright (c) 2018 École Polytechnique de Montréal
 *
 * All rights reserved. This program and the accompanying materials are
 * made available under the terms of the Eclipse Public License v1.0 which
 * accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *******************************************************************************/

package org.eclipse.tracecompass.incubator.callstack.core.instrumented;

import org.eclipse.jdt.annotation.Nullable;
import org.eclipse.tracecompass.incubator.callstack.core.flamechart.CallStack;

import com.google.common.base.Objects;

/**
 * A class that associates a callstack with a depth, to abstract the state
 * system accesses.
 *
 * @author Geneviève Bastien
 */
public class CallStackDepth {

    private final CallStack fCallstack;
    private final int fDepth;

    /**
     * Constructor. The caller must make sure that the callstack has the requested
     * depth.
     *
     * @param callstack
     *            The callstack
     * @param depth
     *            The depth of the callstack
     */
    public CallStackDepth(CallStack callstack, int depth) {
        fCallstack = callstack;
        fDepth = depth;
    }

    /**
     * Get the quark corresponding to this callstack depth
     *
     * @return The quark at this depth
     */
    public int getQuark() {
        return fCallstack.getQuarkAtDepth(fDepth);
    }

    /**
     * Get the callstack corresponding to this callstack depth
     *
     * @return The callstack
     */
    public CallStack getCallStack() {
        return fCallstack;
    }

    @Override
    public int hashCode() {
        // Compare with the actual callstack object, as the callstack's own hash may
        // change as the callstack is built. Here, we are looking for the same object,
        // no matter its content
        return Objects.hashCode(System.identityHashCode(fCallstack), fDepth);
    }

    @Override
    public boolean equals(@Nullable Object obj) {
        if (!(obj instanceof CallStackDepth)) {
            return false;
        }
        CallStackDepth csd = (CallStackDepth) obj;
        // Compare with the actual callstack object, as the callstack's own hash may
        // change as the callstack is built. Here, we are looking for the same object,
        // no matter its content
        return Objects.equal(System.identityHashCode(fCallstack), System.identityHashCode(csd.fCallstack)) && (fDepth == csd.fDepth);
    }

    @Override
    public String toString() {
        return fCallstack + " at depth " + fDepth; //$NON-NLS-1$
    }

}

Back to the top