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: DxTreeMap.java,v 1.1 2001/12/18 10:31:30 per_nyfelt Exp $
008:
009: package org.ozoneDB.DxLib;
010:
011: import java.io.*;
012:
013: /**
014: * A DxMap implementation that is based on a weight balanced tree.
015: *
016: *
017: * @author <a href="http://www.softwarebuero.de/">SMB</a>
018: * @version $Revision: 1.1 $Date: 2001/12/18 10:31:30 $
019: */
020: public class DxTreeMap extends DxAbstractMap implements
021: DxTreeCollection, Externalizable {
022:
023: final static long serialVersionUID = 1L;
024:
025: protected transient DxBBTree bbtree;
026:
027: protected DxComparator comparator = null;
028:
029: public DxTreeMap() {
030: comparator = new DxStandardComparator();
031: bbtree = new DxBBTree(comparator);
032: }
033:
034: public DxTreeMap(DxComparator _comparator) {
035: comparator = _comparator;
036: bbtree = new DxBBTree(comparator);
037: }
038:
039: public Object clone() {
040: DxMap newMap = new DxTreeMap(comparator);
041: return clone(newMap);
042: }
043:
044: /**
045: */
046: public synchronized boolean addForKey(Object obj, Object key) {
047: return bbtree.addForKey(obj, key);
048: }
049:
050: /**
051: */
052: public Object elementForKey(Object key) {
053: return bbtree.elementForKey(key);
054: }
055:
056: /**
057: */
058: public Object keyForElement(Object obj) {
059: return bbtree.keyForElement(obj);
060: }
061:
062: /**
063: */
064: public synchronized Object removeForKey(Object key) {
065: return bbtree.removeForKey(key);
066: }
067:
068: /**
069: */
070: public synchronized boolean remove(Object obj) {
071: Object key = keyForElement(obj);
072: if (key != null) {
073: removeForKey(key);
074: return true;
075: }
076: return false;
077: }
078:
079: /**
080: */
081: public DxIterator iterator() {
082: return new DxBBIterator(this );
083: }
084:
085: /**
086: */
087: public int count() {
088: return bbtree.count();
089: }
090:
091: /**
092: */
093: public boolean isEmpty() {
094: return bbtree.isEmpty();
095: }
096:
097: /**
098: */
099: public boolean containsKey(Object key) {
100: return bbtree.containsKey(key);
101: }
102:
103: /**
104: */
105: public synchronized void clear() {
106: bbtree = new DxBBTree(comparator);
107: }
108:
109: /**
110: */
111: public DxBBTree internalTree() {
112: return bbtree;
113: }
114:
115: public void writeExternal(ObjectOutput out) throws IOException {
116: // System.out.println (getClass().getName() + ".writeExternal()...");
117: out.writeObject(comparator);
118: super .writeExternal(out);
119: }
120:
121: public synchronized void readExternal(ObjectInput in)
122: throws IOException, ClassNotFoundException {
123: // System.out.println ("tree.readExternal()...");
124: comparator = (DxComparator) in.readObject();
125: bbtree = new DxBBTree(comparator);
126: super.readExternal(in);
127: }
128: }
|