File tree Expand file tree Collapse file tree 1 file changed +47
-0
lines changed
Expand file tree Collapse file tree 1 file changed +47
-0
lines changed Original file line number Diff line number Diff line change 1+ import java .util .*;
2+
3+ interface Playlist {
4+ Song getNextSong ();
5+
6+ boolean hasNextSong ();
7+ }
8+
9+ class Song {
10+ String name ;
11+
12+ public Song (String name ) {
13+ this .name = name ;
14+ }
15+ }
16+
17+ class CollaborativePlaylist implements Playlist {
18+ private Deque <Playlist > dq ;
19+
20+ public CollaborativePlaylist (List <Playlist > playlists ) {
21+ dq = new ArrayDeque <>();
22+
23+ for (Playlist p : playlists ) {
24+ dq .offer (p );
25+ }
26+ }
27+
28+ @ Override
29+ public Song getNextSong () {
30+ while (!dq .isEmpty ()) {
31+ Playlist p = dq .pollFirst ();
32+
33+ if (p .hasNextSong ()) {
34+ Song s = p .getNextSong ();
35+ dq .offerLast (p );
36+ return s ;
37+ }
38+ }
39+
40+ return null ;
41+ }
42+
43+ @ Override
44+ public boolean hasNextSong () {
45+ return !dq .isEmpty ();
46+ }
47+ }
You can’t perform that action at this time.
0 commit comments