package com.twu.biblioteca;

import com.twu.biblioteca.model.Book;

import java.util.List;
import java.util.Optional;
import java.util.stream.Stream;

import static java.util.stream.Collectors.toList;

public class BibliotecaLibrary {

    private List<Book> books;

    public BibliotecaLibrary() {
        books = buildPreExistingList();
    }

    private List<Book> buildPreExistingList() {
        return Stream.of("book1", "book2")
                .map(Book::new)
                .collect(toList());
    }

    public List<Book> getBooks() {
        return books;
    }

    public String getWelcome() {
        return "Welcome to Yuexiang's Biblioteca";
    }

    public boolean checkOutBook(String bookName) {
        Optional<Book> findBook = books.stream()
                .filter(book -> !book.isCheckOut() && book.getName().equals(bookName))
                .findFirst();
        if (findBook.isPresent()) {
            findBook.get().setCheckOut(true);
            return true;
        }
        return false;
    }

    public boolean returnBook(String bookName) {
        Optional<Book> findBook = books.stream()
                .filter(book -> book.isCheckOut() && book.getName().equals(bookName))
                .findFirst();
        if (findBook.isPresent()) {
            findBook.get().setCheckOut(false);
            return true;
        }
        return false;
    }
}

@@ -60,16 +60,83 @@
 l.Book;%0A
+import com.twu.biblioteca.model.Movie;%0A%0Aimport java.util.ArrayList;
 %0Aimport 
@@ -325,16 +325,48 @@
 %3E books;
+%0A    private List%3CMovie%3E movies;
 %0A%0A    pu
@@ -428,24 +428,67 @@
 tingList();%0A
+        movies = buildPreExistingMovies();%0A
     %7D%0A%0A    p
@@ -640,32 +640,350 @@
 List());%0A    %7D%0A%0A
+    private List%3CMovie%3E buildPreExistingMovies() %7B%0A        List%3CMovie%3E movies = new ArrayList%3C%3E();%0A        movies.add(new Movie(%22movie1%22, 2006, %22director1%22, 8));%0A        movies.add(new Movie(%22movie2%22, 1980, %22director2%22, 9));%0A        movies.add(new Movie(%22movie3%22, 2015, %22director3%22, 2));%0A        return movies;%0A    %7D%0A%0A
     public List%3C

add private method BibliotecaLibrary.buildPreExistingMovies to build movies