Package de.timefinder.algo.util

Source Code of de.timefinder.algo.util.TimeFinder2Tester

/*
*  Copyright 2009 Peter Karich, peat_hal ‘at’ users ‘dot’ sourceforge ‘dot’ net.
*
*  Licensed under the Apache License, Version 2.0 (the "License");
*  you may not use this file except in compliance with the License.
*  You may obtain a copy of the License at
*
*       http://www.apache.org/licenses/LICENSE-2.0
*
*  Unless required by applicable law or agreed to in writing, software
*  distributed under the License is distributed on an "AS IS" BASIS,
*  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*  See the License for the specific language governing permissions and
*  limitations under the License.
*  under the License.
*/
package de.timefinder.algo.util;

import de.timefinder.data.algo.DataPoolSettings;
import de.timefinder.algo.constraint.RasterConstraint;
import de.timefinder.data.Event;
import de.timefinder.data.Resource;
import de.timefinder.data.TimeFinderTester;
import de.timefinder.data.algo.Assignment;
import de.timefinder.data.util.ResourceForTest;
import java.io.File;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.Set;
import javolution.util.FastMap;
import javolution.util.FastSet;
import org.apache.log4j.PropertyConfigurator;

/**
* @author Peter Karich, peat_hal ‘at’ users ‘dot’ sourceforge ‘dot’ net
*/
public class TimeFinder2Tester extends TimeFinderTester {

    protected DataPoolSettings settings;

    public void setupLog() {
        try {
            PropertyConfigurator.configure(System.getProperty("user.home") + File.separator
                    + ".timefinder/log4j.properties");
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }

    @Override
    public void setUp() {
        super.setUp();
        setupLog();
        settings = new DataPoolSettings();
    }

    public RasterConstraint newRasterConstraint() {
        return new RasterConstraint(settings.createWeekRaster());
    }

    /**
     * transforms a List<List<Assignment>> into a map of Entry<Resource, List<Assignment>>
     */
    public Map<Resource, Set<Assignment>> newResources(List<Assignment>... resources) {
        Map<Resource, Set<Assignment>> result = FastMap.newInstance();
        for (List<Assignment> assignments : resources) {
            ResourceForTest res = new ResourceForTest();
            Set<Assignment> set = FastSet.newInstance();
            for (Assignment ass : assignments) {
                set.add(ass);
                res.getEvents().add(ass.getEvent());
            }
            result.put(res, set);
        }
        return result;
    }

    public Map<Event, Assignment> createTransformerMap(Collection<Event> input) {
        Map map = FastMap.newInstance();

        for (Event ev : input) {
            map.put(ev, new Assignment(ev, ev.getStart()));
        }
        return map;
    }
}
TOP

Related Classes of de.timefinder.algo.util.TimeFinder2Tester

TOP
Copyright © 2018 www.massapi.com. 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.