001package org.intellimate.izou.sdk.frameworks.music.resources; 002 003import org.intellimate.izou.events.EventModel; 004import org.intellimate.izou.identification.Identification; 005import org.intellimate.izou.resource.ResourceModel; 006import org.intellimate.izou.sdk.frameworks.music.player.Volume; 007import org.intellimate.izou.sdk.resource.Resource; 008 009import java.util.Optional; 010 011/** 012 * this resource is simply used hold the playlist, can be obtained via the resourceManager 013 * @author LeanderK 014 * @version 1.0 015 */ 016public class VolumeResource extends Resource<Integer> { 017 public static final String ID = "izou.music.resource.volume"; 018 019 /** 020 * creates a new Resource. 021 * This method is thread-safe. 022 * 023 * @param provider the Provider of the Resource 024 */ 025 public VolumeResource(Identification provider) { 026 super(ID, provider); 027 } 028 029 /** 030 * creates a new Resource. 031 * This method is thread-safe. 032 * 033 * @param provider the Provider of the Resource 034 * @param volume the resource 035 */ 036 public VolumeResource(Identification provider, Volume volume) { 037 super(ID, provider, volume.getVolume()); 038 } 039 040 /** 041 * creates a new Resource. 042 * This method is thread-safe. 043 * 044 * @param provider the Provider of the Resource 045 * @param consumer the ID of the Consumer 046 */ 047 public VolumeResource(Identification provider, Identification consumer) { 048 super(ID, provider, consumer); 049 } 050 051 /** 052 * creates a new Resource. 053 * This method is thread-safe. 054 * 055 * @param provider the Provider of the Resource 056 * @param volume the resource 057 * @param consumer the ID of the Consumer 058 */ 059 public VolumeResource(Identification provider, Volume volume, Identification consumer) { 060 super(ID, provider, volume.getVolume(), consumer); 061 } 062 063 /** 064 * gets the first Volume if found in the EventModel 065 * @param eventModel the EventModel 066 * @return return the optional Volume 067 */ 068 public static Optional<Volume> getVolume(EventModel eventModel) { 069 if (eventModel.getListResourceContainer().containsResourcesFromSource(ID)) { 070 return eventModel 071 .getListResourceContainer() 072 .provideResource(ID) 073 .stream() 074 .map(ResourceModel::getResource) 075 .filter(ob -> ob instanceof Integer) 076 .map(ob -> (Integer) ob) 077 .findAny() 078 .flatMap(Volume::createVolume); 079 080 } else { 081 return Optional.empty(); 082 } 083 } 084}