You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
36 lines
824 B
36 lines
824 B
package com.music.repository;
|
|
|
|
import com.music.model.Song;
|
|
import java.util.*;
|
|
|
|
public class SongRepository {
|
|
private final List<Song> songs = new ArrayList<>();
|
|
|
|
public void add(Song song) {
|
|
if (song == null) {
|
|
throw new IllegalArgumentException("歌曲不能为 null");
|
|
}
|
|
if (song.getName() == null || song.getName().trim().isEmpty()) {
|
|
throw new IllegalArgumentException("歌曲名不能为空");
|
|
}
|
|
songs.add(song);
|
|
}
|
|
|
|
public void addAll(List<Song> songList) {
|
|
for (Song s : songList) {
|
|
add(s);
|
|
}
|
|
}
|
|
|
|
public List<Song> getAll() {
|
|
return Collections.unmodifiableList(songs);
|
|
}
|
|
|
|
public int size() {
|
|
return songs.size();
|
|
}
|
|
|
|
public void clear() {
|
|
songs.clear();
|
|
}
|
|
}
|