01: // You can redistribute this software and/or modify it under the terms of
02: // the Ozone Library License version 1 published by ozone-db.org.
03: //
04: // The original code and portions created by SMB are
05: // Copyright (C) 1997-@year@ by SMB GmbH. All rights reserved.
06: //
07: // $Id: DxVectorIterator.java,v 1.1 2001/12/18 10:31:30 per_nyfelt Exp $
08:
09: package org.ozoneDB.DxLib;
10:
11: import java.io.*;
12: import java.util.*;
13:
14: /**
15: *
16: *
17: * @author <a href="http://www.softwarebuero.de/">SMB</a>
18: * @version $Revision: 1.1 $Date: 2001/12/18 10:31:30 $
19: */
20: public final class DxVectorIterator extends DxAbstractIterator {
21:
22: final static long serialVersionUID = 1L;
23:
24: DxVectorCollection coll;
25:
26: Vector vector;
27:
28: int currentIndex;
29:
30: Object currentObject;
31:
32: /**
33: */
34: public DxVectorIterator(DxVectorCollection _coll) {
35: coll = _coll;
36: vector = coll.internalVector();
37: reset();
38: }
39:
40: /**
41: */
42: public Object object() {
43: return currentObject;
44: }
45:
46: /**
47: */
48: public Object next() {
49: if (atFirstObject) {
50: atFirstObject = false;
51: } else {
52: try {
53: //skip null elements
54: while ((currentObject = vector
55: .elementAt(++currentIndex)) == null)
56: ;
57: } catch (ArrayIndexOutOfBoundsException e) {
58: //object returns null if currentIndex exceeds vector size
59: currentObject = null;
60: }
61: }
62: return currentObject;
63: }
64:
65: /**
66: */
67: public void reset() {
68: atFirstObject = true;
69: objectRemoved = false;
70: currentIndex = 0;
71: currentObject = currentIndex < vector.size() ? vector
72: .elementAt(currentIndex) : null;
73: }
74:
75: /**
76: */
77: public synchronized Object removeObject() {
78: Object answer = vector.elementAt(currentIndex);
79: //decrement index to point to the same index after next()
80: vector.removeElementAt(currentIndex--);
81: coll.decCounter();
82: return answer;
83: }
84: }
|