Exemplo n.º 1
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;
 }
Exemplo n.º 2
0
 public void delete(MediaCopy copy) {
   for (Iterator iter = mediaCopies.values().iterator(); iter.hasNext(); ) {
     List list = (List) iter.next();
     if (list.remove(copy)) {
       return;
     }
   }
 }
Exemplo n.º 3
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;
 }
Exemplo n.º 4
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;
 }
Exemplo n.º 5
0
 public void testAddCopiesCreatesUniqueIds() throws Exception {
   List copies = gateway.addCopies(new Book("isbn", "War and Peace", "Tolstoy"), 3);
   assertEquals(3, copies.size());
   assertEquals(5, gateway.findAllCopies("isbn").size());
   Set ids = new HashSet();
   for (Iterator iter = gateway.findAllCopies("isbn").iterator(); iter.hasNext(); )
     ids.add(((MediaCopy) iter.next()).getId());
   assertEquals(5, ids.size());
 }
Exemplo n.º 6
0
 public MediaCopy findCdCopy(String barCode) {
   List copies = (List) this.mediaCopies.get(barCode);
   if (copies != null) {
     for (Iterator i = copies.iterator(); i.hasNext(); ) {
       MediaCopy copy = (MediaCopy) i.next();
       if (copy.isCdCopy()) return copy;
     }
     return null;
   } else return null;
 }
Exemplo n.º 7
0
 public MediaCopy findBookCopy(String isbn) {
   List copies = (List) this.mediaCopies.get(isbn);
   if (copies != null) {
     for (Iterator i = copies.iterator(); i.hasNext(); ) {
       MediaCopy copy = (MediaCopy) i.next();
       if (copy.isBookCopy()) return copy;
     }
     return null;
   } else return null;
 }
Exemplo n.º 8
0
 public void testGetAllISBNs() {
   gateway.addCopy(new Book("isbn2", "Peace and War", "Toy Story")).getId();
   List isbns = gateway.findAllISBNs();
   assertEquals(2, isbns.size());
   Iterator iter = isbns.iterator();
   while (iter.hasNext()) {
     String isbn = (String) iter.next();
     assertTrue(isbn, isbn.startsWith("isbn"));
   }
 }
Exemplo n.º 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;
 }
Exemplo n.º 10
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"));
   }
 }
Exemplo n.º 11
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;
 }
Exemplo n.º 12
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;
 }