Lines 294-325
Link Here
|
294 |
private boolean initialized = false; |
294 |
private boolean initialized = false; |
295 |
private Map attrs = Collections.EMPTY_MAP; //Map<String->Attribute> |
295 |
private Map attrs = Collections.EMPTY_MAP; //Map<String->Attribute> |
296 |
|
296 |
|
297 |
// for equality comparisons |
|
|
298 |
private int hash = 0; |
299 |
|
300 |
public BFSBase(String name, FileObject parent, int offset) { |
297 |
public BFSBase(String name, FileObject parent, int offset) { |
301 |
this.name = name; |
298 |
this.name = name; |
302 |
this.parent = parent; |
299 |
this.parent = parent; |
303 |
this.offset = offset; |
300 |
this.offset = offset; |
304 |
} |
301 |
} |
305 |
|
302 |
|
306 |
public boolean equals(Object o) { |
303 |
public final boolean equals(Object o) { |
307 |
if (!(o instanceof BFSBase)) return false; |
304 |
if (!(o instanceof BFSBase)) return false; |
308 |
if (o == this) return true; |
305 |
if (o == this) return true; |
309 |
BFSBase f = (BFSBase)o; |
306 |
BFSBase f = (BFSBase)o; |
310 |
if (f.hashCode() != hashCode()) return false; |
|
|
311 |
return f.getPath().equals(getPath()) && specificEquals(f); |
307 |
return f.getPath().equals(getPath()) && specificEquals(f); |
312 |
} |
308 |
} |
313 |
|
309 |
|
314 |
public int hashCode() { |
310 |
public final int hashCode() { |
315 |
if (hash == 0) { |
311 |
return getPath().hashCode(); |
316 |
hash = getPath().hashCode() ^ (specificHashCode() + 265478956); |
|
|
317 |
} |
318 |
return hash; |
319 |
} |
312 |
} |
320 |
|
313 |
|
321 |
protected abstract boolean specificEquals(BFSBase f); |
314 |
protected abstract boolean specificEquals(BFSBase f); |
322 |
protected abstract int specificHashCode(); |
|
|
323 |
|
315 |
|
324 |
/** no-op implementations of read-only, fixed, never firing FS */ |
316 |
/** no-op implementations of read-only, fixed, never firing FS */ |
325 |
public void addFileChangeListener(FileChangeListener fcl) {} |
317 |
public void addFileChangeListener(FileChangeListener fcl) {} |
Lines 704-731
Link Here
|
704 |
if (len == -1) uri = ptr.getString(); |
696 |
if (len == -1) uri = ptr.getString(); |
705 |
} |
697 |
} |
706 |
|
698 |
|
707 |
// hashCode and equals compare data: URI or byte contents. |
699 |
// equals compares data: URI or byte contents. |
708 |
|
700 |
|
709 |
protected int specificHashCode() { |
|
|
710 |
initialize(); |
711 |
if (len == -1) { |
712 |
return uri.hashCode(); |
713 |
} else { |
714 |
byte[] data; |
715 |
try { |
716 |
data = data(); |
717 |
} catch (IOException ioe) { |
718 |
return 55; |
719 |
} |
720 |
int x = 0; |
721 |
for (int i = 0; i < data.length; i++) { |
722 |
x += 876824551; |
723 |
x ^= data[i]; |
724 |
} |
725 |
return x; |
726 |
} |
727 |
} |
728 |
|
729 |
protected boolean specificEquals(BFSBase _f) { |
701 |
protected boolean specificEquals(BFSBase _f) { |
730 |
if (!(_f instanceof BFSFile)) return false; |
702 |
if (!(_f instanceof BFSFile)) return false; |
731 |
BFSFile f = (BFSFile)_f; |
703 |
BFSFile f = (BFSFile)_f; |
Lines 817-833
Link Here
|
817 |
} |
789 |
} |
818 |
} |
790 |
} |
819 |
|
791 |
|
820 |
// hashCode and equals compare contents recursively. |
792 |
// equals compares contents recursively. |
821 |
|
|
|
822 |
protected int specificHashCode() { |
823 |
initialize(); |
824 |
int x = 0; |
825 |
Iterator it = childrenMap.values().iterator(); |
826 |
while (it.hasNext()) { |
827 |
x ^= ((BFSBase)it.next()).hashCode(); |
828 |
} |
829 |
return x; |
830 |
} |
831 |
|
793 |
|
832 |
protected boolean specificEquals(BFSBase _f) { |
794 |
protected boolean specificEquals(BFSBase _f) { |
833 |
if (!(_f instanceof BFSFolder)) return false; |
795 |
if (!(_f instanceof BFSFolder)) return false; |