KickJava   Java API By Example, From Geeks To Geeks.

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


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

9 package org.ozoneDB.DxLib;
10
11 import java.io.*;
12
13 /**
14  * A DxMap implementation that is based on a weight balanced tree.
15  *
16  *
17  * @author <a HREF="http://www.softwarebuero.de/">SMB</a>
18  * @version $Revision: 1.7 $Date: 2000/10/28 16:55:14 $
19  */

20 public class DxTreeMap extends DxAbstractMap implements DxTreeCollection, Externalizable {
21     
22     final static long serialVersionUID = 1L;
23     
24     protected transient DxBBTree bbtree;
25     
26     protected DxComparator comparator = null;
27     
28     
29     public DxTreeMap() {
30         comparator = new DxStandardComparator();
31         bbtree = new DxBBTree( comparator );
32     }
33     
34     
35     public DxTreeMap( DxComparator _comparator ) {
36         comparator = _comparator;
37         bbtree = new DxBBTree( comparator );
38     }
39     
40     
41     public Object JavaDoc clone() {
42         DxMap newMap = new DxTreeMap( comparator );
43         return clone( newMap );
44     }
45     
46     
47     /**
48      */

49     public synchronized boolean addForKey( Object JavaDoc obj, Object JavaDoc key ) {
50         return bbtree.addForKey( obj, key );
51     }
52     
53     
54     /**
55      */

56     public Object JavaDoc elementForKey( Object JavaDoc key ) {
57         return bbtree.elementForKey( key );
58     }
59     
60     
61     /**
62      */

63     public Object JavaDoc keyForElement( Object JavaDoc obj ) {
64         return bbtree.keyForElement( obj );
65     }
66     
67     
68     /**
69      */

70     public synchronized Object JavaDoc removeForKey( Object JavaDoc key ) {
71         return bbtree.removeForKey( key );
72     }
73     
74     
75     /**
76      */

77     public synchronized boolean remove( Object JavaDoc obj ) {
78         Object JavaDoc key = keyForElement( obj );
79         if (key != null) {
80             removeForKey( key );
81             return true;
82         }
83         return false;
84     }
85     
86     
87     /**
88      */

89     public DxIterator iterator() {
90         return new DxBBIterator( this );
91     }
92     
93     
94     /**
95      */

96     public int count() {
97         return bbtree.count();
98     }
99     
100     
101     /**
102      */

103     public boolean isEmpty() {
104         return bbtree.isEmpty();
105     }
106     
107     
108     /**
109      */

110     public boolean containsKey( Object JavaDoc key ) {
111         return bbtree.containsKey( key );
112     }
113     
114     
115     /**
116      */

117     public synchronized void clear() {
118         bbtree = new DxBBTree( comparator );
119     }
120     
121     
122     /**
123      */

124     public DxBBTree internalTree() {
125         return bbtree;
126     }
127     
128     
129     public void writeExternal( ObjectOutput out ) throws IOException {
130         // System.out.println (getClass().getName() + ".writeExternal()...");
131
out.writeObject( comparator );
132         super.writeExternal( out );
133     }
134     
135     
136     public synchronized void readExternal( ObjectInput in ) throws IOException, ClassNotFoundException JavaDoc {
137         // System.out.println ("tree.readExternal()...");
138
comparator = (DxComparator)in.readObject();
139         bbtree = new DxBBTree( comparator );
140         super.readExternal( in );
141     }
142 }
143
Popular Tags