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: DxHashSet.java,v 1.2 2002/06/08 00:49:38 mediumnet Exp $
08:
09: package org.ozoneDB.DxLib;
10:
11: import java.util.*;
12:
13: /**
14: *
15: *
16: * @author <a href="http://www.softwarebuero.de/">SMB</a>
17: * @version $Revision: 1.2 $Date: 2002/06/08 00:49:38 $
18: */
19: public class DxHashSet extends DxAbstractSet implements
20: DxHashCollection {
21:
22: final static long serialVersionUID = 1L;
23:
24: protected Hashtable ht;
25:
26: public DxHashSet() {
27: ht = new Hashtable();
28: }
29:
30: public DxHashSet(int initSize) {
31: ht = new Hashtable(initSize);
32: }
33:
34: public Object clone() {
35: DxSet newSet = new DxHashSet(count());
36: return clone(newSet);
37: }
38:
39: public synchronized boolean add(Object obj) {
40: Object old = ht.put(obj, obj);
41: if (old != null) {
42: ht.put(old, old);
43: return false;
44: } else {
45: return true;
46: }
47: }
48:
49: public synchronized boolean remove(Object obj) {
50: Object old = ht.remove(obj);
51: return old != null;
52: }
53:
54: public boolean contains(Object obj) {
55: return ht.containsKey(obj);
56: }
57:
58: public DxIterator iterator() {
59: return new DxHashIterator(this );
60: }
61:
62: public int count() {
63: return ht.size();
64: }
65:
66: public boolean isEmpty() {
67: return ht.isEmpty();
68: }
69:
70: public synchronized void clear() {
71: ht.clear();
72: }
73:
74: public Hashtable internalHashtable() {
75: return ht;
76: }
77:
78: public String toString() {
79: StringBuffer b = new StringBuffer((ht.size() + 1) << 4);
80:
81: b.append("DxHashSet{");
82:
83: DxIterator iterator = iterator();
84: boolean comma = false;
85:
86: while (iterator.next() != null) {
87: if (comma) {
88: b.append(',');
89: } else {
90: comma = true;
91: }
92: b.append(iterator.key());
93: }
94:
95: b.append("}");
96:
97: return b.toString();
98: }
99: }
|