@Override public void addRental(Rental rental) { Lendable lendable = rental.getLendable(); Rental myRental = getMyRental(lendable); if (myRental != null) myRental.renew(); else rentals.add(rental); }
private Rental getMyRental(Lendable lendable) { for (Rental aRental : rentals) if (aRental.getLendable().equals(lendable)) return aRental; return null; }
@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; }