01: ///////////////////////////////////////////////////////////////////////////////
02: //
03: // Copyright (C) 2003-@year@ by Thomas M. Hazel, MyOODB (www.myoodb.org)
04: //
05: // All Rights Reserved
06: //
07: // This program is free software; you can redistribute it and/or modify
08: // it under the terms of the GNU General Public License and GNU Library
09: // 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
27: Iterator {
28: private int m_index;
29: private java.util.Collection m_collection;
30:
31: public IteratorDbImpl(java.util.Collection collection) {
32: m_index = 0;
33: m_collection = collection;
34: }
35:
36: public boolean hasNext() {
37: return m_index < m_collection.size();
38: }
39:
40: public Object next() {
41: Object retval = null;
42:
43: if (hasNext() == true) {
44: m_index++;
45:
46: java.util.Iterator iter = m_collection.iterator();
47: for (int i = 1; i <= m_index; i++) {
48: Object tmp = iter.next();
49:
50: if (i == m_index) {
51: retval = tmp;
52: break;
53: }
54: }
55: }
56:
57: return retval;
58: }
59:
60: public void remove() {
61: java.util.Iterator iter = m_collection.iterator();
62: for (int i = 1; i <= m_index; i++) {
63: Object tmp = iter.next();
64:
65: if (i == m_index) {
66: iter.remove();
67: m_index--;
68: break;
69: }
70: }
71: }
72: }
|