KickJava   Java API By Example, From Geeks To Geeks.

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


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.ListIterator JavaDoc;
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 /**
23  * @version $Revision: 1.2 $
24  */

25 public class ContainerListIterator extends ContainerValueCollectionIterator implements ListIterator JavaDoc{
26
27     protected ContainerListIterator(ListContainerImpl container,IndexLinkedList list,IndexItem start){
28         super(container,list,start);
29     }
30
31     /*
32      * (non-Javadoc)
33      *
34      * @see java.util.ListIterator#hasPrevious()
35      */

36     public boolean hasPrevious(){
37         synchronized(container){
38             nextItem=(IndexItem)list.refreshEntry(nextItem);
39             return list.getPrevEntry(nextItem)!=null;
40         }
41     }
42
43     /*
44      * (non-Javadoc)
45      *
46      * @see java.util.ListIterator#previous()
47      */

48     public Object JavaDoc 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     /*
57      * (non-Javadoc)
58      *
59      * @see java.util.ListIterator#nextIndex()
60      */

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     /*
76      * (non-Javadoc)
77      *
78      * @see java.util.ListIterator#previousIndex()
79      */

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     /*
95      * (non-Javadoc)
96      *
97      * @see java.util.ListIterator#set(E)
98      */

99     public void set(Object JavaDoc o){
100         IndexItem item=((ListContainerImpl)container).internalSet(previousIndex()+1,o);
101         nextItem=item;
102     }
103
104     /*
105      * (non-Javadoc)
106      *
107      * @see java.util.ListIterator#add(E)
108      */

109     public void add(Object JavaDoc o){
110         IndexItem item=((ListContainerImpl)container).internalAdd(previousIndex()+1,o);
111         nextItem=item;
112     }
113 }
114
Popular Tags