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

nl.hsac.fitnesse.slimcoverage.SlimScenarioUsagePer Maven / Gradle / Ivy

There is a newer version: 1.32.11
Show newest version
package nl.hsac.fitnesse.slimcoverage;

import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.atomic.AtomicInteger;

public class SlimScenarioUsagePer {
    private final String groupName;
    private final Map usage = new LinkedHashMap();
    private final List overriddenScenarios = new ArrayList();

    public SlimScenarioUsagePer(String groupName) {
        this.groupName = groupName;
    }

    public void addDefinition(String scenarioName) {
        if (usage.containsKey(scenarioName)) {
            overriddenScenarios.add(scenarioName);
        } else {
            addUsage(scenarioName, 0);
        }
    }

    public void addUsage(String scenarioName) {
        addUsage(scenarioName, 1);
    }

    public void addUsage(String scenarioName, Integer valueToAdd) {
        AtomicInteger currentValue = usage.get(scenarioName);
        if (currentValue == null) {
            currentValue = new AtomicInteger(0);
            usage.put(scenarioName, currentValue);
        }
        currentValue.getAndAdd(valueToAdd);
    }

    public Map getUsage() {
        Map result = new LinkedHashMap();
        for (Map.Entry entry : usage.entrySet()) {
            result.put(entry.getKey(), entry.getValue().intValue());
        }
        return result;
    }

    public List getOverriddenScenarios() {
        return overriddenScenarios;
    }

    public String toString() {
        return groupName + ": " + usage;
    }

    public String getGroupName() {
        return groupName;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy