3 import interfaces
.Track
;
4 import interfaces
.collection
.AbstractCollection
;
5 import interfaces
.collection
.Collection
;
6 import interfaces
.collection
.EditableSource
;
7 import interfaces
.collection
.Source
;
9 import java
.util
.LinkedList
;
10 import java
.util
.List
;
12 import notification
.AbstractEventGenerator
;
14 public class ShufflePlaylist
15 extends AbstractEventGenerator
<Source
.Listener
>
16 implements Source
<Track
>, EditableSource
<Track
> {
18 private final PlaybackQueue queue
;
19 private final int containerId
;
20 private int collectionItemId
;
22 public ShufflePlaylist(PlaybackQueue queue
, final int id
, final long pid
, final String name
) {
25 this.containerId
= id
;
26 collectionItemId
= id
+1;
28 collection
= new AbstractCollection
<Track
>(id
, pid
) {
30 public int editStatus() {
31 return Collection
.EDITABLE
;
34 public boolean isRoot() {
38 public String
name() {
42 public Collection
<?
extends Track
> parent() {
47 return shuffle
.size();
50 public Source
<Track
> source() {
57 private volatile LinkedList
<Track
> _list
= new LinkedList
<Track
>();
59 private LinkedList
<Track
> getList() {
63 private void setList(LinkedList
<Track
> list
) {
65 queue
.notifyQueueChanged();
69 setList(new LinkedList
<Track
>());
72 public boolean hasNext() {
73 return !getList().isEmpty();
77 LinkedList
<Track
> old
= getList();
78 Track next
= old
.peek();
79 LinkedList
<Track
> list
= new LinkedList
<Track
>(old
.subList(1, old
.size()));
85 return getList().size();
88 public List
<Track
> tracks() {
92 public void append(Track t
) {
94 LinkedList
<Track
> n
= new LinkedList
<Track
>(getList());
95 n
.addLast(new CollectionTrack(t
, containerId
, collectionItemId
++));
100 public void appendAll(java
.util
.Collection
<?
extends Track
> ts
) {
102 LinkedList
<Track
> n
= new LinkedList
<Track
>(getList());
104 n
.add(new CollectionTrack(t
, containerId
, this.collectionItemId
++));
110 public void insertFirst(Track t
) {
112 LinkedList
<Track
> n
= new LinkedList
<Track
>(getList());
118 public void move(Track track
, Track marker
) {
120 LinkedList
<Track
> n
= new LinkedList
<Track
>(getList());
121 if (marker
== null) {
125 else if (marker
.equals(track
));
130 if (t
.equals(marker
)) {
131 n
.subList(0, i
).add(track
);
137 //didn't find element to insert before
145 public void remove(Track t
) {
146 LinkedList
<Track
> list
= getList();
147 if (t
!= null && list
.contains(t
)) {
148 list
= new LinkedList
<Track
>(list
);
154 public void removeAll(java
.util
.Collection
<?
extends Track
> coll
) {
155 for (Track t
: coll
) {
160 public void trim(int size
) {
161 if (getList().size() <= size
) return;
162 LinkedList
<Track
> list
= new LinkedList
<Track
>(getList().subList(0, size
));
168 private final ShufflePlaylist shuffle
= this;
169 private final Collection
<Track
> collection
;
171 public final Collection
<Track
> collection() {