package org.dvdexchange.service;
import java.util.ArrayList;
import java.util.List;
import org.dvdexchange.domain.Dvd;
import org.dvdexchange.domain.DvdCollection;
import org.dvdexchange.domain.User;
/**
* A simple dvd library implementation
*/
public class SimpleDvdLibrary implements DvdLibrary {
private List<Dvd> m_library;
public SimpleDvdLibrary() {
m_library = new ArrayList<Dvd>();
}
@Override
public DvdCollection getDvdsAvailableForUser(User user) {
DvdCollection collection = new DvdCollection();
for (Dvd dvd : m_library) {
if (user == null || !user.equals(dvd.getOwner())) {
collection.add(dvd);
}
}
return collection;
}
@Override
public DvdCollection getDvdsUserOwns(User user) {
DvdCollection collection = new DvdCollection();
for (Dvd dvd : m_library) {
if (user != null && user.equals(dvd.getOwner())) {
collection.add(dvd);
}
}
return collection;
}
public void addDvd(Dvd dvd) {
m_library.add(dvd);
}
public void setDvds(List<Dvd> allDvds) {
m_library.clear();
m_library.addAll(allDvds);
}
}