KickJava   Java API By Example, From Geeks To Geeks.

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


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: DxHashSet.java,v 1.1.2.1 2002/05/21 20:14:38 mediumnet Exp $
8

9 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.1.2.1 $Date: 2002/05/21 20:14:38 $
18  */

19 public class DxHashSet extends DxAbstractSet implements DxHashCollection {
20     
21     final static long serialVersionUID = 1L;
22     
23     protected Hashtable ht;
24     
25     
26     public DxHashSet() {
27         ht = new Hashtable();
28     }
29     
30     
31     public DxHashSet( int initSize ) {
32         ht = new Hashtable( initSize );
33     }
34     
35     
36     public Object JavaDoc clone() {
37         DxSet newSet = new DxHashSet( count() );
38         return clone( newSet );
39     }
40     
41     
42     public synchronized boolean add( Object JavaDoc obj ) {
43         Object JavaDoc old = ht.put( obj, obj );
44         if (old != null) {
45             ht.put( old, old );
46             return false;
47         } else {
48             return true;
49         }
50     }
51     
52     
53     public synchronized boolean remove( Object JavaDoc obj ) {
54         Object JavaDoc old = ht.remove( obj );
55         return old != null;
56     }
57     
58     
59     public boolean contains( Object JavaDoc obj ) {
60         return ht.containsKey( obj );
61     }
62     
63     
64     public DxIterator iterator() {
65         return new DxHashIterator( this );
66     }
67     
68     
69     public int count() {
70         return ht.size();
71     }
72     
73     
74     public boolean isEmpty() {
75         return ht.isEmpty();
76     }
77     
78     
79     public synchronized void clear() {
80         ht.clear();
81     }
82     
83     
84     public Hashtable internalHashtable() {
85         return ht;
86     }
87
88     public String JavaDoc toString() {
89         StringBuffer JavaDoc b = new StringBuffer JavaDoc((ht.size()+1)<<4);
90
91         b.append("DxHashSet{");
92
93         DxIterator iterator = iterator();
94         boolean comma = false;
95
96         while (iterator.next()!=null) {
97             if (comma) {
98                 b.append(',');
99             } else {
100                 comma = true;
101             }
102             b.append(iterator.key());
103         }
104
105         b.append("}");
106
107         return b.toString();
108     }
109 }
110
Popular Tags