예제 #1
0
 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());
 }
예제 #2
0
 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;
 }
예제 #3
0
 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;
 }
예제 #4
0
 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"));
   }
 }
예제 #5
0
 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;
 }
예제 #6
0
 public int copyCount() {
   int count = 0;
   for (Iterator iter = mediaCopies.values().iterator(); iter.hasNext(); ) {
     List list = (List) iter.next();
     count += list.size();
   }
   return count;
 }
예제 #7
0
 public void delete(MediaCopy copy) {
   for (Iterator iter = mediaCopies.values().iterator(); iter.hasNext(); ) {
     List list = (List) iter.next();
     if (list.remove(copy)) {
       return;
     }
   }
 }
예제 #8
0
 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;
 }
예제 #9
0
 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;
 }
예제 #10
0
 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;
 }
예제 #11
0
 public boolean contains(String id) {
   return mediaCopies.containsKey(id);
 }
예제 #12
0
 public int mediaCount() {
   return mediaCopies.size();
 }
예제 #13
0
 public void clear() {
   lastCopyId = 0;
   mediaCopies.clear();
 }