Package de.timefinder.data.algo

Examples of de.timefinder.data.algo.Constraint


    public Collection readConstraints(Element constrElement) {
        List<Constraint> res = new ArrayList();
        for (Object obj : constrElement.elements()) {
            Element element = (Element) obj;
            Constraint constraint = null;

            if (RasterConstraint.class.getSimpleName().equals(element.getName())) {
                BitSet bs = getResult(obj, BitSet.class, element);
                int length = Integer.parseInt(element.attributeValue("length"));
                constraint = new RasterConstraint(new WeekRasterImpl(
                        new BitRasterImpl(bs, length)));

            } else if (EventOrderConstraint.class.getSimpleName().equals(element.getName())) {
                UnsupportedOperationException excFirstEl = new UnsupportedOperationException(
                        "First element in eventOrderConstraint must be the event!" + element.getPath());
                for (Object eocObj : element.elements()) {
                    Element eocEl = (Element) eocObj;
                    if ("event".equals(eocEl.getName())) {
                        Event ev = getObject(getRef(eocEl), Event.class);
                        constraint = new EventOrderConstraint(ev);
                    } else if ("beforeEvent".equals(eocEl.getName())) {
                        if (constraint == null)
                            throw excFirstEl;
                        Event ev = getObject(getRef(eocEl), Event.class);
                        ((EventOrderConstraint) constraint).addBefore(ev);
                    } else if ("followsEvent".equals(eocEl.getName())) {
                        if (constraint == null)
                            throw excFirstEl;
                        Event ev = getObject(getRef(eocEl), Event.class);
                        ((EventOrderConstraint) constraint).addFollow(ev);
                    } else
                        throw new UnsupportedOperationException("Element not supported in eventOrderConstraint:"
                                + eocEl.getPath());
                }
            } else if (PersonITCRasterConstraint.class.getSimpleName().equals(element.getName())) {
                Person p = getObject(getRef(element.element("person")), Person.class);
                constraint = new PersonITCRasterConstraint(p, settings);

            } else if (MinGapsConstraint.class.getSimpleName().equals(element.getName())) {
                constraint = new MinGapsConstraint(settings,
                        readCollection(element, Event.class));
                ((MinGapsConstraint) constraint).setCountEarly(
                        Boolean.parseBoolean(element.attributeValue("countEarly")));

            } else if (DifferentDayConstraint.class.getSimpleName().equals(element.getName())) {
                constraint = new DifferentDayConstraint(settings,
                        readCollection(element, Event.class));

            } else
                throw new UnsupportedOperationException("Constraint not supported:" + element.getName());

            if (constraint == null)
                throw new IllegalStateException("Couldn't find a constraint in path:" + element.getPath());
            float weight = Float.parseFloat(element.attributeValue("weight"));
            constraint.setWeight(weight);
            res.add(constraint);
        }
        return res;
    }
View Full Code Here

TOP

Related Classes of de.timefinder.data.algo.Constraint

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.