package be.iminds.ilabt.jfed.highlevel.tasks;

import be.iminds.ilabt.jfed.highlevel.controller.Task;

import java.util.HashMap;

/**
 * User: twalcari
 * Date: 6/16/2015
 * Time: 16:09
 */
public abstract class CacheableTaskFactory<S, T extends Task> {

    private final HashMap<S, T> cachedTasks = new HashMap<>();

    public synchronized T getTask(S input) {
        return cachedTasks.computeIfAbsent(input, this::createNewTask);
    }

    protected abstract T createNewTask(S input);


}
