01: // You can redistribute this software and/or modify it under the terms of
02: // the Ozone Library License version 1 published by ozone-db.org.
03: //
04: // The original code and portions created by SMB are
05: // Copyright (C) 1997-@year@ by SMB GmbH. All rights reserved.
06: //
07: // $Id: DxTreeSet.java,v 1.1 2001/12/18 10:31:30 per_nyfelt Exp $
08:
09: package org.ozoneDB.DxLib;
10:
11: import java.util.*;
12: import java.io.*;
13:
14: /**
15: *
16: *
17: * @author <a href="http://www.softwarebuero.de/">SMB</a>
18: * @version $Revision: 1.1 $Date: 2001/12/18 10:31:30 $
19: */
20: public class DxTreeSet extends DxAbstractSet implements
21: DxTreeCollection {
22: //, Externalizable {
23:
24: final static long serialVersionUID = 1L;
25:
26: protected transient DxBBTree bbtree;
27:
28: protected DxComparator comparator;
29:
30: /**
31: * Constructs a new, empty set. All keys inserted into the map must
32: * implement the DxComparable interface.
33: */
34: public DxTreeSet() {
35: comparator = new DxStandardComparator();
36: bbtree = new DxBBTree(comparator);
37: }
38:
39: /**
40: * Constructs a new, empty set, sorted according to the given comparator.
41: * All inserted objects must be comparable by the given comparator.
42: */
43: public DxTreeSet(DxComparator _comparator) {
44: comparator = _comparator;
45: bbtree = new DxBBTree(comparator);
46: }
47:
48: public Object clone() {
49: DxSet newSet = new DxTreeSet(comparator);
50: return clone(newSet);
51: }
52:
53: public synchronized boolean add(Object obj) {
54: return bbtree.addForKey(obj, obj);
55: }
56:
57: public synchronized boolean remove(Object obj) {
58: return bbtree.removeForKey(obj) != null;
59: }
60:
61: public boolean contains(Object obj) {
62: return bbtree.containsKey(obj);
63: }
64:
65: public DxIterator iterator() {
66: return new DxBBIterator(this );
67: }
68:
69: public int count() {
70: return bbtree.count();
71: }
72:
73: public boolean isEmpty() {
74: return bbtree.isEmpty();
75: }
76:
77: public synchronized void clear() {
78: bbtree = new DxBBTree();
79: }
80:
81: public DxBBTree internalTree() {
82: return bbtree;
83: }
84:
85: // public void writeExternal (ObjectOutput out) throws IOException {
86: // // System.out.println (getClass().getName() + ".writeExternal()...");
87: // out.writeObject (comparator);
88: // super.writeExternal (out);
89: // }
90: //
91: //
92: // public synchronized void readExternal (ObjectInput in) throws IOException, ClassNotFoundException {
93: // comparator = (DxComparator)in.readObject();
94: // bbtree = new DxBBTree (comparator);
95: // super.readExternal (in);
96: // }
97:
98: }
|