001: // You can redistribute this software and/or modify it under the terms of
002: // the Ozone Library License version 1 published by ozone-db.org.
003: //
004: // The original code and portions created by SMB are
005: // Copyright (C) 1997-@year@ by SMB GmbH. All rights reserved.
006: //
007: // $Id: DxBBIterator.java,v 1.1 2001/12/18 10:31:30 per_nyfelt Exp $
008:
009: package org.ozoneDB.DxLib;
010:
011: /**
012: *
013: *
014: * @author <a href="http://www.softwarebuero.de/">SMB</a>
015: * @version $Revision: 1.1 $Date: 2001/12/18 10:31:30 $
016: */
017: public final class DxBBIterator extends DxAbstractIterator {
018:
019: final static long serialVersionUID = 1L;
020:
021: DxBBTree bbtree;
022: DxBBnode node;
023:
024: /**
025: */
026: public DxBBIterator(DxTreeCollection _coll) {
027: bbtree = _coll.internalTree();
028: reset();
029: }
030:
031: /**
032: */
033: public Object object() {
034: return node != null ? node.data : null;
035: }
036:
037: /**
038: */
039: public Object key() {
040: return node != null ? node.key : null;
041: }
042:
043: /**
044: */
045: public Object next() {
046: Object obj = object();
047: if (atFirstObject) {
048: atFirstObject = false;
049: } else {
050: if (obj != null && !objectRemoved) {
051: if (node.re != null) {
052: node = leftMost(node.re);
053: } else {
054: node = firstRightParent(node);
055: }
056: obj = object();
057: }
058: objectRemoved = false;
059: }
060: return obj;
061: }
062:
063: /**
064: */
065: public void reset() {
066: node = leftMost(bbtree.root());
067: atFirstObject = true;
068: objectRemoved = false;
069: }
070:
071: /**
072: */
073: public Object removeObject() {
074: Object obj = object();
075: if (obj != null && !objectRemoved) {
076: DxBBnode delNode = node;
077: if (node.re != null) {
078: node = leftMost(node.re);
079: } else {
080: node = firstRightParent(node);
081: }
082: bbtree.removeForKey(delNode.key);
083: objectRemoved = true;
084: }
085: return obj;
086: }
087:
088: /**
089: */
090: private DxBBnode leftMost(DxBBnode node) {
091: if (node != null && node.li != null) {
092: return leftMost(node.li);
093: }
094: return node;
095: }
096:
097: /**
098: */
099: private DxBBnode firstRightParent(DxBBnode node) {
100: if (node == bbtree.quietRoot) {
101: return null;
102: }
103: if (node.isRight) {
104: return firstRightParent(node.pa);
105: }
106: return node.pa;
107: }
108: }
|