All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.eclipse.mat.parser.internal.snapshot.PathsFromGCRootsTreeBuilder Maven / Gradle / Ivy

The newest version!
/*******************************************************************************
 * Copyright (c) 2008 SAP AG.
 * 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
 *
 * Contributors:
 *    SAP AG - initial API and implementation
 *******************************************************************************/
package org.eclipse.mat.parser.internal.snapshot;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

import org.eclipse.mat.snapshot.PathsFromGCRootsTree;

public class PathsFromGCRootsTreeBuilder {
    private int ownId;
    private ArrayList objectIds = new ArrayList();
    private HashMap objectInboundReferers;

    public PathsFromGCRootsTreeBuilder(int ownId) {
        this.ownId = ownId;
        objectInboundReferers = new HashMap();
    }

    public HashMap getObjectReferers() {
        return objectInboundReferers;
    }

    public PathsFromGCRootsTree toPathsFromGCRootsTree() {
        HashMap data = new HashMap(objectInboundReferers
                .size());
        for (Map.Entry entry : objectInboundReferers.entrySet()) {
            data.put(entry.getKey(), entry.getValue().toPathsFromGCRootsTree());
        }
        int[] children = new int[objectIds.size()];
        for (int i = 0; i < children.length; i++) {
            children[i] = objectIds.get(i);
        }
        return new PathsFromGCRootsTree(ownId, data, children);
    }

    public int getOwnId() {
        return ownId;
    }

    public void addObjectReferer(PathsFromGCRootsTreeBuilder referer) {
        if (objectInboundReferers.put(referer.getOwnId(), referer) == null) {
            objectIds.add(referer.getOwnId());
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy