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

org.sahagin.share.runresults.LineScreenCapture Maven / Gradle / Ivy

There is a newer version: 0.10.1
Show newest version
package org.sahagin.share.runresults;

import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.sahagin.share.yaml.YamlUtils;
import org.sahagin.share.yaml.YamlConvertException;
import org.sahagin.share.yaml.YamlConvertible;

public class LineScreenCapture implements YamlConvertible {
    // should use absolute path
    private File path;
    // head element means stack top
    private List stackLines = new ArrayList(16);

    public File getPath() {
        return path;
    }

    public void setPath(File path) {
        this.path = path;
    }

    public List getStackLines() {
        return stackLines;
    }

    public void addStackLine(StackLine stackLine) {
        stackLines.add(stackLine);
    }

    public void addAllStackLines(List stackLines) {
        for (StackLine stackLine : stackLines) {
            addStackLine(stackLine);
        }
    }

    // check if stack line for this instance matches targetStackLines
    public boolean matchesStackLines(List targetStackLines) {
        if (targetStackLines.size() != getStackLines().size()) {
            return false;
        }
        for (int i = 0; i < targetStackLines.size(); i++) {
            StackLine targetLine = targetStackLines.get(i);
            StackLine line = getStackLines().get(i);
            if (!targetLine.getMethod().getKey().equals(line.getMethod().getKey())) {
                return false;
            }
            if (targetLine.getCodeBodyIndex() != line.getCodeBodyIndex()) {
                return false;
            }
        }
        return true;
    }

    @Override
    public Map toYamlObject() {
        Map result = new HashMap(2);
        result.put("path", path.getPath());
        result.put("stackLines", YamlUtils.toYamlObjectList(stackLines));
        return result;
    }

    @Override
    public void fromYamlObject(Map yamlObject)
            throws YamlConvertException {
        path = new File(YamlUtils.getStrValue(yamlObject, "path"));
        List> stackLinesYamlObj
        = YamlUtils.getYamlObjectListValue(yamlObject, "stackLines");
        stackLines = new ArrayList(stackLinesYamlObj.size());
        for (Map stackLineYamlObj : stackLinesYamlObj) {
            StackLine stackLine = new StackLine();
            stackLine.fromYamlObject(stackLineYamlObj);
            stackLines.add(stackLine);
        }
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy