1 8 9 package com.sleepycat.je; 10 11 import com.sleepycat.je.tree.TreeUtils; 12 import com.sleepycat.util.keyrange.KeyRange; 13 14 18 public class DatabaseEntry { 19 20 21 private byte[] data; 22 private int dlen = 0; 23 private int doff = 0; 24 private int offset = 0; 25 private int size = 0; 26 private boolean partial = false; 27 28 29 30 public static int MAX_DUMP_BYTES = 100; 31 32 public String toString() { 33 StringBuffer sb = new StringBuffer ("<DatabaseEntry"); 34 sb.append(" dlen=\"").append(dlen); 35 sb.append("\" doff=\"").append(doff); 36 sb.append("\" doff=\"").append(doff); 37 sb.append("\" offset=\"").append(offset); 38 sb.append("\" size=\"").append(size); 39 sb.append("\" data=\"").append(dumpData()); 40 if ((size - 1) > MAX_DUMP_BYTES) { 41 sb.append(" ... ").append((size - MAX_DUMP_BYTES) + 42 " bytes not shown "); 43 } 44 sb.append("\"/>"); 45 return sb.toString(); 46 } 47 48 51 52 56 public DatabaseEntry() { 57 } 58 59 63 public DatabaseEntry(byte[] data) { 64 this.data = data; 65 if (data != null) { 66 this.size = data.length; 67 } 68 } 69 70 74 public DatabaseEntry(byte[] data, int offset, int size) { 75 this.data = data; 76 this.offset = offset; 77 this.size = size; 78 } 79 80 83 84 88 public byte[] getData() { 89 return data; 90 } 91 92 96 public void setData(byte[] data) { 97 this.data = data; 98 offset = 0; 99 size = (data == null) ? 0 : data.length; 100 } 101 102 106 public void setData(byte[] data, int offset, int size) { 107 this.data = data; 108 this.offset = offset; 109 this.size = size; 110 } 111 112 116 public void setPartial(int doff, int dlen, boolean partial) { 117 setPartialOffset(doff); 118 setPartialLength(dlen); 119 setPartial(partial); 120 } 121 122 126 public int getPartialLength() { 127 return dlen; 128 } 129 130 134 public void setPartialLength(int dlen) { 135 this.dlen = dlen; 136 } 137 138 142 public int getPartialOffset() { 143 return doff; 144 } 145 146 150 public void setPartialOffset(int doff) { 151 this.doff = doff; 152 } 153 154 158 public boolean getPartial() { 159 return partial; 160 } 161 162 166 public void setPartial(boolean partial) { 167 this.partial = partial; 168 } 169 170 174 public int getOffset() { 175 return offset; 176 } 177 178 182 public void setOffset(int offset) { 183 this.offset = offset; 184 } 185 186 190 public int getSize() { 191 return size; 192 } 193 194 198 public void setSize(int size) { 199 this.size = size; 200 } 201 202 205 String dumpData() { 206 return TreeUtils.dumpByteArray(KeyRange.getByteArray(this, 207 MAX_DUMP_BYTES)); 208 } 209 210 225 public boolean equals(Object o) { 226 if (!(o instanceof DatabaseEntry)) { 227 return false; 228 } 229 DatabaseEntry e = (DatabaseEntry) o; 230 if (partial || e.partial) { 231 if (partial != e.partial || 232 dlen != e.dlen || 233 doff != e.doff) { 234 return false; 235 } 236 } 237 if (data == null && e.data == null) { 238 return true; 239 } 240 if (data == null || e.data == null) { 241 return false; 242 } 243 if (size != e.size) { 244 return false; 245 } 246 for (int i = 0; i < size; i += 1) { 247 if (data[offset + i] != e.data[e.offset + i]) { 248 return false; 249 } 250 } 251 return true; 252 } 253 254 257 public int hashCode() { 258 int hash = 0; 259 if (data != null) { 260 for (int i = 0; i < size; i += 1) { 261 hash += data[offset + i]; 262 } 263 } 264 return hash; 265 } 266 } 267 | Popular Tags |