KickJava   Java API By Example, From Geeks To Geeks.

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


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: DxMultiIterator.java,v 1.5 2000/10/28 16:55:14 daniela Exp $
8

9 package org.ozoneDB.DxLib;
10
11 /**
12  *
13  *
14  * @author <a HREF="http://www.softwarebuero.de/">SMB</a>
15  * @version $Revision: 1.5 $Date: 2000/10/28 16:55:14 $
16  */

17 public class DxMultiIterator extends DxAbstractIterator {
18     
19     final static long serialVersionUID = 1L;
20     
21     DxMultiMap multiMap;
22     DxIterator mapIt;
23     DxIterator contIt;
24     
25     
26     /**
27      */

28     public DxMultiIterator( DxMultiMap _multiMap ) {
29         multiMap = _multiMap;
30         reset();
31     }
32     
33     
34     /**
35      */

36     public Object JavaDoc object() {
37         return contIt != null ? contIt.object() : null;
38     }
39     
40     
41     /**
42      */

43     public Object JavaDoc key() {
44         return mapIt != null ? mapIt.key() : null;
45     }
46     
47     
48     /**
49      */

50     public Object JavaDoc next() {
51         Object JavaDoc obj = contIt != null ? contIt.next() : null;
52         if (obj == null) {
53             contIt = null;
54             if (mapIt != null && mapIt.next() != null) {
55                 contIt = ((DxCollection)mapIt.object()).iterator();
56                 obj = contIt.next();
57             } else {
58                 mapIt = null;
59             }
60         }
61         return obj;
62     }
63     
64     
65     /**
66      */

67     public void reset() {
68         mapIt = multiMap.iterator();
69         if (mapIt.next() != null) {
70             contIt = ((DxCollection)mapIt.object()).iterator();
71         } else {
72             mapIt = null;
73         }
74     }
75     
76     
77     /**
78      */

79     public Object JavaDoc removeObject() {
80         Object JavaDoc obj = null;
81         if (contIt != null) {
82             obj = contIt.removeObject();
83             multiMap.multiItemCount--;
84             if (((DxCollection)mapIt.object()).isEmpty()) {
85                 contIt = null;
86                 mapIt.removeObject();
87             }
88         }
89         return obj;
90     }
91 }
92
Popular Tags