1 18 package org.apache.activemq.kaha.impl.container; 19 20 import java.util.ArrayList ; 21 import java.util.Collection ; 22 import java.util.Iterator ; 23 import java.util.LinkedList ; 24 import java.util.List ; 25 26 import org.apache.activemq.kaha.impl.index.IndexItem; 27 import org.apache.activemq.kaha.impl.index.IndexLinkedList; 28 29 34 class ContainerValueCollection extends ContainerCollectionSupport implements Collection { 35 36 37 ContainerValueCollection(MapContainerImpl container){ 38 super(container); 39 } 40 41 42 43 public boolean contains(Object o){ 44 return container.containsValue(o); 45 } 46 47 48 public Iterator iterator(){ 49 IndexLinkedList list=container.getItemList(); 50 return new ContainerValueCollectionIterator(container,list,list.getRoot()); 51 } 52 53 54 public Object [] toArray(){ 55 Object [] result = null; 56 IndexLinkedList list = container.getItemList(); 57 synchronized(list){ 58 result = new Object [list.size()]; 59 IndexItem item = list.getFirst(); 60 int count = 0; 61 while (item != null){ 62 Object value=container.getValue(item); 63 result[count++] = value; 64 65 item = list.getNextEntry(item); 66 } 67 68 69 } 70 return result; 71 } 72 73 public Object [] toArray(Object [] result){ 74 IndexLinkedList list=container.getItemList(); 75 synchronized(list){ 76 if(result.length<=list.size()){ 77 IndexItem item = list.getFirst(); 78 int count = 0; 79 while (item != null){ 80 Object value=container.getValue(item); 81 result[count++] = value; 82 83 item = list.getNextEntry(item); 84 } 85 } 86 } 87 return result; 88 } 89 90 91 public boolean add(Object o){ 92 throw new UnsupportedOperationException ("Can't add an object here"); 93 } 94 95 96 public boolean remove(Object o){ 97 return container.removeValue(o); 98 } 99 100 101 public boolean containsAll(Collection c){ 102 boolean result = !c.isEmpty(); 103 for (Iterator i = c.iterator(); i.hasNext(); ){ 104 if (!contains(i.next())){ 105 result = false; 106 break; 107 } 108 } 109 return result; 110 } 111 112 113 public boolean addAll(Collection c){ 114 throw new UnsupportedOperationException ("Can't add everything here!"); 115 } 116 117 118 public boolean removeAll(Collection c){ 119 boolean result = true; 120 for (Iterator i = c.iterator(); i.hasNext(); ){ 121 Object obj = i.next(); 122 result&=remove(obj); 123 } 124 return result; 125 } 126 127 128 public boolean retainAll(Collection c){ 129 List tmpList = new ArrayList (); 130 for (Iterator i = c.iterator(); i.hasNext(); ){ 131 Object o = i.next(); 132 if (!contains(o)){ 133 tmpList.add(o); 134 } 135 } 136 for(Iterator i = tmpList.iterator(); i.hasNext();){ 137 remove(i.next()); 138 } 139 return !tmpList.isEmpty(); 140 } 141 142 143 public void clear(){ 144 container.clear(); 145 } 146 } 147 | Popular Tags |