1 package org.musicontroller.songselection;
2
3 import java.util.ArrayList;
4 import java.util.Iterator;
5 import java.util.List;
6
7
8
9
10
11
12
13
14 public class LastPlayedContainer implements Cloneable {
15 private int _maxHistory=8;
16
17
18
19
20 private List<LastPlayedEntry> _lastsongs;
21
22 public LastPlayedContainer() {
23 _lastsongs = new ArrayList<LastPlayedEntry>(_maxHistory);
24 }
25
26
27
28
29
30
31
32
33 public void addToLastPlayed(long songid) {
34 addToLastPlayed(songid, true);
35 }
36
37
38
39
40
41
42
43 public void addToLastPlayed(long songid, boolean entirely) {
44 if (_lastsongs.size()>_maxHistory+1) {
45 _lastsongs.remove(0);
46 }
47 _lastsongs.add(new LastPlayedEntry(songid, entirely));
48 }
49
50 public int getSize() {
51 return _lastsongs.size();
52 }
53
54 public Iterator<LastPlayedEntry> getIterator() {
55 return _lastsongs.iterator();
56 }
57
58
59
60
61
62 @Override
63 public LastPlayedContainer clone() throws CloneNotSupportedException {
64 LastPlayedContainer clone = new LastPlayedContainer();
65
66 for (LastPlayedEntry e : _lastsongs) {
67 clone.addToLastPlayed(e.getSongid(), e.isPlayedEntirely());
68 }
69
70 return clone;
71 }
72
73
74
75
76
77 public String toString() {
78 return _lastsongs.toString();
79 }
80
81
82
83
84 public void markLastSongAsSkipped() {
85 int lastIndex = _lastsongs.size()-1;
86 _lastsongs.get(lastIndex).markSkipped();
87 }
88 }