package com.parnswir.playlist;

import java.util.ArrayList;


public class Playlist extends PlaylistElement {
	
	private int current;
	public ArrayList<PlaylistElement> children = new ArrayList<PlaylistElement>();
	
	
	public int getPosition() {
		return current;
	}
	
	public void setPosition(int position) {
		if (position < children.size() && position > -1)
			current = position;
	}

	public PlaylistElement getCurrentChild() {
		if (isFinished())
			throw new IndexOutOfBoundsException("Playlist is finished.");
		
		return children.get(current);
	}
	
	public void nextSource() {
		current = current + 1;
	}
	
	public boolean isFinished() {
		return current >= children.size();
	}
	
	public void start() {
		current = 0;
	}

	@Override
	public String getCurrentFile() {
		return getCurrentChild().getCurrentFile();
	}
	
	@Override
	public String getNextFile() {
		String nextFile = super.getNextFile();
		while (! isFinished() && nextFile == null) {
			nextFile = getCurrentChild().getNextFile();
			if (nextFile == null)
				nextSource();
		}
		return nextFile;
	}

	@Override
	public void setRepeating(boolean repeating) {
		super.setRepeating(repeating);
		for (PlaylistElement child : children) {
			child.setRepeating(repeating);
		}
	}
	
	@Override
	public void setShuffled(boolean shuffled) {
		super.setShuffled(shuffled);
		for (PlaylistElement child : children) {
			child.setShuffled(shuffled);
		}
	}
	
}

@@ -105,16 +105,38 @@
 ent %7B%0A%09%0A
+%09private String name;%0A
 %09private
@@ -233,16 +233,122 @@
 ();%0A%09%0A%09%0A
+%09public String getName() %7B%0A%09%09return name;%0A%09%7D%0A%0A%09public void setName(String name) %7B%0A%09%09this.name = name;%0A%09%7D%0A%0A
 %09public 

Add name to playlist class