Skip to main content
aboutsummaryrefslogblamecommitdiffstats
blob: 2a408e0cdfad3b6c9afaef7c40db870b76f55217 (plain) (tree)




























































                                                                                  



                                                                                      







                                                  



                                                                                                                                     







                                                                
/*******************************************************************************
 * 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