package com.caju.uheer.services.infrastructure;

import com.caju.uheer.core.Channel;
import com.caju.uheer.core.Music;
import com.caju.uheer.services.exceptions.EndOfPlaylistException;

public class PlaylistItem {
    private Channel channel;
    private Music music;
    private int indexAtSongsList;
    private long startingAt;

    public PlaylistItem(Channel channel, Music music, int indexAtSongsList) {
        this(channel, music, indexAtSongsList, 0);
    }

    public PlaylistItem(Channel channel, Music music, int indexAtSongsList, long startingAt) {
        this.channel = channel;
        this.music = music;
        this.indexAtSongsList = indexAtSongsList;
        this.startingAt = startingAt;
    }

    public PlaylistItem next() {
        if (indexAtSongsList + 1 == channel.Musics.length && !channel.Loops) {
            music = null;
            indexAtSongsList = -1;
            startingAt = -1;

            throw new EndOfPlaylistException();
        }

        indexAtSongsList = (indexAtSongsList + 1) % channel.Musics.length;
        music = channel.Musics[indexAtSongsList];
        startingAt = 0;

        return this;
    }

    public Music getMusic() {
        return music;
    }

    public long getStartingAt() {
        return startingAt;
    }

    public void setStartingAt(long startingAt) {
        this.startingAt = startingAt;
    }

    public static PlaylistItem currentOf(Channel channel) {
        for (int i = 0; i < channel.Musics.length; i++) {
            Music music = channel.Musics[i];

            if (music.Id == channel.CurrentId) {
                return new PlaylistItem(channel, music, i, 0);
            }
        }

        return null;
    }
}

@@ -216,1488 +216,246 @@
    p
-rivate Channel channel;%0A    private Music music;%0A    private int indexAtSongsList;%0A    private long startingAt;%0A%0A    public PlaylistItem(Channel channel, Music music, int indexAtSongsList) %7B%0A        this(channel, music, indexAtSongsList, 0);%0A    %7D%0A%0A    public PlaylistItem(Channel channel, Music music, int indexAtSongsList, long startingAt) %7B%0A        this.channel = channel;%0A        this.music = music;%0A        this.indexAtSongsList = indexAtSongsList;%0A        this.startingAt = startingAt;%0A    %7D%0A%0A    public PlaylistItem next() %7B%0A        if (indexAtSongsList + 1 == channel.Musics.length && !channel.Loops) %7B%0A            music = null;%0A            indexAtSongsList = -1;%0A            startingAt = -1;%0A%0A            throw new EndOfPlaylistException();%0A        %7D%0A%0A        indexAtSongsList = (indexAtSongsList + 1) %25 channel.Musics.length;%0A        music = channel.Musics%5BindexAtSongsList%5D;%0A        startingAt = 0;%0A%0A        return this;%0A    %7D%0A%0A    public Music getMusic() %7B%0A        return music;%0A    %7D%0A%0A    public long getStartingAt() %7B%0A        return startingAt;%0A    %7D%0A%0A    public void setStartingAt(long startingAt) %7B%0A        this.startingAt = startingAt;%0A    %7D%0A%0A    public static PlaylistItem currentOf(Channel channel) %7B%0A        for (int i = 0; i %3C channel.Musics.length; i++) %7B%0A            Music music = channel.Musics%5Bi%5D;%0A%0A            if (music.Id == channel.CurrentId) %7B%0A                return new PlaylistItem(channel, music, i, 0);%0A            %7D%0A        %7D%0A%0A        return null
+ublic Music music;%0A    public long startingAt;%0A%0A    public PlaylistItem(Music music) %7B%0A        this(music, 0);%0A    %7D%0A%0A    public PlaylistItem(Music music, long startingAt) %7B%0A        this.music = music;%0A        this.startingAt = startingAt
 ;%0A  

Simplify PlaylistItem