KickJava   Java API By Example, From Geeks To Geeks.

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


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

14
15 package org.apache.activemq.kaha.impl.container;
16
17 import java.util.Iterator JavaDoc;
18 import org.apache.activemq.kaha.impl.index.IndexItem;
19 import org.apache.activemq.kaha.impl.index.IndexLinkedList;
20
21 /**
22  * Values collection iterator for the MapContainer
23  *
24  * @version $Revision: 1.2 $
25  */

26 public class ContainerValueCollectionIterator implements Iterator JavaDoc{
27
28     protected BaseContainerImpl container;
29     protected IndexLinkedList list;
30     protected IndexItem nextItem;
31     protected IndexItem currentItem;
32
33     ContainerValueCollectionIterator(BaseContainerImpl container,IndexLinkedList list,IndexItem start){
34         this.container=container;
35         this.list=list;
36         this.currentItem=start;
37         this.nextItem=list.getNextEntry((IndexItem)list.refreshEntry(start));
38     }
39
40     public boolean hasNext(){
41         return nextItem!=null;
42     }
43
44     public Object JavaDoc next(){
45         synchronized(container){
46             nextItem=(IndexItem)list.refreshEntry(nextItem);
47             currentItem=nextItem;
48             Object JavaDoc result=container.getValue(nextItem);
49             nextItem=list.getNextEntry(nextItem);
50             return result;
51         }
52     }
53
54     public void remove(){
55         synchronized(container){
56             if(currentItem!=null){
57                 currentItem=(IndexItem)list.refreshEntry(currentItem);
58                 container.remove(currentItem);
59             }
60         }
61     }
62 }
63
Popular Tags