package com.twu.biblioteca;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Tito on 18/09/2015.
 *
 * Contains a list of all books
 */
public class Library {
    private List<Book> bookList;
    private List<Movie> movieList;

    /**
     * Default constructor
     */
    public Library() {
        this.bookList = new ArrayList<Book>();
        this.movieList = new ArrayList<Movie>();
    }

    /**
     * Add a book to the library
     * @param book The book to be added
     */
    public void add(Book book) {
        bookList.add(book);
    }

    /**
     * Add a movie to the library
     * @param movie The movie to be added
     */
    public void add(Movie movie) {
        movieList.add(movie);
    }

    /**
     * Get a list of all books
     * @return A list of every book in the library
     */
    public List<Book> getBooks(){
        return this.bookList;
    }

    /**
     * Get all available books
     * @return Every book that has not been checked out
     */
    public List<Book> getAvailableBooks(){
        return (List<Book>) searchByAvailability(bookList, true);
    }

    /**
     * Get all books that have been loaned out
     * @return Every book currently on loan
     */
    public List<Book> getLoanedBooks() {
        return (List<Book>) searchByAvailability(bookList, false);
    }

    /**
     * Get all available movies
     * @return Every movie that has not been checked out
     */
    public List<Movie> getAvailableMovies() {
        return (List<Movie>) searchByAvailability(movieList, true);
    }

    /**
     * Get all movies that have been loaned out
     * @return Every movie currently on loan
     */
    public List<Movie> getLoanedMovies() {
        return (List<Movie>) searchByAvailability(movieList, false);
    }

    /**
     * Get all of the movies in the library
     * @return All movies
     */
    public List<Movie> getMovies() {
        return this.movieList;
    }

    /**
     * Return available or unavailable items from a list of library stock items
     */
    private List<?extends LibraryStock> searchByAvailability(List<?extends LibraryStock> list, boolean availability) {
        List<LibraryStock> items = new ArrayList<LibraryStock>();

        for (LibraryStock item : list) {
            if (item.isAvailable() == availability) {
                items.add(item);
            }
        }
        return items;
    }

}

@@ -67,19 +67,67 @@
 va.util.
-Lis
+HashSet;%0Aimport java.util.List;%0Aimport java.util.Se
 t;%0A%0A/**%0A
@@ -289,16 +289,47 @@
 vieList;
+%0A    private Set%3CUser%3E userSet;
 %0A%0A    /*
@@ -431,24 +431,24 @@
 st%3CBook%3E();%0A
-
         this
@@ -480,24 +480,232 @@
 t%3CMovie%3E();%0A
+        this.userSet = new HashSet%3CUser%3E();%0A    %7D%0A%0A    /**%0A     *Add a user to the library%0A     * @param user The user to be added%0A     */%0A    public void addUser(User user) %7B%0A        this.userSet.add(user);%0A
     %7D%0A%0A    /

Add set of users to library