import java.util.ArrayList;

/**
 * La misma idea por herencia: ES un ArrayList. Hace override de add(Song) para
 * cuidar la duración máxima, pero hereda decenas de métodos públicos que no la
 * cuidan (add(int, Song), addAll, set...).
 */
@SuppressWarnings("serial")     // ArrayList es Serializable; aquí no serializamos
public class InheritedPlaylist extends ArrayList<Song> {
    private final int maxSeconds;

    public InheritedPlaylist(int maxSeconds) {
        this.maxSeconds = maxSeconds;
    }

    @Override
    public boolean add(Song song) {
        if (totalSeconds() + song.seconds() > maxSeconds) {
            return false;
        }
        return super.add(song);
    }

    public int totalSeconds() {
        int sum = 0;
        for (Song s : this) {
            sum += s.seconds();
        }
        return sum;
    }
}
