KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > ozoneDB > DxLib > DxHashIterator


1 // You can redistribute this software and/or modify it under the terms of
2
// the Ozone Library License version 1 published by ozone-db.org.
3
//
4
// The original code and portions created by SMB are
5
// Copyright (C) 1997-@year@ by SMB GmbH. All rights reserved.
6
//
7
// $Id: DxHashIterator.java,v 1.1 2001/12/18 10:31:30 per_nyfelt Exp $
8

9 package org.ozoneDB.DxLib;
10
11 import java.util.*;
12
13 /**
14  *
15  *
16  * @author <a HREF="http://www.softwarebuero.de/">SMB</a>
17  * @version $Revision: 1.1 $Date: 2001/12/18 10:31:30 $
18  */

19 public final class DxHashIterator extends DxAbstractIterator {
20     
21     final static long serialVersionUID = 1L;
22     
23     Enumeration keyEnum;
24     Enumeration objEnum;
25     Object JavaDoc currentKey;
26     Object JavaDoc currentObject;
27     Hashtable ht;
28     
29     
30     /**
31      */

32     public DxHashIterator( DxHashCollection _coll ) {
33         ht = _coll.internalHashtable();
34         reset();
35     }
36     
37     
38     /**
39      */

40     public Object JavaDoc object() {
41         return currentObject;
42     }
43     
44     
45     /**
46      */

47     public Object JavaDoc key() {
48         return currentKey;
49     }
50     
51     
52     /**
53      */

54     public Object JavaDoc next() {
55         if (atFirstObject) {
56             atFirstObject = false;
57         } else {
58             if (objEnum.hasMoreElements()) {
59                 currentObject = objEnum.nextElement();
60                 currentKey = keyEnum.nextElement();
61             } else {
62                 return null;
63             }
64         }
65         return object();
66     }
67     
68     
69     /**
70      */

71     public void reset() {
72         atFirstObject = true;
73         objectRemoved = false;
74         keyEnum = ht.keys();
75         objEnum = ht.elements();
76         if (objEnum.hasMoreElements()) {
77             currentObject = objEnum.nextElement();
78         }
79         if (keyEnum.hasMoreElements()) {
80             currentKey = keyEnum.nextElement();
81         }
82     }
83     
84     
85     /**
86      */

87     public synchronized Object JavaDoc removeObject() {
88         return ht.remove( currentKey );
89     }
90 }
91
Popular Tags