001package org.intellimate.izou.sdk.events;
002
003import org.intellimate.izou.events.EventBehaviourControllerModel;
004import org.intellimate.izou.identification.Identification;
005
006import java.util.HashMap;
007import java.util.List;
008import java.util.function.Function;
009
010/**
011 * This class can control the Behaviour of the the Event, like which Output-Plugin should get the Event first.
012 */
013public class EventBehaviourController implements EventBehaviourControllerModel {
014
015    private Function<List<Identification>, HashMap<Integer, List<Identification>>> outputPluginBehaviour;
016
017    /**
018     * this method sets the controls for the Output-Plugin Behaviour.
019     * <p>
020     * Supply a Function, which controls the OutputPlugin-Behaviour. You can set Priorities.
021     * The output-plugin with the highest POSITIVE priority (in int) will be processed first. Negative priorities
022     * are processed last (so outputPlugins with no priorities will be processed in between positive and negative
023     * priorities)
024     *
025     * This function returns an HashMap, where the keys represent the associated Behaviour
026     * and the values the Identification;
027     * </p>
028     * @param outputPluginBehaviour all the registered outputPlugins
029     */
030    public void controlOutputPluginBehaviour(Function<List<Identification>,
031            HashMap<Integer, List<Identification>>> outputPluginBehaviour) {
032        this.outputPluginBehaviour = outputPluginBehaviour;
033    }
034
035    /**
036     * generates the data to control the Event
037     * @param identifications the Identifications of the OutputPlugins
038     * @return a HashMap, where the keys represent the associated Behaviour and the values the Identification;
039     */
040    @Override
041    public HashMap<Integer, List<Identification>> getOutputPluginBehaviour(List<Identification> identifications) {
042        if(outputPluginBehaviour == null) return new HashMap<>();
043        return outputPluginBehaviour.apply(identifications);
044    }
045}