1 9 package org.ozoneDB.DxLib; 10 11 import java.io.*; 12 13 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 clone() { 42 DxMap newMap = new DxTreeMap( comparator ); 43 return clone( newMap ); 44 } 45 46 47 49 public synchronized boolean addForKey( Object obj, Object key ) { 50 return bbtree.addForKey( obj, key ); 51 } 52 53 54 56 public Object elementForKey( Object key ) { 57 return bbtree.elementForKey( key ); 58 } 59 60 61 63 public Object keyForElement( Object obj ) { 64 return bbtree.keyForElement( obj ); 65 } 66 67 68 70 public synchronized Object removeForKey( Object key ) { 71 return bbtree.removeForKey( key ); 72 } 73 74 75 77 public synchronized boolean remove( Object obj ) { 78 Object key = keyForElement( obj ); 79 if (key != null) { 80 removeForKey( key ); 81 return true; 82 } 83 return false; 84 } 85 86 87 89 public DxIterator iterator() { 90 return new DxBBIterator( this ); 91 } 92 93 94 96 public int count() { 97 return bbtree.count(); 98 } 99 100 101 103 public boolean isEmpty() { 104 return bbtree.isEmpty(); 105 } 106 107 108 110 public boolean containsKey( Object key ) { 111 return bbtree.containsKey( key ); 112 } 113 114 115 117 public synchronized void clear() { 118 bbtree = new DxBBTree( comparator ); 119 } 120 121 122 124 public DxBBTree internalTree() { 125 return bbtree; 126 } 127 128 129 public void writeExternal( ObjectOutput out ) throws IOException { 130 out.writeObject( comparator ); 132 super.writeExternal( out ); 133 } 134 135 136 public synchronized void readExternal( ObjectInput in ) throws IOException, ClassNotFoundException { 137 comparator = (DxComparator)in.readObject(); 139 bbtree = new DxBBTree( comparator ); 140 super.readExternal( in ); 141 } 142 } 143 | Popular Tags |