Package org.dvdexchange.service

Source Code of org.dvdexchange.service.SimpleDvdLibrary

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);
  }
}
TOP

Related Classes of org.dvdexchange.service.SimpleDvdLibrary

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.