KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > activemq > kaha > impl > container > ContainerEntrySet


1 /**
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one or more
4  * contributor license agreements. See the NOTICE file distributed with
5  * this work for additional information regarding copyright ownership.
6  * The ASF licenses this file to You under the Apache License, Version 2.0
7  * (the "License"); you may not use this file except in compliance with
8  * the License. You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */

18 package org.apache.activemq.kaha.impl.container;
19
20 import java.util.ArrayList JavaDoc;
21 import java.util.Collection JavaDoc;
22 import java.util.HashSet JavaDoc;
23 import java.util.Iterator JavaDoc;
24 import java.util.List JavaDoc;
25 import java.util.Set JavaDoc;
26
27 /**
28 * Set of Map.Entry objects for a container
29 *
30 * @version $Revision: 1.2 $
31 */

32 public class ContainerEntrySet extends ContainerCollectionSupport implements Set JavaDoc{
33     ContainerEntrySet(MapContainerImpl container){
34         super(container);
35     }
36
37     public boolean contains(Object JavaDoc o){
38         return container.entrySet().contains(o);
39     }
40
41     public Iterator JavaDoc iterator(){
42         return new ContainerEntrySetIterator(container,buildEntrySet().iterator());
43     }
44
45     public Object JavaDoc[] toArray(){
46         return buildEntrySet().toArray();
47     }
48
49     public Object JavaDoc[] toArray(Object JavaDoc[] a){
50         return buildEntrySet().toArray(a);
51     }
52
53     public boolean add(Object JavaDoc o){
54         throw new UnsupportedOperationException JavaDoc("Cannot add here");
55     }
56
57     public boolean remove(Object JavaDoc o){
58         boolean result=false;
59         if(buildEntrySet().remove(o)){
60             ContainerMapEntry entry=(ContainerMapEntry) o;
61             container.remove(entry.getKey());
62         }
63         return result;
64     }
65
66     public boolean containsAll(Collection JavaDoc c){
67         return buildEntrySet().containsAll(c);
68     }
69
70     public boolean addAll(Collection JavaDoc c){
71         throw new UnsupportedOperationException JavaDoc("Cannot add here");
72     }
73
74     public boolean retainAll(Collection JavaDoc c){
75         List JavaDoc tmpList=new ArrayList JavaDoc();
76         for(Iterator JavaDoc i=c.iterator();i.hasNext();){
77             Object JavaDoc o=i.next();
78             if(!contains(o)){
79                 tmpList.add(o);
80             }
81         }
82         boolean result=false;
83         for(Iterator JavaDoc i=tmpList.iterator();i.hasNext();){
84             result|=remove(i.next());
85         }
86         return result;
87     }
88
89     public boolean removeAll(Collection JavaDoc c){
90         boolean result=true;
91         for(Iterator JavaDoc i=c.iterator();i.hasNext();){
92             if(!remove(i.next())){
93                 result=false;
94             }
95         }
96         return result;
97     }
98
99     public void clear(){
100         container.clear();
101     }
102
103     protected Set JavaDoc buildEntrySet(){
104         Set JavaDoc set=new HashSet JavaDoc();
105         for(Iterator JavaDoc i=container.keySet().iterator();i.hasNext();){
106             ContainerMapEntry entry=new ContainerMapEntry(container,i.next());
107             set.add(entry);
108         }
109         return set;
110     }
111 }
112
Popular Tags