001package org.intellimate.izou.sdk.frameworks.permanentSoundOutput.output; 002 003import org.intellimate.izou.events.EventModel; 004import org.intellimate.izou.identification.IdentificationManager; 005import org.intellimate.izou.resource.ResourceModel; 006import org.intellimate.izou.sdk.frameworks.common.resources.ResourcesProviderBase; 007import org.intellimate.izou.sdk.frameworks.permanentSoundOutput.resource.UsingSoundResource; 008 009import java.util.ArrayList; 010import java.util.LinkedList; 011import java.util.List; 012import java.util.Optional; 013 014/** 015 * implements methods to automatically create Resources 016 * @author LeanderK 017 * @version 1.0 018 */ 019public interface PermanentSoundResources extends ResourcesProviderBase, PermanentSoundUsed { 020 021 @Override 022 default List<? extends ResourceModel> announceResources() { 023 List<ResourceModel> resources = new ArrayList<>(); 024 IdentificationManager.getInstance().getIdentification(this) 025 .map(UsingSoundResource::new) 026 .ifPresent(resources::add); 027 return resources; 028 } 029 030 @Override 031 default List<ResourceModel> provideResource(List<? extends ResourceModel> list, Optional<EventModel> event) { 032 if (isOutputRunning()) { 033 return ResourcesProviderBase.super.provideResource(list, event); 034 } else { 035 return new LinkedList<>(); 036 } 037 } 038 039 /** 040 * generates the resources 041 * @param resourceModel the resourceModel 042 * @param event the Event 043 * @return a Stream containing the resourceModel(s) 044 */ 045 @Override 046 default Optional<? extends ResourceModel> generateResource(ResourceModel resourceModel, Optional<EventModel> event) { 047 if (resourceModel.getResourceID().equals(UsingSoundResource.ID)) { 048 return createUsingSoundResource(); 049 } else { 050 return ResourcesProviderBase.super.generateResource(resourceModel, event); 051 } 052 } 053 054 /** 055 * creates a UsingSoundResource ready to return 056 * @return a list with (when no error happens) one resource 057 */ 058 default Optional<UsingSoundResource> createUsingSoundResource() { 059 return IdentificationManager.getInstance() 060 .getIdentification(this) 061 .map(UsingSoundResource::new); 062 } 063}