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.system.sound.SoundIDs;
007
008import java.util.ArrayList;
009import java.util.Arrays;
010import java.util.Optional;
011
012/**
013 * this event indicates that the sound ended
014 * @author LeanderK
015 * @version 1.0
016 */
017public class EndedEvent extends Event {
018    public static final String ID = SoundIDs.EndedEvent.descriptor;
019    /**
020     * Creates a new Event Object
021     *
022     * @param source      the source of the Event, most likely a this reference.
023     * @throws IllegalArgumentException if one of the Arguments is null or empty
024     */
025    protected EndedEvent(Identification source)
026            throws IllegalArgumentException {
027        super(CommonEvents.Type.RESPONSE_TYPE, source, new ArrayList<>(Arrays.asList(ID,
028                CommonEvents.Descriptors.NOT_INTERRUPT)));
029    }
030
031    /**
032     * creates a new EndedEvent
033     * @param source the caller
034     * @return the optional StartMusicRequest
035     */
036    public static Optional<EndedEvent> createEndedEvent(Identification source) {
037        try {
038            EndedEvent stopRequest = new EndedEvent(source);
039            return Optional.of(stopRequest);
040        } catch (IllegalArgumentException e) {
041            return Optional.empty();
042        }
043    }
044}