KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > myoodb > collectable > IteratorDbImpl


1 ///////////////////////////////////////////////////////////////////////////////
2
//
3
// Copyright (C) 2003-@year@ by Thomas M. Hazel, MyOODB (www.myoodb.org)
4
//
5
// All Rights Reserved
6
//
7
// This program is free software; you can redistribute it and/or modify
8
// it under the terms of the GNU General Public License and GNU Library
9
// General Public License as published by the Free Software Foundation;
10
// either version 2, or (at your option) any later version.
11
//
12
// This program is distributed in the hope that it will be useful,
13
// but WITHOUT ANY WARRANTY; without even the implied warranty of
14
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
// GNU General Public License and GNU Library General Public License
16
// for more details.
17
//
18
// You should have received a copy of the GNU General Public License
19
// and GNU Library General Public License along with this program; if
20
// not, write to the Free Software Foundation, 675 Mass Ave, Cambridge,
21
// MA 02139, USA.
22
//
23
///////////////////////////////////////////////////////////////////////////////
24
package org.myoodb.collectable;
25
26 public class IteratorDbImpl extends org.myoodb.MyOodbObject implements Iterator
27 {
28     private int m_index;
29     private java.util.Collection JavaDoc m_collection;
30
31     public IteratorDbImpl(java.util.Collection JavaDoc collection)
32     {
33         m_index = 0;
34         m_collection = collection;
35     }
36
37     public boolean hasNext()
38     {
39         return m_index < m_collection.size();
40     }
41
42     public Object JavaDoc next()
43     {
44         Object JavaDoc retval = null;
45
46         if (hasNext() == true)
47         {
48             m_index++;
49
50             java.util.Iterator JavaDoc iter = m_collection.iterator();
51             for (int i = 1; i <= m_index; i++)
52             {
53                 Object JavaDoc tmp = iter.next();
54
55                 if (i == m_index)
56                 {
57                     retval = tmp;
58                     break;
59                 }
60             }
61         }
62
63         return retval;
64     }
65
66     public void remove()
67     {
68         java.util.Iterator JavaDoc iter = m_collection.iterator();
69         for (int i = 1; i <= m_index; i++)
70         {
71             Object JavaDoc tmp = iter.next();
72
73             if (i == m_index)
74             {
75                 iter.remove();
76                 m_index--;
77                 break;
78             }
79         }
80     }
81 }
82
Popular Tags