src/main/java/org/intellimate/izou/sdk/frameworks/music/player/Playlist.java
public static Optional<Playlist> importResource(ResourceModel resourceModel) {
        Object resource = resourceModel.getResource();
        try {
            //noinspection unchecked
            HashMap<String, Object> data = (HashMap<String, Object>) resource;
            ArrayList<TrackInfo> queue = new ArrayList<>();
            ArrayList<PlaybackMode> playbackModes = new ArrayList<>();
            final String[] name = {null};
            final int[] position = {-1};
            final String[] dataString = {null};
            data.entrySet().forEach(entry -> {
                if (entry.getKey().startsWith(QUEUE_DESCRIPTOR)) {
                    int index = Integer.parseInt(entry.getKey().replace(QUEUE_DESCRIPTOR, ""));
                    //noinspection unchecked
                    TrackInfo.importFromHashMap((HashMap<String, Object>) entry.getValue())
                            .ifPresent(trackInfo -> queue.add(index, trackInfo));
                } else if (entry.getKey().startsWith(PLAYBACK_MODE_DESCRIPTOR)) {
                    try {
                        int index = Integer.parseInt(entry.getKey().replace(PLAYBACK_MODE_DESCRIPTOR, ""));
                        //noinspection unchecked
                        playbackModes.add(index, PlaybackMode.valueOf((String) entry.getValue()));
                    } catch (IllegalArgumentException ignored) {
                        //happens when the name is not present...maybe future sdks define other playbackModes
                    }
                } else if (entry.getKey().equals(NAME_DESCRIPTOR)) {
                    name[0] = (String) entry.getValue();
                } else if (entry.getKey().equals(POSITION_DESCRIPTOR)) {
                    position[0] = (int) entry.getValue();
                } else if (entry.getKey().equals(DATA_DESCRIPTOR)) {
                    dataString[0] = (String) entry.getValue();
                }
            });
            return Optional.of(new Playlist(queue, name[0] , playbackModes, position[0], dataString[0]));
        } catch (ClassCastException | IllegalArgumentException e) {
            return Optional.empty();
        }
    }
public static Optional<Playlist> importResource(ResourceModel resourceModel) {
        Object resource = resourceModel.getResource();
        try {
            //noinspection unchecked
            HashMap<String, Object> data = (HashMap<String, Object>) resource;
            ArrayList<TrackInfo> queue = new ArrayList<>();
            ArrayList<PlaybackMode> playbackModes = new ArrayList<>();
            final String[] name = {null};
            final int[] position = {-1};
            final String[] dataString = {null};
            data.entrySet().forEach(entry -> {
                if (entry.getKey().startsWith(QUEUE_DESCRIPTOR)) {
                    int index = Integer.parseInt(entry.getKey().replace(QUEUE_DESCRIPTOR, ""));
                    //noinspection unchecked
                    TrackInfo.importFromHashMap((HashMap<String, Object>) entry.getValue())
                            .ifPresent(trackInfo -> queue.add(index, trackInfo));
                } else if (entry.getKey().startsWith(PLAYBACK_MODE_DESCRIPTOR)) {
                    try {
                        int index = Integer.parseInt(entry.getKey().replace(PLAYBACK_MODE_DESCRIPTOR, ""));
                        //noinspection unchecked
                        playbackModes.add(index, PlaybackMode.valueOf((String) entry.getValue()));
                    } catch (IllegalArgumentException ignored) {
                        //happens when the name is not present...maybe future sdks define other playbackModes
                    }
                } else if (entry.getKey().equals(NAME_DESCRIPTOR)) {
                    name[0] = (String) entry.getValue();
                } else if (entry.getKey().equals(POSITION_DESCRIPTOR)) {
                    position[0] = (int) entry.getValue();
                } else if (entry.getKey().equals(DATA_DESCRIPTOR)) {
                    dataString[0] = (String) entry.getValue();
                }
            });
            return Optional.of(new Playlist(queue, name[0] , playbackModes, position[0], dataString[0]));
        } catch (ClassCastException | IllegalArgumentException e) {
            return Optional.empty();
        }
    }
public static Optional < Playlist > importResource ( ResourceModel resourceModel ) { Object resource = resourceModel . getResource ( ) ; try { //noinspection unchecked HashMap < String , Object > data = ( HashMap < String , Object > ) resource ; ArrayList < TrackInfo > queue = new ArrayList <> ( ) ; ArrayList < PlaybackMode > playbackModes = new ArrayList <> ( ) ; final String [ ] name = { null } ; final int [ ] position = { - 1 } ; final String [ ] dataString = { null } ; data . entrySet ( ) . forEach ( entry -> { if ( entry . getKey ( ) . startsWith ( QUEUE_DESCRIPTOR ) ) { int index = Integer . parseInt ( entry . getKey ( ) . replace ( QUEUE_DESCRIPTOR , "" ) ) ; //noinspection unchecked TrackInfo . importFromHashMap ( ( HashMap < String , Object > ) entry . getValue ( ) ) . ifPresent ( trackInfo -> queue . add ( index , trackInfo ) ) ; } else if ( entry . getKey ( ) . startsWith ( PLAYBACK_MODE_DESCRIPTOR ) ) { try { int index = Integer . parseInt ( entry . getKey ( ) . replace ( PLAYBACK_MODE_DESCRIPTOR , "" ) ) ; //noinspection unchecked playbackModes . add ( index , PlaybackMode . valueOf ( ( String ) entry . getValue ( ) ) ) ; } catch ( IllegalArgumentException ignored ) { //happens when the name is not present...maybe future sdks define other playbackModes } } else if ( entry . getKey ( ) . equals ( NAME_DESCRIPTOR ) ) { name [ 0 ] = ( String ) entry . getValue ( ) ; } else if ( entry . getKey ( ) . equals ( POSITION_DESCRIPTOR ) ) { position [ 0 ] = ( int ) entry . getValue ( ) ; } else if ( entry . getKey ( ) . equals ( DATA_DESCRIPTOR ) ) { dataString [ 0 ] = ( String ) entry . getValue ( ) ; } } ) ; return Optional . of ( new Playlist ( queue , name [ 0 ] , playbackModes , position [ 0 ] , dataString [ 0 ] ) ) ; } catch ( ClassCastException | IllegalArgumentException e ) { return Optional . empty ( ) ; } }
constructs (if no errors were found) the Playlist from the Resource
@param resourceModel the resourceModel to import from
@return the optional Playlist
constructs ( if no errors were found ) the Playlist from the Resource