001package org.intellimate.izou.sdk.frameworks.permanentSoundOutput.events;
002
003import org.intellimate.izou.identification.Identification;
004import org.intellimate.izou.sdk.events.CommonEvents;
005import org.intellimate.izou.sdk.events.Event;
006import org.intellimate.izou.sdk.frameworks.common.resources.SelectorResource;
007
008import java.util.ArrayList;
009import java.util.Arrays;
010import java.util.Optional;
011
012/**
013 * signals that every sound-output should stop
014 * @author LeanderK
015 * @version 1.0
016 */
017public class StopEvent extends Event {
018    //TODO merge with new Izou...built in
019    public static final String ID = "izou.sound.events.stop";
020    /**
021     * Creates a new Event Object
022     *
023     * @param source      the source of the Event, most likely a this reference.
024     * @throws IllegalArgumentException if one of the Arguments is null or empty
025     */
026    protected StopEvent(Identification source)
027            throws IllegalArgumentException {
028        super(CommonEvents.Type.RESPONSE_TYPE, source, new ArrayList<>(Arrays.asList(ID,
029                CommonEvents.Descriptors.STOP_DESCRIPTOR, CommonEvents.Descriptors.NOT_INTERRUPT)));
030    }
031
032    /**
033     * creates a new StopEvent
034     * @param source the caller
035     * @param target the target who should start playing
036     * @return the optional StartMusicRequest
037     */
038    public static Optional<StopEvent> createStopEvent(Identification source, Identification target) {
039        if (target == null || target.equals(source))
040            return Optional.empty();
041        try {
042            StopEvent stopRequest = new StopEvent(source);
043            stopRequest.addResource(new SelectorResource(source, target));
044            return Optional.of(stopRequest);
045        } catch (IllegalArgumentException e) {
046            return Optional.empty();
047        }
048    }
049
050    /**
051     * creates a new StopEvent
052     * @param source the caller
053     * @return the optional StartMusicRequest
054     */
055    public static Optional<StopEvent> createStopEvent(Identification source) {
056        try {
057            StopEvent stopRequest = new StopEvent(source);
058            return Optional.of(stopRequest);
059        } catch (IllegalArgumentException e) {
060            return Optional.empty();
061        }
062    }
063}