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

com.atlassian.clover.instr.java.ContextTreeNode Maven / Gradle / Ivy

Go to download

Clover is an award winning code coverage and testing tool for Java and Groovy. It integrates easily with Maven, Ant, Grails, Eclipse and IntelliJ IDEA as well as with continuous integration servers such as Bamboo, Jenkins or Hudson. Note: before Clover 4.0 this artifact was named com.cenqua.clover:clover.

The newest version!
package com.atlassian.clover.instr.java;

import com.atlassian.clover.context.ContextSet;

/** Used to track and minimise context sets created  during instrumentation */
public class ContextTreeNode {
    private final ContextTreeNode parent;
    private final ContextSet context;
    private ContextTreeNode[] children;

    ContextTreeNode(ContextTreeNode parent, ContextSet context) {
        this.parent = parent;
        this.children = new ContextTreeNode[parent.children.length];
        this.context = context;
    }

    public ContextTreeNode(int childCount, ContextSet context) {
        this.parent = null;
        this.children = new ContextTreeNode[childCount];
        this.context = context;
    }

    public ContextTreeNode enterContext(int index) {
        if (index >= children.length) {
            ContextTreeNode[] children = new ContextTreeNode[this.children.length * 2];
            System.arraycopy(this.children, 0, children, 0, this.children.length);
        }
        ContextTreeNode child = children[index];
        if (child == null) {
            ContextSet context = new ContextSet(this.context);
            context = context.set(index);
            child = new ContextTreeNode(this, context);
            children[index] = child;
        }
        return child;
    }

    public ContextTreeNode exitContext() {
        return parent;
    }

    public ContextSet getContext() {
        return context;           
    }

    public int countSelfAndDescendants() {
        int count = 1;
        for (ContextTreeNode child : children) {
            if (child != null) {
                count += child.countSelfAndDescendants();
            }
        }
        return count;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy