package com.parnswir.unmp.playlist;

import java.util.ArrayList;


public class Playlist extends PlaylistElement {
	
	private static final long serialVersionUID = 3196172024840309061L;
	
	private String name;
	private int current;
	public ArrayList<PlaylistElement> children = new ArrayList<PlaylistElement>();
	
	
	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	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 void next() {
		String nextFile = null;
		while (! isFinished() && nextFile == null) {
			getCurrentChild().next();
			nextFile = getCurrentChild().getCurrentFile();
			if (nextFile == null) {
				nextSource();
				if (! isFinished())
					nextFile = getCurrentChild().getCurrentFile();
			}
		}
	}

	@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);
		}
	}
	
}

@@ -655,72 +655,20 @@
 %0A%09%09%09
-throw new IndexOutOfBoundsException(%22Playlist is finished.%22);%0A%09%09
+return null;
 %0A%09%09r
@@ -915,24 +915,73 @@
 entFile() %7B%0A
+%09%09if (getCurrentChild() == null)%0A%09%09%09return null;%0A
 %09%09return get
@@ -1077,16 +1077,68 @@
 = null;%0A
+%09%09PlaylistElement currentChild = getCurrentChild();%0A
 %09%09while 
@@ -1179,20 +1179,49 @@
 l) %7B%0A%09%09%09
-getC
+if (currentChild != null) %7B%0A%09%09%09%09c
 urrentCh
@@ -1223,18 +1223,16 @@
 entChild
-()
 .next();
@@ -1232,16 +1232,17 @@
 next();%0A
+%09
 %09%09%09nextF
@@ -1239,36 +1239,33 @@
 %0A%09%09%09%09nextFile = 
-getC
+c
 urrentChild().ge
@@ -1251,34 +1251,32 @@
 e = currentChild
-()
 .getCurrentFile(
@@ -1278,16 +1278,21 @@
 File();%0A
+%09%09%09%7D%0A
 %09%09%09if (n
@@ -1346,24 +1346,53 @@
 isFinished()
+ && getCurrentChild() != null
 )%0A%09%09%09%09%09nextF

Fix finishing playlist