Skip to content

Commit a78e61c

Browse files
committed
Playlist arguments checking
1 parent 7645926 commit a78e61c

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

src/main/java/com/xxmicloxx/NoteBlockAPI/model/Playlist.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,17 @@
22

33
import java.util.ArrayList;
44
import java.util.Arrays;
5+
import java.util.List;
56

67
public class Playlist {
78

89
ArrayList<Song> songs = new ArrayList<>();
910

1011
public Playlist(Song ...songs){
12+
if (songs.length == 0){
13+
throw new IllegalArgumentException("Cannot create empty playlist");
14+
}
15+
checkNull(songs);
1116
this.songs.addAll(Arrays.asList(songs));
1217
}
1318

@@ -16,9 +21,20 @@ public Playlist(Song ...songs){
1621
* @param songs
1722
*/
1823
public void add(Song ...songs){
24+
if (songs.length == 0){
25+
return;
26+
}
27+
checkNull(songs);
1928
this.songs.addAll(Arrays.asList(songs));
2029
}
2130

31+
private void checkNull(Song ...songs){
32+
List<Song> songList = Arrays.asList(songs);
33+
if (songList.contains(null)){
34+
throw new IllegalArgumentException("Cannot add null to playlist");
35+
}
36+
}
37+
2238
/**
2339
* Removes songs from playlist
2440
* @param songs

0 commit comments

Comments
 (0)