KickJava   Java API By Example, From Geeks To Geeks.

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


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.io.IOException JavaDoc;
18 import java.util.ArrayList JavaDoc;
19 import java.util.Collection JavaDoc;
20 import java.util.Iterator JavaDoc;
21 import java.util.LinkedList JavaDoc;
22 import java.util.List JavaDoc;
23 import java.util.ListIterator JavaDoc;
24 import org.apache.activemq.kaha.ContainerId;
25 import org.apache.activemq.kaha.ListContainer;
26 import org.apache.activemq.kaha.Marshaller;
27 import org.apache.activemq.kaha.RuntimeStoreException;
28 import org.apache.activemq.kaha.Store;
29 import org.apache.activemq.kaha.StoreEntry;
30 import org.apache.activemq.kaha.StoreLocation;
31 import org.apache.activemq.kaha.impl.DataManager;
32 import org.apache.activemq.kaha.impl.data.Item;
33 import org.apache.activemq.kaha.impl.index.IndexItem;
34 import org.apache.activemq.kaha.impl.index.IndexManager;
35 import org.apache.commons.logging.Log;
36 import org.apache.commons.logging.LogFactory;
37
38 /**
39  * Implementation of a ListContainer
40  *
41  * @version $Revision: 1.2 $
42  */

43 public class ListContainerImpl extends BaseContainerImpl implements ListContainer{
44
45     private static final Log log=LogFactory.getLog(ListContainerImpl.class);
46     protected Marshaller marshaller=Store.ObjectMarshaller;
47    
48
49     public ListContainerImpl(ContainerId id,IndexItem root,IndexManager indexManager,DataManager dataManager,
50             boolean persistentIndex) throws IOException JavaDoc{
51         super(id,root,indexManager,dataManager,persistentIndex);
52     }
53
54     /*
55      * (non-Javadoc)
56      *
57      * @see org.apache.activemq.kaha.ListContainer#load()
58      */

59     public synchronized void load(){
60         checkClosed();
61         if(!loaded){
62             if(!loaded){
63                 loaded=true;
64                 try{
65                     init();
66                     long nextItem=root.getNextItem();
67                     while(nextItem!=Item.POSITION_NOT_SET){
68                         IndexItem item=indexManager.getIndex(nextItem);
69                         indexList.add(item);
70                         itemAdded(item,indexList.size()-1,getValue(item));
71                         nextItem=item.getNextItem();
72                     }
73                 }catch(IOException JavaDoc e){
74                     log.error("Failed to load container "+getId(),e);
75                     throw new RuntimeStoreException(e);
76                 }
77             }
78         }
79     }
80
81     /*
82      * (non-Javadoc)
83      *
84      * @see org.apache.activemq.kaha.ListContainer#unload()
85      */

86     public synchronized void unload(){
87         checkClosed();
88         if(loaded){
89             loaded=false;
90             indexList.clear();
91             
92         }
93     }
94
95     /*
96      * (non-Javadoc)
97      *
98      * @see org.apache.activemq.kaha.ListContainer#setKeyMarshaller(org.apache.activemq.kaha.Marshaller)
99      */

100     public synchronized void setMarshaller(Marshaller marshaller){
101         checkClosed();
102         this.marshaller=marshaller;
103     }
104
105     public synchronized boolean equals(Object JavaDoc obj){
106         load();
107         boolean result=false;
108         if(obj!=null&&obj instanceof List JavaDoc){
109             List JavaDoc other=(List JavaDoc)obj;
110             result=other.size()==size();
111             if(result){
112                 for(int i=0;i<indexList.size();i++){
113                     Object JavaDoc o1=other.get(i);
114                     Object JavaDoc o2=get(i);
115                     result=o1==o2||(o1!=null&&o2!=null&&o1.equals(o2));
116                     if(!result){
117                         break;
118                     }
119                 }
120             }
121         }
122         return result;
123     }
124
125     /*
126      * (non-Javadoc)
127      *
128      * @see org.apache.activemq.kaha.ListContainer#size()
129      */

130     public synchronized int size(){
131         load();
132         return indexList.size();
133     }
134
135     /*
136      * (non-Javadoc)
137      *
138      * @see org.apache.activemq.kaha.ListContainer#addFirst(java.lang.Object)
139      */

140     public synchronized void addFirst(Object JavaDoc o){
141         internalAddFirst(o);
142     }
143
144     /*
145      * (non-Javadoc)
146      *
147      * @see org.apache.activemq.kaha.ListContainer#addLast(java.lang.Object)
148      */

149     public synchronized void addLast(Object JavaDoc o){
150         internalAddLast(o);
151     }
152
153     /*
154      * (non-Javadoc)
155      *
156      * @see org.apache.activemq.kaha.ListContainer#removeFirst()
157      */

158     public synchronized Object JavaDoc removeFirst(){
159         load();
160         Object JavaDoc result=null;
161         IndexItem item=(IndexItem)indexList.getFirst();
162         if(item!=null){
163             itemRemoved(0);
164             result=getValue(item);
165             IndexItem prev=root;
166             IndexItem next=indexList.size()>1?(IndexItem)indexList.get(1):null;
167             indexList.removeFirst();
168             delete(item,prev,next);
169             item=null;
170         }
171         return result;
172     }
173
174     /*
175      * (non-Javadoc)
176      *
177      * @see org.apache.activemq.kaha.ListContainer#removeLast()
178      */

179     public synchronized Object JavaDoc removeLast(){
180         load();
181         Object JavaDoc result=null;
182         IndexItem last=indexList.getLast();
183         if(last!=null){
184             itemRemoved(indexList.size()-1);
185             result=getValue(last);
186             IndexItem prev=indexList.getPrevEntry(last);
187             IndexItem next=null;
188             indexList.removeLast();
189             delete(last,prev,next);
190         }
191         return result;
192     }
193
194     /*
195      * (non-Javadoc)
196      *
197      * @see java.util.List#isEmpty()
198      */

199     public synchronized boolean isEmpty(){
200         load();
201         return indexList.isEmpty();
202     }
203
204     /*
205      * (non-Javadoc)
206      *
207      * @see java.util.List#contains(java.lang.Object)
208      */

209     public synchronized boolean contains(Object JavaDoc o){
210         load();
211         boolean result=false;
212         if(o!=null){
213             IndexItem next=indexList.getFirst();
214             while(next!=null){
215                 Object JavaDoc value=getValue(next);
216                 if(value!=null&&value.equals(o)){
217                     result=true;
218                     break;
219                 }
220                 next=indexList.getNextEntry(next);
221             }
222         }
223         return result;
224     }
225
226     /*
227      * (non-Javadoc)
228      *
229      * @see java.util.List#iterator()
230      */

231     public synchronized Iterator JavaDoc iterator(){
232         load();
233         return listIterator();
234     }
235
236     /*
237      * (non-Javadoc)
238      *
239      * @see java.util.List#toArray()
240      */

241     public synchronized Object JavaDoc[] toArray(){
242         load();
243         List JavaDoc tmp=new ArrayList JavaDoc(indexList.size());
244         IndexItem next=indexList.getFirst();
245         while(next!=null){
246             Object JavaDoc value=getValue(next);
247             tmp.add(value);
248             next=indexList.getNextEntry(next);
249         }
250         return tmp.toArray();
251     }
252
253     /*
254      * (non-Javadoc)
255      *
256      * @see java.util.List#toArray(T[])
257      */

258     public synchronized Object JavaDoc[] toArray(Object JavaDoc[] a){
259         load();
260         List JavaDoc tmp=new ArrayList JavaDoc(indexList.size());
261         IndexItem next=indexList.getFirst();
262         while(next!=null){
263             Object JavaDoc value=getValue(next);
264             tmp.add(value);
265             next=indexList.getNextEntry(next);
266         }
267         return tmp.toArray(a);
268     }
269
270     /*
271      * (non-Javadoc)
272      *
273      * @see java.util.List#add(E)
274      */

275     public synchronized boolean add(Object JavaDoc o){
276         load();
277         addLast(o);
278         return true;
279     }
280
281     /*
282      * (non-Javadoc)
283      *
284      * @see java.util.List#remove(java.lang.Object)
285      */

286     public synchronized boolean remove(Object JavaDoc o){
287         load();
288         boolean result=false;
289         int pos=0;
290         IndexItem next=indexList.getFirst();
291         while(next!=null){
292             Object JavaDoc value=getValue(next);
293             if(value!=null&&value.equals(o)){
294                 remove(next);
295                 itemRemoved(pos);
296                 result=true;
297                 break;
298             }
299             next=indexList.getNextEntry(next);
300             pos++;
301         }
302         return result;
303     }
304
305     protected synchronized void remove(IndexItem item){
306         IndexItem prev=indexList.getPrevEntry(item);
307         IndexItem next=indexList.getNextEntry(item);
308         indexList.remove(item);
309         delete(item,prev,next);
310     }
311
312     /*
313      * (non-Javadoc)
314      *
315      * @see java.util.List#containsAll(java.util.Collection)
316      */

317     public synchronized boolean containsAll(Collection JavaDoc c){
318         load();
319         boolean result=false;
320         for(Iterator JavaDoc i=c.iterator();i.hasNext();){
321             Object JavaDoc obj=i.next();
322             if(!(result=contains(obj))){
323                 result=false;
324                 break;
325             }
326         }
327         return result;
328     }
329
330     /*
331      * (non-Javadoc)
332      *
333      * @see java.util.List#addAll(java.util.Collection)
334      */

335     public synchronized boolean addAll(Collection JavaDoc c){
336         load();
337         for(Iterator JavaDoc i=c.iterator();i.hasNext();){
338             add(i.next());
339         }
340         return true;
341     }
342
343     /*
344      * (non-Javadoc)
345      *
346      * @see java.util.List#addAll(int, java.util.Collection)
347      */

348     public synchronized boolean addAll(int index,Collection JavaDoc c){
349         load();
350         boolean result=false;
351         ListIterator JavaDoc e1=listIterator(index);
352         Iterator JavaDoc e2=c.iterator();
353         while(e2.hasNext()){
354             e1.add(e2.next());
355             result=true;
356         }
357         return result;
358     }
359
360     /*
361      * (non-Javadoc)
362      *
363      * @see java.util.List#removeAll(java.util.Collection)
364      */

365     public synchronized boolean removeAll(Collection JavaDoc c){
366         load();
367         boolean result=true;
368         for(Iterator JavaDoc i=c.iterator();i.hasNext();){
369             Object JavaDoc obj=i.next();
370             result&=remove(obj);
371         }
372         return result;
373     }
374
375     /*
376      * (non-Javadoc)
377      *
378      * @see java.util.List#retainAll(java.util.Collection)
379      */

380     public synchronized boolean retainAll(Collection JavaDoc c){
381         load();
382         List JavaDoc tmpList=new ArrayList JavaDoc();
383         IndexItem next=indexList.getFirst();
384         while(next!=null){
385             Object JavaDoc o=getValue(next);
386             if(!c.contains(o)){
387                 tmpList.add(o);
388             }
389             next=indexList.getNextEntry(next);
390         }
391         for(Iterator JavaDoc i=tmpList.iterator();i.hasNext();){
392             remove(i.next());
393         }
394         return !tmpList.isEmpty();
395     }
396
397     /*
398      * (non-Javadoc)
399      *
400      * @see java.util.List#clear()
401      */

402     public synchronized void clear(){
403         checkClosed();
404         super.clear();
405         doClear();
406         
407     }
408
409     /*
410      * (non-Javadoc)
411      *
412      * @see java.util.List#get(int)
413      */

414     public synchronized Object JavaDoc get(int index){
415         load();
416         Object JavaDoc result = null;
417         IndexItem item=indexList.get(index);
418         if(item!=null){
419             result=getValue(item);
420         }
421         return result;
422     }
423
424     /*
425      * (non-Javadoc)
426      *
427      * @see java.util.List#set(int, E)
428      */

429     public synchronized Object JavaDoc set(int index,Object JavaDoc element){
430         load();
431         Object JavaDoc result=null;
432         IndexItem replace=indexList.isEmpty()?null:(IndexItem)indexList.get(index);
433         IndexItem prev=(indexList.isEmpty()||(index-1)<0)?null:(IndexItem)indexList.get(index-1);
434         IndexItem next=(indexList.isEmpty()||(index+1)>=size())?null:(IndexItem)indexList.get(index+1);
435         result=getValue(replace);
436         indexList.remove(index);
437         delete(replace,prev,next);
438         itemRemoved(index);
439         add(index,element);
440         return result;
441     }
442
443     protected synchronized IndexItem internalSet(int index,Object JavaDoc element){
444         IndexItem replace=indexList.isEmpty()?null:(IndexItem)indexList.get(index);
445         IndexItem prev=(indexList.isEmpty()||(index-1)<0)?null:(IndexItem)indexList.get(index-1);
446         IndexItem next=(indexList.isEmpty()||(index+1)>=size())?null:(IndexItem)indexList.get(index+1);
447         indexList.remove(index);
448         delete(replace,prev,next);
449         itemRemoved(index);
450         return internalAdd(index,element);
451     }
452
453     /*
454      * (non-Javadoc)
455      *
456      * @see java.util.List#add(int, E)
457      */

458     public synchronized void add(int index,Object JavaDoc element){
459         load();
460         IndexItem item=insert(index,element);
461         indexList.add(index,item);
462         itemAdded(item,index,element);
463     }
464
465     protected synchronized StoreEntry internalAddLast(Object JavaDoc o){
466         load();
467         IndexItem item=writeLast(o);
468         indexList.addLast(item);
469         itemAdded(item,indexList.size()-1,o);
470         return item;
471     }
472
473     protected synchronized StoreEntry internalAddFirst(Object JavaDoc o){
474         load();
475         IndexItem item=writeFirst(o);
476         indexList.addFirst(item);
477         itemAdded(item,0,o);
478         return item;
479     }
480
481     protected synchronized IndexItem internalAdd(int index,Object JavaDoc element){
482         load();
483         IndexItem item=insert(index,element);
484         indexList.add(index,item);
485         itemAdded(item,index,element);
486         return item;
487     }
488
489     protected synchronized StoreEntry internalGet(int index){
490         load();
491         if(index>=0&&index<indexList.size()){
492             return indexList.get(index);
493         }
494         return null;
495     }
496
497     /*
498      * (non-Javadoc)
499      *
500      * @see org.apache.activemq.kaha.ListContainer#doRemove(int)
501      */

502     public synchronized boolean doRemove(int index){
503         load();
504         boolean result=false;
505         IndexItem item=indexList.get(index);
506         if(item!=null){
507             result=true;
508             IndexItem prev=indexList.getPrevEntry(item);
509             prev=prev!=null?prev:root;
510             IndexItem next=indexList.getNextEntry(prev);
511             indexList.remove(index);
512             itemRemoved(index);
513             delete(item,prev,next);
514         }
515         return result;
516     }
517
518     /*
519      * (non-Javadoc)
520      *
521      * @see java.util.List#remove(int)
522      */

523     public synchronized Object JavaDoc remove(int index){
524         load();
525         Object JavaDoc result=null;
526         IndexItem item=indexList.get(index);
527         if(item!=null){
528             itemRemoved(index);
529             result=getValue(item);
530             IndexItem prev=indexList.getPrevEntry(item);
531             prev=prev!=null?prev:root;
532             IndexItem next=indexList.getNextEntry(item);
533             indexList.remove(index);
534             delete(item,prev,next);
535         }
536         return result;
537     }
538
539     /*
540      * (non-Javadoc)
541      *
542      * @see java.util.List#indexOf(java.lang.Object)
543      */

544     public synchronized int indexOf(Object JavaDoc o){
545         load();
546         int result=-1;
547         if(o!=null){
548             int count=0;
549             IndexItem next=indexList.getFirst();
550             while(next!=null){
551                 Object JavaDoc value=getValue(next);
552                 if(value!=null&&value.equals(o)){
553                     result=count;
554                     break;
555                 }
556                 count++;
557                 next=indexList.getNextEntry(next);
558             }
559         }
560         return result;
561     }
562
563     /*
564      * (non-Javadoc)
565      *
566      * @see java.util.List#lastIndexOf(java.lang.Object)
567      */

568     public synchronized int lastIndexOf(Object JavaDoc o){
569         load();
570         int result=-1;
571         if(o!=null){
572             int count=indexList.size()-1;
573             IndexItem next=indexList.getLast();
574             while(next!=null){
575                 Object JavaDoc value=getValue(next);
576                 if(value!=null&&value.equals(o)){
577                     result=count;
578                     break;
579                 }
580                 count--;
581                 next=indexList.getPrevEntry(next);
582             }
583         }
584         return result;
585     }
586
587     /*
588      * (non-Javadoc)
589      *
590      * @see java.util.List#listIterator()
591      */

592     public synchronized ListIterator JavaDoc listIterator(){
593         load();
594         IndexItem start= indexList.getFirst();
595         return new ContainerListIterator(this,indexList,indexList.getRoot());
596     }
597
598     /*
599      * (non-Javadoc)
600      *
601      * @see java.util.List#listIterator(int)
602      */

603     public synchronized ListIterator JavaDoc listIterator(int index){
604         load();
605         IndexItem start = (index-1) >0 ?indexList.get(index-1):indexList.getRoot();
606         return new ContainerListIterator(this,indexList,start);
607     }
608
609     /*
610      * (non-Javadoc)
611      *
612      * @see java.util.List#subList(int, int)
613      */

614     public synchronized List JavaDoc subList(int fromIndex,int toIndex){
615         load();
616         List JavaDoc result=new ArrayList JavaDoc();
617         int count=fromIndex;
618         IndexItem next=indexList.get(fromIndex);
619         while(next!=null&&count++<toIndex){
620             result.add(getValue(next));
621             next=indexList.getNextEntry(next);
622         }
623         return result;
624     }
625
626     /**
627      * add an Object to the list but get a StoreEntry of its position
628      *
629      * @param object
630      * @return the entry in the Store
631      */

632     public synchronized StoreEntry placeLast(Object JavaDoc object){
633         StoreEntry item=internalAddLast(object);
634         return item;
635     }
636
637     /**
638      * insert an Object in first position int the list but get a StoreEntry of its position
639      *
640      * @param object
641      * @return the location in the Store
642      */

643     public synchronized StoreEntry placeFirst(Object JavaDoc object){
644         StoreEntry item=internalAddFirst(object);
645         return item;
646     }
647
648     /**
649      * @param entry
650      * @param object
651      * @see org.apache.activemq.kaha.ListContainer#update(org.apache.activemq.kaha.StoreEntry, java.lang.Object)
652      */

653     public synchronized void update(StoreEntry entry,Object JavaDoc object){
654         try{
655             dataManager.updateItem(entry.getValueDataItem(),marshaller,object);
656         }catch(IOException JavaDoc e){
657             throw new RuntimeException JavaDoc(e);
658         }
659     }
660
661     /**
662      * Retrieve an Object from the Store by its location
663      *
664      * @param entry
665      * @return the Object at that entry
666      */

667     public synchronized Object JavaDoc get(final StoreEntry entry){
668         load();
669         StoreEntry entryToUse = refresh(entry);
670         return getValue(entryToUse);
671     }
672
673     /**
674      * remove the Object at the StoreEntry
675      *
676      * @param entry
677      * @return true if successful
678      */

679     public synchronized boolean remove(StoreEntry entry){
680         IndexItem item=(IndexItem)entry;
681         load();
682         boolean result=false;
683         if(item!=null){
684            
685             remove(item);
686             result = true;
687         }
688         return result;
689     }
690
691     /**
692      * Get the StoreEntry for the first item of the list
693      *
694      * @return the first StoreEntry or null if the list is empty
695      */

696     public synchronized StoreEntry getFirst(){
697         load();
698         return indexList.getFirst();
699     }
700
701     /**
702      * Get the StoreEntry for the last item of the list
703      *
704      * @return the last StoreEntry or null if the list is empty
705      */

706     public synchronized StoreEntry getLast(){
707         load();
708         return indexList.getLast();
709     }
710
711     /**
712      * Get the next StoreEntry from the list
713      *
714      * @param entry
715      * @return the next StoreEntry or null
716      */

717     public synchronized StoreEntry getNext(StoreEntry entry){
718         load();
719         IndexItem item=(IndexItem)entry;
720         return indexList.getNextEntry(item);
721     }
722
723     /**
724      * Get the previous StoreEntry from the list
725      *
726      * @param entry
727      * @return the previous store entry or null
728      */

729     public synchronized StoreEntry getPrevious(StoreEntry entry){
730         load();
731         IndexItem item=(IndexItem)entry;
732         return indexList.getPrevEntry(item);
733     }
734     
735     /**
736      * It's possible that a StoreEntry could be come stale
737      * this will return an upto date entry for the StoreEntry position
738      * @param entry old entry
739      * @return a refreshed StoreEntry
740      */

741     public synchronized StoreEntry refresh(StoreEntry entry) {
742         load();
743         return indexList.getEntry(entry);
744     }
745
746     protected synchronized IndexItem writeLast(Object JavaDoc value){
747         IndexItem index=null;
748         try{
749             if(value!=null){
750                 StoreLocation data=dataManager.storeDataItem(marshaller,value);
751                 index=indexManager.createNewIndex();
752                 index.setValueData(data);
753                 IndexItem prev=indexList.getLast();
754                 prev=prev!=null?prev:root;
755                 IndexItem next=indexList.getNextEntry(prev);
756                 prev.setNextItem(index.getOffset());
757                 index.setPreviousItem(prev.getOffset());
758                 updateIndexes(prev);
759                 if(next!=null){
760                     next.setPreviousItem(index.getOffset());
761                     index.setNextItem(next.getOffset());
762                     updateIndexes(next);
763                 }
764                 storeIndex(index);
765             }
766         }catch(IOException JavaDoc e){
767             log.error("Failed to write "+value,e);
768             throw new RuntimeStoreException(e);
769         }
770         return index;
771     }
772
773     protected synchronized IndexItem writeFirst(Object JavaDoc value){
774         IndexItem index=null;
775         try{
776             if(value!=null){
777                 StoreLocation data=dataManager.storeDataItem(marshaller,value);
778                 index=indexManager.createNewIndex();
779                 index.setValueData(data);
780                 IndexItem prev=root;
781                 IndexItem next=indexList.getNextEntry(prev);
782                 prev.setNextItem(index.getOffset());
783                 index.setPreviousItem(prev.getOffset());
784                 updateIndexes(prev);
785                 if(next!=null){
786                     next.setPreviousItem(index.getOffset());
787                     index.setNextItem(next.getOffset());
788                     updateIndexes(next);
789                 }
790                 storeIndex(index);
791             }
792         }catch(IOException JavaDoc e){
793             log.error("Failed to write "+value,e);
794             throw new RuntimeStoreException(e);
795         }
796         return index;
797     }
798
799     protected synchronized IndexItem insert(int insertPos,Object JavaDoc value){
800         IndexItem index=null;
801         try{
802             if(value!=null){
803                 StoreLocation data=dataManager.storeDataItem(marshaller,value);
804                 index=indexManager.createNewIndex();
805                 index.setValueData(data);
806                 IndexItem prev=null;
807                 IndexItem next=null;
808                 if(insertPos<=0){
809                     prev=root;
810                     next=indexList.getNextEntry(root);
811                 }else if(insertPos>=indexList.size()){
812                     prev=indexList.getLast();
813                     next=null;
814                 }else{
815                     prev=indexList.get(insertPos);
816                     prev=prev!=null?prev:root;
817                     next=indexList.getNextEntry(prev);
818                 }
819                 prev.setNextItem(index.getOffset());
820                 index.setPreviousItem(prev.getOffset());
821                 updateIndexes(prev);
822                 if(next!=null){
823                     next.setPreviousItem(index.getOffset());
824                     index.setNextItem(next.getOffset());
825                     updateIndexes(next);
826                 }
827                 storeIndex(index);
828             }
829         }catch(IOException JavaDoc e){
830             log.error("Failed to insert "+value,e);
831             throw new RuntimeStoreException(e);
832         }
833         return index;
834     }
835
836     protected synchronized Object JavaDoc getValue(StoreEntry item){
837         Object JavaDoc result=null;
838         if(item!=null){
839             try{
840                 StoreLocation data=item.getValueDataItem();
841                 result=dataManager.readItem(marshaller,data);
842             }catch(IOException JavaDoc e){
843                 log.error("Failed to get value for "+item,e);
844                 throw new RuntimeStoreException(e);
845             }
846         }
847         return result;
848     }
849
850     /**
851      * @return a string representation of this collection.
852      */

853     public synchronized String JavaDoc toString(){
854         StringBuffer JavaDoc result=new StringBuffer JavaDoc();
855         result.append("[");
856         Iterator JavaDoc i=iterator();
857         boolean hasNext=i.hasNext();
858         while(hasNext){
859             Object JavaDoc o=i.next();
860             result.append(String.valueOf(o));
861             hasNext=i.hasNext();
862             if(hasNext)
863                 result.append(", ");
864         }
865         result.append("]");
866         return result.toString();
867     }
868
869     protected synchronized void itemAdded(IndexItem item,int pos,Object JavaDoc value){
870         
871     }
872
873     protected synchronized void itemRemoved(int pos){
874         
875     }
876 }
877
Popular Tags