001 /** 002 * Licensed to the Apache Software Foundation (ASF) under one or more 003 * contributor license agreements. See the NOTICE file distributed with 004 * this work for additional information regarding copyright ownership. 005 * The ASF licenses this file to You under the Apache License, Version 2.0 006 * (the "License"); you may not use this file except in compliance with 007 * the License. You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017 package org.apache.activemq.kaha.impl.container; 018 019 import java.util.Iterator; 020 import org.apache.activemq.kaha.impl.index.IndexItem; 021 import org.apache.activemq.kaha.impl.index.IndexLinkedList; 022 023 /** 024 * Values collection iterator for the MapContainer 025 * 026 * @version $Revision: 1.2 $ 027 */ 028 public class ContainerValueCollectionIterator implements Iterator { 029 030 protected BaseContainerImpl container; 031 protected IndexLinkedList list; 032 protected IndexItem nextItem; 033 protected IndexItem currentItem; 034 035 ContainerValueCollectionIterator(BaseContainerImpl container, IndexLinkedList list, IndexItem start) { 036 this.container = container; 037 this.list = list; 038 this.currentItem = start; 039 this.nextItem = list.getNextEntry((IndexItem)list.refreshEntry(start)); 040 } 041 042 public boolean hasNext() { 043 return nextItem != null; 044 } 045 046 public Object next() { 047 synchronized (container) { 048 nextItem = (IndexItem)list.refreshEntry(nextItem); 049 currentItem = nextItem; 050 Object result = container.getValue(nextItem); 051 nextItem = list.getNextEntry(nextItem); 052 return result; 053 } 054 } 055 056 public void remove() { 057 synchronized (container) { 058 if (currentItem != null) { 059 currentItem = (IndexItem)list.refreshEntry(currentItem); 060 container.remove(currentItem); 061 } 062 } 063 } 064 }