Package eu.scape_project.planning.model

Examples of eu.scape_project.planning.model.Values


        em.persist(lStored);
        em.getTransaction().commit();

        lStored = em.find(Leaf.class, l.getId());
        for (Alternative a : alternatives) {
            Values values = lStored.getValues(a.getName());
            assertEquals(4, ((PositiveIntegerValue) values.getValue(0)).getValue());
            assertEquals(1, ((PositiveIntegerValue) values.getValue(1)).getValue());
        }
        lStored.initValues(alternatives, 5, true);
        for (Alternative a : alternatives) {
            for (int idx = 2; idx <= 4; idx++) {
                Value v = lStored.getValues(a.getName()).getList().get(idx);
                ((PositiveIntegerValue) v).setValue(idx+1);
            }
        }
        em.getTransaction().begin();
        em.persist(lStored);
        em.getTransaction().commit();

        em.close();
        // check order with new connection, this time don't recreate schema
        em = newConnection();
        assertNotNull(em);
        em.getTransaction().begin();
       
        lStored = em.find(Leaf.class, l.getId());
        for (Alternative a : alternatives) {
            Values values = lStored.getValues(a.getName());
            assertEquals(4, ((PositiveIntegerValue) values.getValue(0)).getValue());
            assertEquals(1, ((PositiveIntegerValue) values.getValue(1)).getValue());
            assertEquals(3, ((PositiveIntegerValue) values.getValue(2)).getValue());
            assertEquals(4, ((PositiveIntegerValue) values.getValue(3)).getValue());
            assertEquals(5, ((PositiveIntegerValue) values.getValue(4)).getValue());
       
       
        assertEquals("Removed values (orphans) should be automatically deleted", 15,
            ((Long)em.createQuery("select count(*) from Value").getSingleResult()).longValue());
       
View Full Code Here


        OrdinalValue yes = new OrdinalValue();
        yes.setValue("Y");
        OrdinalValue no = new OrdinalValue();
        no.setValue("N");

        Values valuesAlternative1 = new Values();
        Values valuesAlternative2 = new Values();
        valuesAlternative1.add(yes);
        valuesAlternative1.add(yes);
        valuesAlternative1.add(yes);
        valuesAlternative1.add(no);
        valuesAlternative2.add(no);
        valuesAlternative2.add(no);
        valuesAlternative2.add(no);
        valuesAlternative2.add(no);

        Map<String, Values> valueMap = new HashMap<String, Values>();
        valueMap.put("alt1", valuesAlternative1);
        valueMap.put("alt2", valuesAlternative2);
        leaf.setValueMap(valueMap);
View Full Code Here

        FloatValue v4 = new FloatValue();
        v4.setValue(4d);
        FloatValue v5 = new FloatValue();
        v5.setValue(5d);

        Values valuesAlternative1 = new Values();
        Values valuesAlternative2 = new Values();
        valuesAlternative1.add(v0);
        valuesAlternative1.add(v0);
        valuesAlternative1.add(v3);
        valuesAlternative1.add(v4);
        valuesAlternative1.add(v5);
        valuesAlternative2.add(v3);
        valuesAlternative2.add(v3);
        valuesAlternative2.add(v1);
        valuesAlternative2.add(v3);
        valuesAlternative2.add(v5);

        Map<String, Values> valueMap = new HashMap<String, Values>();
        valueMap.put("alt1", valuesAlternative1);
        valueMap.put("alt2", valuesAlternative2);
        leaf.setValueMap(valueMap);
View Full Code Here

    @Test
    public void testResetValues_Scale_Equals_Null() {
        Leaf l = new Leaf();
        Map<String, Values> map = new HashMap<String, Values>();
        map.put("test", new Values());
        l.setValueMap(map);
        Assert.assertTrue(l.getValueMap().size() == 1);
        l.resetValues(null);
        Assert.assertTrue(l.getValueMap().size() == 0);
    }
View Full Code Here

        alternatives.add(a);

        Map<String, Values> map = new HashMap<String, Values>();
        Value v1 = new IntegerValue();
        v1.setScale(new IntegerScale());
        Values values = new Values();
        values.add(v1);
        map.put("test", values);
        l.setValueMap(map);
        Assert.assertTrue(l.getValueMap().size() == 1);
        l.resetValues(alternatives);
        Assert.assertTrue(l.getValueMap().size() == 0);
View Full Code Here

        // - that leads to the orphan VALUE objects to be deleted from the
        // database.
        if (samplesToRemove.size() > 0) {
            for (Leaf l : plan.getTree().getRoot().getAllLeaves()) {
                for (Alternative a : plan.getAlternativesDefinition().getConsideredAlternatives()) {
                    Values v = l.getValues(a.getName());
                    if (v != null) {
                        em.persist(em.merge(v));
                    } else {
                        log.error("values is NULL: " + l.getName() + ", " + a.getName());
                    }
View Full Code Here

        Map<String, Values> map = new HashMap<String, Values>();
        Value v1 = new IntegerValue();
        Value v2 = new IntegerValue();
        Value v3 = new IntegerValue();
        v1.setScale(new IntegerScale());
        Values values = new Values();
        values.add(v1);
        values.add(v2);
        values.add(v3);
        map.put("test", values);
        l.setValueMap(map);
        Assert.assertTrue(l.getValueMap().get("test").size() == 3);
        l.removeValues(alternatives, 1);
        Assert.assertTrue(l.getValueMap().get("test").size() == 2);
View Full Code Here

        // alternatives.add(a);
        // a.setName("test");
        Map<String, Values> map = new HashMap<String, Values>();
        Value v1 = new IntegerValue();
        v1.setScale(new IntegerScale());
        Values values1 = new Values();
        values1.add(v1);
        map.put("test1", values1);
        Value v2 = new IntegerValue();
        v2.setScale(new IntegerScale());
        Values values2 = new Values();
        values2.add(v2);
        map.put("test2", values2);
        Value v3 = new IntegerValue();
        v3.setScale(new IntegerScale());
        Values values3 = new Values();
        values3.add(v3);
        map.put("test3", values3);
        l.setValueMap(map);
        l.removeLooseValues(list, 5);
        Map<String, Values> res = l.getValueMap();
        Assert.assertTrue(res.containsKey("test1"));
View Full Code Here

     *            the {@link Alternative} for which evaluation values shall be
     *            returned
     * @return {@link TargetValues}
     */
    public TargetValues transformValues(Alternative a) {
        Values v = valueMap.get(a.getName());
        if (transformer == null) {
            log.error("transformer is null!");
        }
        return transformer.transformValues(v);
    }
View Full Code Here

            valueMap.clear();
            return;
        }
        // Get the Values for each Alternative
        for (Alternative a : list) {
            Values values = valueMap.get(a.getName());
            if (values == null) {
                log.debug("values is null for alternative " + a.getName() + " in Leaf " + name);
                continue;
            }
            // Check value of each sample object for conformance with Scale -
            // if we find a changed scale, we reset everything.
            // It might be faster not to check ALL values, but this is safer.
            for (Value value : values.getList()) {
                // If the scale has changed, we reset all evaluation values of
                // this Alternative:
                // this may look strange, but it is OK that the scale of a value
                // is null.
                // If there have been values before, you change the scale and
                // then save - the linkage is lost
                // if (value.getScale() == null) {
                // LogFactory.getLog(Leaf.class).error("WHAT THE...?? no scale for value"+getName());
                // } else {
                if ((value.getScale() == null) || (!value.getScale().getClass().equals(scale.getClass()))) {
                    if (!a.isDiscarded()) { // for discarded alternatives,
                                            // that's ok.
                        log.debug("Leaf " + this.getName() + " Class: " + value.getClass() + " not like "
                            + scale.getClass() + ". RESETTING the valuemap now!");
                        valueMap.clear(); // reset all values
                        return;
                    }
                }
                // }
                // PLEASE NOTE- WRT ORDINAL RESTRICTIONS:
                // we do NOT reset values when the restriction has changed, such
                // as
                // the ordinal values or the boundaries.
                // Instead, those values that are still valid remain, the others
                // will be checked
                // and need to be corrected anyway in the evaluate step.
                // Should be nicer for the user. If we find out this leads to
                // validation problems
                // (which shouldnt be the case because the data types are valid
                // as long as the scale
                // doesnt change) then we will reset the values even if just the
                // restriction changes.
            }
            /*
             * maybe this leaf was set to single, reset all values
             */
            if (isSingle() && values.size() > 1) {
                valueMap.clear();
                return;
            }
        }
    }
View Full Code Here

TOP

Related Classes of eu.scape_project.planning.model.Values

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.