1 14 15 package org.apache.activemq.kaha.impl.container; 16 17 import java.util.ListIterator ; 18 import org.apache.activemq.kaha.StoreEntry; 19 import org.apache.activemq.kaha.impl.index.IndexItem; 20 import org.apache.activemq.kaha.impl.index.IndexLinkedList; 21 22 25 public class ContainerListIterator extends ContainerValueCollectionIterator implements ListIterator { 26 27 protected ContainerListIterator(ListContainerImpl container,IndexLinkedList list,IndexItem start){ 28 super(container,list,start); 29 } 30 31 36 public boolean hasPrevious(){ 37 synchronized(container){ 38 nextItem=(IndexItem)list.refreshEntry(nextItem); 39 return list.getPrevEntry(nextItem)!=null; 40 } 41 } 42 43 48 public Object previous(){ 49 synchronized(container){ 50 nextItem=(IndexItem)list.refreshEntry(nextItem); 51 nextItem=list.getPrevEntry(nextItem); 52 return nextItem!=null?container.getValue(nextItem):null; 53 } 54 } 55 56 61 public int nextIndex(){ 62 int result=-1; 63 if(nextItem!=null){ 64 synchronized(container){ 65 nextItem=(IndexItem)list.refreshEntry(nextItem); 66 StoreEntry next=list.getNextEntry(nextItem); 67 if(next!=null){ 68 result=container.getInternalList().indexOf(next); 69 } 70 } 71 } 72 return result; 73 } 74 75 80 public int previousIndex(){ 81 int result=-1; 82 if(nextItem!=null){ 83 synchronized(container){ 84 nextItem=(IndexItem)list.refreshEntry(nextItem); 85 StoreEntry prev=list.getPrevEntry(nextItem); 86 if(prev!=null){ 87 result=container.getInternalList().indexOf(prev); 88 } 89 } 90 } 91 return result; 92 } 93 94 99 public void set(Object o){ 100 IndexItem item=((ListContainerImpl)container).internalSet(previousIndex()+1,o); 101 nextItem=item; 102 } 103 104 109 public void add(Object o){ 110 IndexItem item=((ListContainerImpl)container).internalAdd(previousIndex()+1,o); 111 nextItem=item; 112 } 113 } 114 | Popular Tags |