1 16 package org.apache.cocoon.portal.coplets.basket; 17 18 import java.io.Serializable ; 19 import java.util.ArrayList ; 20 import java.util.Iterator ; 21 import java.util.List ; 22 23 24 30 public abstract class ContentStore implements Serializable { 31 32 33 protected final List items = new ArrayList (); 34 35 36 protected final String id; 37 38 41 public ContentStore(String id) { 42 this.id = id; 43 } 44 45 48 public String getId() { 49 return this.id; 50 } 51 52 55 public Object getItem(int index) { 56 return this.items.get(index); 57 } 58 59 62 public void addItem(Object item) { 63 this.items.add(item); 64 } 65 66 69 public Iterator getIterator() { 70 return this.items.iterator(); 71 } 72 73 76 public void removeItem(Object item) { 77 this.items.remove(item); 78 } 79 80 83 public int size() { 84 return this.items.size(); 85 } 86 87 90 public int contentSize() { 91 int size = 0; 92 Iterator i = this.items.iterator(); 93 while (i.hasNext()) { 94 Object item = i.next(); 95 if ( item instanceof ContentItem ) { 96 int v = ((ContentItem)item).size(); 97 if ( v != -1 ) { 98 size += v; 99 } 100 } 101 } 102 return size; 103 } 104 105 108 public Object getItem(long id) { 109 Iterator i = this.items.iterator(); 110 while (i.hasNext()) { 111 Object item = i.next(); 112 if ( item instanceof AbstractItem ) { 113 if (((AbstractItem)item).getId() == id ) { 114 return item; 115 } 116 } 117 } 118 return null; 119 } 120 } 121 122 | Popular Tags |