package com.twu.biblioteca;

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

/**
 * Created by santacos on 8/7/2016 AD.
 */
public class Library {
    private String name;
    private ArrayList<Book> books;

    public Library(String name, ArrayList<Book> books) {
        this.name = name;
        this.books = books;
    }

    public String getName() {
        return name;
    }

    public Book findBookByName(String name) {
        for(Book book: books){
            if(book.getName().equals(name)){
                return book;
            }
        }
        return null;
    }


    public boolean checkOutBookByName(String name) {
        Book book = findBookByName(name);
        if(book == null)
            return false;

        boolean isCheckedOutSuccessfully = book.checkOut();
        return isCheckedOutSuccessfully;
    }
}

@@ -72,16 +72,43 @@
 il.List;
+%0Aimport java.util.Optional;
 %0A%0A/**%0A *
@@ -419,20 +419,30 @@
  public 
+Optional%3C
 Book
+%3E
  findBoo
@@ -563,20 +563,33 @@
  return 
+Optional.of(
 book
+)
 ;%0A      
@@ -621,20 +621,32 @@
  return 
-null
+Optional.empty()
 ;%0A    %7D%0A
@@ -708,20 +708,30 @@
         
+Optional%3C
 Book
+%3E
  book = 
@@ -771,45 +771,73 @@
 book
- == null)%0A            return false;%0A%0A
+.isPresent())%7B%0A            Book checkedOutBook = book.get();%0A    
     
@@ -875,17 +875,27 @@
 fully = 
-b
+checkedOutB
 ook.chec
@@ -898,24 +898,28 @@
 checkOut();%0A
+    
         retu
@@ -947,16 +947,69 @@
 sfully;%0A
+        %7Delse%7B%0A            return false;%0A        %7D%0A%0A%0A
     %7D%0A%7D%0A

update Library class in findBookByName method to return Option object , avoid NullPointerException