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.Arrays;
009import java.util.Collections;
010import java.util.Optional;
011
012/**
013 * signals that an output started
014 * @author LeanderK
015 * @version 1.0
016 */
017public class StartEvent extends Event {
018    public static final String ID = SoundIDs.StartEvent.descriptor;
019    public static final String IS_USING_NON_JAVA_OUTPUT = SoundIDs.StartEvent.isUsingNonJava;
020
021    /**
022     * Creates a new Event Object
023     *
024     * @param source      the source of the Event, most likely a this reference.
025     * @throws IllegalArgumentException if one of the Arguments is null or empty
026     */
027    protected StartEvent(Identification source)
028            throws IllegalArgumentException {
029        super(CommonEvents.Type.RESPONSE_TYPE, source, Collections.singletonList(ID));
030    }
031
032    /**
033     * Creates a new Event Object
034     *
035     * @param source      the source of the Event, most likely a this reference.
036     * @param descriptor the descriptor to add (used for IS_USING_NON_JAVA_OUTPUT)
037     * @throws IllegalArgumentException if one of the Arguments is null or empty
038     */
039    protected StartEvent(Identification source, String descriptor)
040            throws IllegalArgumentException {
041        super(CommonEvents.Type.RESPONSE_TYPE, source, Arrays.asList(ID, descriptor));
042    }
043
044
045    /**
046     * creates a new StartEvent.
047     * Assumes the Output is using the java-sound output.
048     * @param source the caller
049     * @return the optional StartMusicRequest
050     */
051    public static Optional<StartEvent> createStartEvent(Identification source) {
052        try {
053            StartEvent startRequest = new StartEvent(source);
054            return Optional.of(startRequest);
055        } catch (IllegalArgumentException e) {
056            return Optional.empty();
057        }
058    }
059
060    /**
061     * creates a new StartEvent
062     * @param source the caller
063     * @param isUsingJava true if using java, false if not (and for example a C-library)
064     * @return the optional StartMusicRequest
065     */
066    public static Optional<StartEvent> createStartEvent(Identification source, boolean isUsingJava) {
067        try {
068            StartEvent startEvent;
069            if (isUsingJava) {
070                startEvent  = new StartEvent(source);
071            } else {
072                startEvent =  new StartEvent(source, IS_USING_NON_JAVA_OUTPUT);
073            }
074            return Optional.of(startEvent);
075        } catch (IllegalArgumentException e) {
076            return Optional.empty();
077        }
078    }
079}