Package eu.planets_project.pp.plato.model.tree

Examples of eu.planets_project.pp.plato.model.tree.Leaf


    private PositiveIntegerScale posInt = new PositiveIntegerScale();
    private PositiveFloatScale posFloat = new PositiveFloatScale();
   
    @Test
    public void testScaleBooleanValue(){
        Leaf leaf = new Leaf();
        leaf.changeScale(booleanScale);
        // test as parent Scale - this is the way it is used within the application
        Scale scale = leaf.getScale();
        assert("Yes/No".equals(((BooleanScale)scale).getRestriction()));
        ((RestrictedScale)scale).setRestriction("meine/eigene");
        assert("Yes/No".equals(((RestrictedScale)scale).getRestriction()));
        Scale cloned = scale.clone();
        assert(cloned instanceof BooleanScale);
View Full Code Here


        assert("Yes/No".equals(((RestrictedScale)cloned).getRestriction()));
    }
   
    @Test
    public void testScaleIntRangeValue(){
        Leaf leaf = new Leaf();
        leaf.changeScale(intRangeScale);
        Scale scale = leaf.getScale();
        assert("0/5".equals(((RestrictedScale)scale).getRestriction()));
        ((RestrictedScale)scale).setRestriction("-5/-1");
        assert("-5/-1".equals(((RestrictedScale)scale).getRestriction()));
        ((RestrictedScale)scale).setRestriction("aa/bbb");
        assert("-5/-1".equals(((RestrictedScale)scale).getRestriction()));
View Full Code Here

        assert("mm".equals(cloned.getUnit()));
    }
   
    @Test
    public void testChangeScaleType(){
        Leaf leaf = new Leaf();
        leaf.changeScale(booleanScale);
        leaf.changeScale(intRangeScale);
        Scale scale = leaf.getScale();
       
        assert(scale instanceof IntRangeScale);
        assert("0/5".equals(((RestrictedScale)scale).getRestriction()));
       
        leaf.changeScale(yanScale);
        scale = leaf.getScale();
        assert(scale instanceof YanScale);
        assert("Yes/Acceptable/No".equals(((RestrictedScale)scale).getRestriction()));
        assert("Yes/Acceptable/No".equals(((OrdinalScale)scale).getRestriction()));
        assert("Yes/Acceptable/No".equals(((YanScale)scale).getRestriction()));       
       
View Full Code Here

        Node childNode = new Node();
        childNode.setName("Image properties");
        rootN.addChild(childNode);

        Leaf leafWithUnit = new Leaf();
        leafWithUnit.setName("Amount of Pixel");
        leafWithUnit.changeScale(new PositiveIntegerScale());
        leafWithUnit.getScale().setUnit("px");
        childNode.addChild(leafWithUnit);

        Leaf ordinalLeaf = new Leaf();
        ordinalLeaf.setName("Karma");
        OrdinalScale ordinalScale = new OrdinalScale();
        ordinalScale.setRestriction("Good/Bad/Evil");
        ordinalLeaf.changeScale(ordinalScale);
        rootN.addChild(ordinalLeaf);

        Leaf numericLeaf = new Leaf();
        numericLeaf.setName("Filesize (in Relation to Original)");
        numericLeaf.changeScale(new PositiveFloatScale());
        numericLeaf.getScale().setUnit("MB");
        rootN.addChild(numericLeaf);

        Leaf singleLeaf = new Leaf();
        singleLeaf.setName("A Single-Leaf");
        singleLeaf.changeScale(new PositiveFloatScale());
        singleLeaf.getScale().setUnit("tbd");
        singleLeaf.setSingle(true);
        rootN.addChild(singleLeaf);

        Leaf restrictedLeaf = new Leaf();
        restrictedLeaf.setName("IntRange 0-10");
        IntRangeScale range = new IntRangeScale();
        range.setLowerBound(0);
        range.setUpperBound(10);
        restrictedLeaf.changeScale(range);
        rootN.addChild(restrictedLeaf);

        q.getTree().setRoot(rootN);

        q.getTree().initValues(q.getAlternativesDefinition().getAlternatives(),
                q.getSampleRecordsDefinition().getRecords().size());


        int j = 3;
        int alternativeIndex = 0;
        for (Alternative alt : q.getAlternativesDefinition().getAlternatives()) {

            double[] singleLeafValues = { 3.2, 5.2 };
            int[][] leafWithUnitValues = { { 1024, 2048 }, { 2048, 2048 } };
            int[][] ordinalValues = { { 0, 1 }, { 2, 1 } };
            double[][] numericValues = { { 6500.32, 7312, 28 },
                    { 8212.65, 7921.235 } };
            int[][] restrictedValues = { { 8, 5 }, { 3, 7 } };
            ((PositiveFloatValue) singleLeaf.getValueMap().get(alt.getName())
                    .getValue(0)).setValue(singleLeafValues[alternativeIndex]);

            List<String> ordinalOptions = ((OrdinalScale) ordinalLeaf
                    .getScale()).getList();

            for (int i = 0; i < q.getSampleRecordsDefinition().getRecords()
                    .size(); i++) {
                ((PositiveIntegerValue) leafWithUnit.getValueMap().get(
                        alt.getName()).getValue(i))
                        .setValue(leafWithUnitValues[alternativeIndex][i]);
                ((OrdinalValue) ordinalLeaf.getValueMap().get(alt.getName())
                        .getValue(i)).setValue(ordinalOptions
                        .get(ordinalValues[alternativeIndex][i]));
                ((PositiveFloatValue) numericLeaf.getValueMap().get(
                        alt.getName()).getValue(i))
                        .setValue(numericValues[alternativeIndex][i]);
                ((IntRangeValue) restrictedLeaf.getValueMap()
                        .get(alt.getName()).getValue(i))
                        .setValue(restrictedValues[alternativeIndex][i]);
            }
/*
            NumericTransformer nt = (NumericTransformer) singleLeaf
View Full Code Here

public class NodeTester {
   
    @Test
    public void isCompletelySpecified(){
        Node node = new Node();
        Leaf leaf = new Leaf();
        leaf.setName("Name");
        node.addChild(leaf);
        node.addChild(leaf);
        Leaf leaf2 = new Leaf();
        leaf2.setName("Name2");
        node.addChild(leaf2);
        node.addChild(leaf2);
        List<String> nodelist = new ArrayList<String>();
        System.out.println(node.getChildren().size());
        node.isCompletelySpecified(nodelist);
View Full Code Here

     */
    private void addSubTree(TreeNode data, Element xmlRoot) {
        if (data.isLeaf()) {
            Element leaf = xmlRoot.addElement("leaf");
            addNodeAttributes(data, leaf);
            Leaf l = (Leaf) data;
            leaf.addElement("aggregationMode")
            .addAttribute("value", l.getAggregationMode().name());

            String typename= null;
            /*
             * Scale:
             * A special element is created, depending on the type of the scale
             */
            Scale s = l.getScale();

            if (s != null) {
                typename = deriveElementname(s.getClass());


                addScale(s, leaf);

                // Transformer
                if (l.getTransformer() != null) {
                    Element transformer = leaf.addElement(deriveElementname(l.getTransformer().getClass()));

                    if (l.getTransformer() instanceof OrdinalTransformer) {

                        Map<String,TargetValueObject> mapping = ((OrdinalTransformer) l.getTransformer()).getMapping();
                        Element mappings = transformer.addElement("mappings");
                        for (String ordinal : mapping.keySet()) {
                            mappings.addElement("mapping")
                            .addAttribute("ordinal", ordinal)
                            .addAttribute("target", floatFormatter.formatFloatPrecisly(mapping.get(ordinal).getValue()));
                        }
                    }
                    if (l.getTransformer() instanceof NumericTransformer) {
                        NumericTransformer nt = (NumericTransformer) l.getTransformer();
                        transformer.addElement("mode")
                                   .addAttribute("value", nt.getMode().name());
                        Element thresholds = transformer.addElement("thresholds");
                        thresholds.addElement("threshold1").setText(floatFormatter.formatFloatPrecisly(nt.getThreshold1()));
                        thresholds.addElement("threshold2").setText(floatFormatter.formatFloatPrecisly(nt.getThreshold2()));
                        thresholds.addElement("threshold3").setText(floatFormatter.formatFloatPrecisly(nt.getThreshold3()));
                        thresholds.addElement("threshold4").setText(floatFormatter.formatFloatPrecisly(nt.getThreshold4()));
                        thresholds.addElement("threshold5").setText(floatFormatter.formatFloatPrecisly(nt.getThreshold5()));
                       
                    }
                    addChangeLog(l.getTransformer().getChangeLog(), transformer);
                }
               
                if (l.getMeasurementInfo() != null) {
                    addMeasurementInfo(l.getMeasurementInfo(), leaf);
                }
               
                Element eval = leaf.addElement("evaluation");
                typename = typename.substring(0, typename.lastIndexOf("Scale"));
                /*
                 * keep in mind: there are only values of the considered alternatives in the map
                 */
                for (String a : l.getValueMap().keySet()) {
                    Element alt = eval.addElement("alternative");
                    alt.addAttribute("key", a);
                    addStringElement(alt, "comment", l.getValueMap().get(a).getComment());
                    for (Value v : l.getValueMap().get(a).getList()) {
                        /*
                         * A special element is created, depending on the type of the scale
                         */
                        Element valElement = alt.addElement(typename+"Result");
                        addStringElement(valElement, "value", v.toString());
View Full Code Here

        Element element = xmlElement.addElement("node");
        addFreemindAttributes(node, element);

        if (node.isLeaf()) {
            //add scale
            Leaf leaf = (Leaf) node;
            Scale scale = leaf.getScale();
            if (scale != null) {
                Element scaleElement = element.addElement("node");
                String restriction = "?";
               
                //restrictions: restrictedscale, ordinals -freestring
View Full Code Here

    @Test
    public void testExportImport() throws Exception{
        LibraryTree lib = new LibraryTree();
        lib.addMainRequirements();
        lib.getRoot().setDescription("This is a description");
        Leaf c = new Leaf();
        c.setName("ImageWidth");
        MeasurementInfo mInfo = new MeasurementInfo();
        mInfo.fromUri("xcl://imageWidth#equal");
        c.setMeasurementInfo(mInfo);
        ((LibraryRequirement)lib.getRoot().getChildren().get(0).getChildren().get(0)).addChild(c);
       
        LibraryExport export = new LibraryExport();
        File exported = new File ("test-data/lib_export.xml");
        export.exportToStream(lib, new FileOutputStream(exported));
View Full Code Here

       
        if (node instanceof LibraryRequirement) {
            Element req = parent.addElement("requirement");
            addRequirementProperties(req, (LibraryRequirement)node);
        } else {
            Leaf l = (Leaf) node;
            Element leaf = parent.addElement("criterion");
            addNodeAttributes(leaf, l);
           
            if (l.getMeasurementInfo().getUri() != null) {
                Element meas = leaf.addElement("measurementInfo");
                meas.addAttribute("uri", l.getMeasurementInfo().getUri());
            }
        }
       
    }
View Full Code Here

        if (hasLeaves && isLeaf()) {
            // i am a leaf, so create a Leaf.
            // this is called only if hasUnits == false, see below.
            // So we don't need to check that again.
            Leaf leaf = new Leaf();
            setNameAndWeight(leaf);
            setDescription(leaf);
            setMIU(leaf);
            return leaf;
        } else {
            // We start with assuming that I'm a Node
            TreeNode node =  new eu.planets_project.pp.plato.model.tree.Node();

            setNameAndWeight(node);
            setDescription(node);
            for (Node n : children) {
                if (hasLeaves && n.isLeaf()) {
                    // Case 1: we don't have units in the tree, so n is in fact a LEAF
                    // and I am a NODE as assumed above
                    if (!hasUnits) {
                        Leaf leaf = new Leaf();
                        n.setNameAndWeight(leaf);
                        n.setDescription(leaf);
                        n.setMIU(leaf);
                        ((eu.planets_project.pp.plato.model.tree.Node)node).addChild(leaf);
                    } else {
                        // Case 2: we have units, so n is the SCALE of myself
                        // - but this means that I AM a LEAF
                        // and that we can finish recursion
                        node = new Leaf();
                        setNameAndWeight(node);
                        setDescription(node);
                        Leaf leaf = (Leaf) node;
                        leaf.changeScale(n.createScale());
                        setMIU(leaf);
                       
                        return leaf; // == node
                    }
                } else {
View Full Code Here

TOP

Related Classes of eu.planets_project.pp.plato.model.tree.Leaf

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.