1 4 package com.openedit.archive.collection; 5 6 import java.util.ArrayList ; 7 import java.util.Iterator ; 8 import java.util.List ; 9 10 import com.openedit.store.Product; 11 12 public class Collection 13 { 14 protected String fieldId; 15 protected String fieldName; 16 protected List fieldCollectionItems; 17 18 public Collection() 19 { 20 21 } 22 23 public String getId() 24 { 25 return fieldId; 26 } 27 public void setId(String inId) 28 { 29 fieldId = inId; 30 } 31 public String getName() 32 { 33 return fieldName; 34 } 35 public void setName(String inName) 36 { 37 fieldName = inName; 38 } 39 public boolean isEmpty() 40 { 41 return fieldCollectionItems == null || fieldCollectionItems.size() == 0; 42 } 43 public boolean hasItems() 44 { 45 return fieldCollectionItems != null && fieldCollectionItems.size() > 0; 46 } 47 48 public List getCollectionItems() 49 { 50 if (fieldCollectionItems == null) 51 { 52 fieldCollectionItems = new ArrayList (); 53 54 } 55 56 return fieldCollectionItems; 57 } 58 public void setCollectionItems(List inCollectionItems) 59 { 60 fieldCollectionItems = inCollectionItems; 61 } 62 public void addItem(CollectionItem inItem) 63 { 64 getCollectionItems().add(inItem); 65 } 66 public boolean containsProduct(String inId) 67 { 68 if( fieldCollectionItems == null) 69 { 70 return false; 71 } 72 for (Iterator iter = getCollectionItems().iterator(); iter.hasNext();) 73 { 74 CollectionItem item = (CollectionItem) iter.next(); 75 Product prod = item.getProduct(); 76 77 if( prod != null && prod.getId().equals(inId)) 78 { 79 return true; 80 } 81 } 82 return false; 83 } 84 public boolean containsProduct(Product inProduct) 85 { 86 return containsProduct(inProduct.getId()); 87 } 88 public void removeItem(String inProductid) 89 { 90 CollectionItem found = null; 91 for (Iterator iter = getCollectionItems().iterator(); iter.hasNext();) 92 { 93 CollectionItem item = (CollectionItem) iter.next(); 94 if( item.getProduct() == null || item.getProduct().getId().equals(inProductid)) 95 { 96 found = item; 97 break; 98 } 99 } 100 if( found != null) 101 { 102 removeItem(found); 103 } 104 } 105 public void removeItem(CollectionItem inFound) 106 { 107 getCollectionItems().remove(inFound); 108 } 109 public void clear() 110 { 111 getCollectionItems().clear(); 112 } 113 } 114 | Popular Tags |