1 9 package org.ozoneDB.DxLib; 10 11 import java.util.*; 12 13 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 clone() { 37 DxSet newSet = new DxHashSet( count() ); 38 return clone( newSet ); 39 } 40 41 42 public synchronized boolean add( Object obj ) { 43 Object 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 obj ) { 54 Object old = ht.remove( obj ); 55 return old != null; 56 } 57 58 59 public boolean contains( Object 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 toString() { 89 StringBuffer b = new StringBuffer ((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 |