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

org.sahagin.share.srctree.TestClassTable Maven / Gradle / Ivy

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

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

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

//class or interface
public class TestClassTable implements YamlConvertible {
    private List testClasses = new ArrayList<>(512);

    public List getTestClasses() {
        return testClasses;
    }

    public void addTestClass(TestClass testClass) {
        testClasses.add(testClass);
    }

    public boolean isEmpty() {
        return testClasses.isEmpty();
    }

    // returns null if not found
    public TestClass getByKey(String key) {
        if (key == null) {
            throw new NullPointerException();
        }
        for (TestClass testClass : testClasses) {
            if (key.equals(testClass.getKey())) {
                return testClass;
            }
        }
        return null;
    }

    public void sort() {
        Collections.sort(testClasses, new Comparator() {

            @Override
            public int compare(TestClass left, TestClass right) {
                return CommonUtils.compare(left.getKey(), right.getKey());
            }
        });
    }

    @Override
    public Map toYamlObject() {
        Map result = new HashMap<>(1);
        if (!isEmpty()) {
            result.put("classes", YamlUtils.toYamlObjectList(testClasses));
        }
        return result;
    }

    @Override
    public void fromYamlObject(Map yamlObject)
            throws YamlConvertException {
        List> testClassesYamlObj
        = YamlUtils.getYamlObjectListValue(yamlObject, "classes", true);
        testClasses = new ArrayList<>(testClassesYamlObj.size());
        for (Map testClassYamlObj : testClassesYamlObj) {
            TestClass testClass = TestClass.newInstanceFromYamlObject(testClassYamlObj);
            testClasses.add(testClass);
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy