public void testGetAllISBNsDoesNotIncludeCompactDiscs() { gateway.addCopies( new CompactDisc("abcd", "Peace and War, The Musical", "Gilbertolov and Sullivanalov"), 2); gateway.addCopies(new CompactDisc("xyz", "The White Album", "The Beatles"), 2); Map isbnsTitles = gateway.findAllISBNsAndTitles(); assertEquals(1, isbnsTitles.size()); assertEquals(6, gateway.copyCount()); }
protected List findAllKeysForValuesOfType(Class type) { List list = new ArrayList(); for (Iterator iter = mediaCopies.keySet().iterator(); iter.hasNext(); ) { String key = (String) iter.next(); Media media = getFirstInList((List) mediaCopies.get(key)); if (media != null && media.getClass().equals(type)) list.add(key); } return list; }
public MediaCopy addCopy(Media media) { lastCopyId += 1; MediaCopy mediaCopy = new MediaCopy(media, "" + lastCopyId); String mediaId = media.getId(); List copies = (List) mediaCopies.get(mediaId); if (copies == null) { copies = new LinkedList(); mediaCopies.put(mediaId, copies); } copies.add(mediaCopy); return mediaCopy; }
public void testGetAllISBNsAndTitles() { gateway.addCopy(new Book("isbn2", "Peace and War", "Toy Story")).getId(); gateway.addCopy(new Book("isbn3", "Son of Peace and War", "Toy Story II")).getId(); Map isbnsTitles = gateway.findAllISBNsAndTitles(); assertEquals(3, isbnsTitles.size()); Iterator iter = isbnsTitles.entrySet().iterator(); while (iter.hasNext()) { Entry entry = (Entry) iter.next(); assertTrue(((String) entry.getKey()).startsWith("isbn")); assertTrue(((String) entry.getValue()).contains("Peace")); } }
public Map findAllISBNsAndTitles() { List isbns = findAllKeysForValuesOfType(Book.class); Map map = new HashMap(); for (Iterator iter = isbns.iterator(); iter.hasNext(); ) { String isbn = (String) iter.next(); List copies = (List) mediaCopies.get(isbn); if (copies.size() > 0) { String title = ((MediaCopy) copies.get(0)).getMedia().getTitle(); map.put(isbn, title); } } return map; }
public int copyCount() { int count = 0; for (Iterator iter = mediaCopies.values().iterator(); iter.hasNext(); ) { List list = (List) iter.next(); count += list.size(); } return count; }
public void delete(MediaCopy copy) { for (Iterator iter = mediaCopies.values().iterator(); iter.hasNext(); ) { List list = (List) iter.next(); if (list.remove(copy)) { return; } } }
protected List findAllCollectionsOfType(Class type) { List list = new ArrayList(); List keys = findAllKeysForValuesOfType(type); for (Iterator iter = keys.iterator(); iter.hasNext(); ) { String key = (String) iter.next(); list.add(mediaCopies.get(key)); } return list; }
public MediaCopy findCopyById(String copyId) { Collection listsOfCopies = mediaCopies.values(); for (Iterator i = listsOfCopies.iterator(); i.hasNext(); ) { List copies = (List) i.next(); for (int j = 0; j < copies.size(); j++) { MediaCopy mediaCopy = (MediaCopy) copies.get(j); if (mediaCopy.getId().equals(copyId)) return mediaCopy; } } return null; }
public List findAllLoanReceiptsFor(String patronId) { List receipts = new LinkedList(); Collection copyLists = mediaCopies.values(); for (Iterator i = copyLists.iterator(); i.hasNext(); ) { List copyList = (List) i.next(); for (int j = 0; j < copyList.size(); j++) { MediaCopy mediaCopy = (MediaCopy) copyList.get(j); LoanReceipt receipt = mediaCopy.getLoanReceipt(); if (receipt != null && receipt.getBorrower().getId().equals(patronId)) receipts.add(receipt); } } return receipts; }
public boolean contains(String id) { return mediaCopies.containsKey(id); }
public int mediaCount() { return mediaCopies.size(); }
public void clear() { lastCopyId = 0; mediaCopies.clear(); }