001 package market; 002 003 import java.util.Iterator; 004 005 import data.CatalogItem; 006 import data.CountingStock; 007 import data.events.VetoException; 008 import data.ooimpl.CatalogImpl; 009 import data.ooimpl.CountingStockImpl; 010 011 /** 012 * A Catalog containing {@link CIOpenPurchaseOrders}. 013 */ 014 public class COpenPurchaseOrders extends CatalogImpl { 015 016 /** 017 * ID for serialization. 018 */ 019 private static final long serialVersionUID = 3506320704311968981L; 020 021 /** 022 * @param name the catalogs's name. 023 */ 024 public COpenPurchaseOrders(String name) { 025 super(name); 026 } 027 028 /** 029 * Removes a CatalogItem from this Catalog. 030 * @param ci the CatalogItem to be removed. 031 * @return the removed CatalogItem. 032 */ 033 public CIOpenPurchaseOrders remove(CatalogItem ci) { 034 try { 035 return (CIOpenPurchaseOrders)super.remove(ci, null); 036 } 037 catch (VetoException e) { 038 System.err.println("Fehler beim Löschen aus COpenPurchaseOrders"); 039 e.printStackTrace(); 040 return null; 041 } 042 } 043 044 /** 045 * Gets a CatalogItem from this Catalog. 046 * @param key the searched CatalogItem's key. 047 * @return the searched CatalogItem, <code>null</code> if not found. 048 */ 049 public CIOpenPurchaseOrders get(String key) { 050 try { 051 return (CIOpenPurchaseOrders)super.get(key, null, false); 052 } 053 catch (VetoException e) { 054 System.err.println("Fehler beim Holen eines Elements aus COpenPurchaseOrders"); 055 e.printStackTrace(); 056 return null; 057 } 058 } 059 060 /** 061 * Decreases the number of days to wait for open purchase orders according to the days that passed. 062 * All purchases where the days to wait have dropped to or below zero are summed up and returned. 063 * @param i the number of passed days. 064 * @return the accumulated orders that arrived. 065 */ 066 public CountingStock subtractPassedDays(int i) { 067 CountingStock arrived = new CountingStockImpl("arrived", SMarket.getArticleCatalog()); 068 Iterator it = keySet(null).iterator(); 069 while (it.hasNext()) { 070 CIOpenPurchaseOrders next = get((String)it.next()); 071 fireEditingCatalogItem(next, null); //update remaining days in table view (if open) 072 next.decreaseDaysTillArrival(i); 073 if (next.getDaysTillArrival() <= 0) { 074 remove(next); 075 arrived.addStock(next.getOrders(), null, false); 076 } 077 } 078 return arrived; 079 } 080 }