1 6 7 package com.jofti.btree; 8 9 10 11 import java.util.Set ; 12 13 import com.jofti.util.FastSet; 14 15 16 17 25 public class LeafNodeEntry implements NodeEntry{ 26 27 28 31 private static final long serialVersionUID = -181573341072167495L; 32 33 public Set uniqueIdSet = null; 34 35 public Comparable value = null; 36 37 protected volatile int hashCode =0; 38 39 40 public LeafNodeEntry() { 41 } 42 43 public LeafNodeEntry(Object uniqueId, Comparable value){ 44 uniqueIdSet = new FastSet(); 45 uniqueIdSet.add(uniqueId); 46 this.value =value; 47 } 48 49 53 Set getUniqueIdSet() { 54 if (uniqueIdSet == null){ 55 return new FastSet(); 56 } 57 return uniqueIdSet; 58 } 59 60 64 public int getUniqueIdSize(){ 65 if (uniqueIdSet == null){ 66 return 0; 67 } 68 return uniqueIdSet.size(); 69 } 70 71 75 void setUniqueIdSet(Set uniqueIdList) { 76 if (uniqueIdSet == null){ 77 uniqueIdSet = new FastSet(); 78 } 79 this.uniqueIdSet.clear(); 80 this.uniqueIdSet.addAll(uniqueIdList); 81 } 82 83 84 88 public void addUniqueId(Object uniqueId) { 89 if (uniqueIdSet == null){ 90 uniqueIdSet = new FastSet(); 91 } 92 uniqueIdSet.add(uniqueId); 93 } 94 95 99 void addUniqueIdSet(Set uniqueIdList) { 100 this.uniqueIdSet.addAll(uniqueIdList); 101 } 102 103 void removeUniqueId(Object Id) { 104 if (uniqueIdSet == null){ 105 return; 106 } 107 uniqueIdSet.remove(Id); 108 } 109 110 void removeAllIds(Set idSet){ 111 if (uniqueIdSet == null){ 112 return; 113 } 114 uniqueIdSet.removeAll(idSet); 115 } 116 120 public Comparable getValue() { 121 return value; 122 } 123 124 128 129 public void setValue(Comparable value) { 130 this.value = value; 131 } 132 133 public String toString(){ 134 StringBuffer buf = new StringBuffer (); 135 buf.append("value:"+value); 136 buf.append(","); 137 buf.append("uniqueIds:" +uniqueIdSet); 138 139 return buf.toString(); 140 } 141 142 180 public int compareTo(Object o) { 181 182 if (o instanceof LeafNodeEntry) 183 { 184 return value.compareTo(((LeafNodeEntry)o).value); 185 } 186 throw new IllegalArgumentException ("Cannot compare with a non leafnode"); 187 188 } 189 190 193 public boolean equals(Object o) { 194 195 if (o instanceof LeafNodeEntry) 196 { 197 return value.compareTo(((LeafNodeEntry)o).value) == 0; 198 } else { 199 return false; 200 } 201 } 202 203 206 public int hashCode(){ 207 if (hashCode ==0){ 208 int result = 17; 209 result = 37*result + value.hashCode(); 210 hashCode = result; 211 } 212 return hashCode; 213 } 214 215 216 } 217 | Popular Tags |