@Override public void addRental(Rental rental) { Lendable lendable = rental.getLendable(); Rental myRental = getMyRental(lendable); if (myRental != null) myRental.renew(); else rentals.add(rental); }
@Override public Boolean hasNonExpiredRental(Lendable lendable) { Rental myRental = getMyRental(lendable); return myRental != null ? !myRental.isExpired() : false; }
private Rental getMyRental(Lendable lendable) { for (Rental aRental : rentals) if (aRental.getLendable().equals(lendable)) return aRental; return null; }
@Override public boolean returnRentalForLendable(Lendable lendable) { Rental myRental = getMyRental(lendable); return myRental != null && !myRental.isExpired() ? myRental.returnToLibrary() : false; }
@Override public boolean returnRental(Rental rental) { return returnRentalForLendable(rental.getLendable()); }
@Override public boolean removeRental(Rental rental) { Rental myRental = getMyRental(rental.getLendable()); return myRental != null ? rentals.remove(myRental) : false; }