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.List ; 24 import java.util.Set ; 25 import org.apache.activemq.kaha.impl.index.IndexItem; 26 import org.apache.activemq.kaha.impl.index.IndexLinkedList; 27 28 33 public class ContainerKeySet extends ContainerCollectionSupport implements Set { 34 35 36 ContainerKeySet(MapContainerImpl container){ 37 super(container); 38 } 39 40 41 public boolean contains(Object o){ 42 return container.containsKey(o); 43 } 44 45 public Iterator iterator(){ 46 return new ContainerKeySetIterator(container); 47 } 48 49 public Object [] toArray(){ 50 List list = new ArrayList (); 51 IndexItem item = container.getInternalList().getRoot(); 52 while ((item = container.getInternalList().getNextEntry(item)) != null) { 53 list.add(container.getKey(item)); 54 } 55 return list.toArray(); 56 } 57 58 public Object [] toArray(Object [] a){ 59 List list = new ArrayList (); 60 IndexItem item = container.getInternalList().getRoot(); 61 while ((item = container.getInternalList().getNextEntry(item)) != null) { 62 list.add(container.getKey(item)); 63 } 64 return list.toArray(a); 65 } 66 67 public boolean add(Object o){ 68 throw new UnsupportedOperationException ("Cannot add here"); 69 } 70 71 public boolean remove(Object o){ 72 return container.remove(o) != null; 73 } 74 75 public boolean containsAll(Collection c){ 76 boolean result = true; 77 for (Object key:c) { 78 if (!(result&=container.containsKey(key))) { 79 break; 80 } 81 } 82 return result; 83 } 84 85 public boolean addAll(Collection c){ 86 throw new UnsupportedOperationException ("Cannot add here"); 87 } 88 89 public boolean retainAll(Collection c){ 90 List tmpList = new ArrayList (); 91 for (Iterator i = c.iterator(); i.hasNext(); ){ 92 Object o = i.next(); 93 if (!contains(o)){ 94 tmpList.add(o); 95 } 96 } 97 for(Iterator i = tmpList.iterator(); i.hasNext();){ 98 remove(i.next()); 99 } 100 return !tmpList.isEmpty(); 101 } 102 103 public boolean removeAll(Collection c){ 104 boolean result = true; 105 for (Iterator i = c.iterator(); i.hasNext(); ){ 106 if (!remove(i.next())){ 107 result = false; 108 } 109 } 110 return result; 111 } 112 113 public void clear(){ 114 container.clear(); 115 } 116 117 public String toString() { 118 String result ="ContainerKeySet["; 119 IndexItem item = container.getInternalList().getRoot(); 120 while ((item = container.getInternalList().getNextEntry(item)) != null) { 121 result += container.getKey(item); 122 result += ","; 123 } 124 result +="]"; 125 return result; 126 } 127 } 128 | Popular Tags |