KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > mockobjects > Iterator


1 package com.mockobjects;
2
3 import java.util.*;
4
5 /*
6  * TYPE TO PROVIDE BASIC ITERATOR IMPLEMENTATION TO BRIDGE GAP BETWEEN
7  * JDK1.1.7 and JDK 1.2
8  */

9
10 public class Iterator {
11     private Vector vector;
12     private int count;
13
14     public Iterator(Vector v) {
15         vector = v;
16         count = 0;
17     }
18
19     public boolean hasNext() {
20         return count < vector.size();
21     }
22
23     public Object JavaDoc next() {
24         synchronized (vector) {
25             if (count < vector.size()) {
26                 return vector.elementAt(count++);
27             }
28         }
29         throw new NoSuchElementException("VectorEnumerator");
30     }
31 }
32
Popular Tags