Index: openide/src/org/openide/filesystems/MultiFileObject.java =================================================================== RCS file: /cvs/openide/src/org/openide/filesystems/MultiFileObject.java,v retrieving revision 1.107 diff -u -r1.107 MultiFileObject.java --- openide/src/org/openide/filesystems/MultiFileObject.java 3 Dec 2002 14:11:46 -0000 1.107 +++ openide/src/org/openide/filesystems/MultiFileObject.java 13 Dec 2002 18:02:43 -0000 @@ -138,7 +138,7 @@ if (led != null) { // otherwise leave the leader to be last file that represented // this one - if (led != this.leader && this.leader != null) { + if (!led.equals(this.leader) && this.leader != null) { // isValid prevents here from firing events after MFO.delete if (isData() && isValid ()) fileChanged0 (new FileEvent (this)); @@ -191,7 +191,7 @@ FileObject oldLeader = findLeader (oldFileSystems, path); FileObject newLeader = findLeader (fileSystems, path); - if (oldLeader != null && newLeader != null && oldLeader != newLeader) { + if (oldLeader != null && newLeader != null && !oldLeader.equals(newLeader)) { mfo.fileAttributeChanged0(new FileAttributeEvent(mfo,null,null,null)); } } @@ -631,7 +631,7 @@ FileObject localFo = lastAttrCacheFile; String cachedAttrName = lastAttrCacheName; - if (localFo != null && localFo != this && cachedAttrName.equals(attrName)) { + if (localFo != null && !localFo.equals(this) && cachedAttrName.equals(attrName)) { if (localFo.isRoot() && prefixattr != null) { try { @@ -1209,7 +1209,7 @@ */ public void fileChanged(FileEvent fe) { FileObject changedFile = this; - if (fe.getSource() == leader && hasAtLeastOneListeners() && !fe.firedFrom(markAtomicAction)) { + if (fe.getSource().equals(leader) && hasAtLeastOneListeners() && !fe.firedFrom(markAtomicAction)) { /**There should not dissapear information about source and changed file*/ if (!fe.getFile().equals(fe.getSource())) changedFile = getFileObject(fe.getFile().getName(), fe.getFile().getExt()); @@ -1258,13 +1258,13 @@ /** If change is not fired from leader then leader may mask this attribute * and then event should not be fired */ - if (fe.getFile() != leader && fe.getName() != null && + if (!fe.getFile().equals(leader) && fe.getName() != null && leader.getAttribute (fe.getName()) != null) return; /** If change is not fired from leader then another delegate may mask this attribute * and then event should not be fired. */ - if (fe.getFile() != leader && fe.getNewValue() != null && fe.getName() != null && + if (!fe.getFile().equals(leader) && fe.getNewValue() != null && fe.getName() != null && !fe.getNewValue().equals (getAttribute (fe.getName()))) return; Index: core/src/org/netbeans/core/projects/cache/BinaryFS.java =================================================================== RCS file: /cvs/core/src/org/netbeans/core/projects/cache/BinaryFS.java,v retrieving revision 1.3 diff -u -r1.3 BinaryFS.java --- core/src/org/netbeans/core/projects/cache/BinaryFS.java 9 Dec 2002 22:36:37 -0000 1.3 +++ core/src/org/netbeans/core/projects/cache/BinaryFS.java 13 Dec 2002 18:02:43 -0000 @@ -294,12 +294,32 @@ private boolean initialized = false; private Map attrs = Collections.EMPTY_MAP; //MapAttribute> + // for equality comparisons + private int hash = 0; + public BFSBase(String name, FileObject parent, int offset) { this.name = name; this.parent = parent; this.offset = offset; } + public boolean equals(Object o) { + if (!(o instanceof BFSBase)) return false; + BFSBase f = (BFSBase)o; + if (f.hashCode() != hashCode()) return false; + return f.getPath().equals(getPath()) && specificEquals(f); + } + + public int hashCode() { + if (hash == 0) { + hash = getPath().hashCode() ^ (specificHashCode() + 265478956); + } + return hash; + } + + protected abstract boolean specificEquals(BFSBase f); + protected abstract int specificHashCode(); + /** no-op implementations of read-only, fixed, never firing FS */ public void addFileChangeListener(FileChangeListener fcl) {} public void removeFileChangeListener(FileChangeListener fcl) {} @@ -636,6 +657,11 @@ public boolean isFolder() { return false; } + + private byte[] data() throws IOException { + if (len == -1) throw new IllegalArgumentException(); + return new Pointer(contentOffset).getBytes(len); + } /** Get input stream. */ public InputStream getInputStream() throws java.io.FileNotFoundException { @@ -643,7 +669,7 @@ try { return len == -1 ? // URI or not new URL(uri).openConnection().getInputStream() : // len from URI - new ByteArrayInputStream(new Pointer(contentOffset).getBytes(len)); + new ByteArrayInputStream(data()); } catch (Exception e) { FileNotFoundException x = new FileNotFoundException (e.getMessage()); ErrorManager.getDefault().annotate(x,e); @@ -676,7 +702,54 @@ contentOffset = ptr.getOffset(); if (len == -1) uri = ptr.getString(); } + + // hashCode and equals compare data: URI or byte contents. + protected int specificHashCode() { + initialize(); + if (len == -1) { + return uri.hashCode(); + } else { + byte[] data; + try { + data = data(); + } catch (IOException ioe) { + return 55; + } + int x = 0; + for (int i = 0; i < data.length; i++) { + x += 876824551; + x ^= data[i]; + } + return x; + } + } + + protected boolean specificEquals(BFSBase _f) { + if (!(_f instanceof BFSFile)) return false; + BFSFile f = (BFSFile)_f; + initialize(); + f.initialize(); + if (len == -1 && f.len == -1) { + return uri.equals(f.uri); + } else if (len != -1 && f.len != -1) { + byte[] data, fdata; + try { + data = data(); + fdata = f.data(); + } catch (IOException ioe) { + return false; + } + if (data.length != fdata.length) return false; + for (int i = 0; i < data.length; i++) { + if (data[i] != fdata[i]) return false; + } + return true; + } else { + return false; + } + } + } private class BFSFolder extends BFSBase { @@ -742,5 +815,25 @@ } } } + + // hashCode and equals compare contents recursively. + + protected int specificHashCode() { + initialize(); + int x = 0; + Iterator it = childrenMap.values().iterator(); + while (it.hasNext()) { + x ^= ((BFSBase)it.next()).hashCode(); + } + return x; + } + + protected boolean specificEquals(BFSBase _f) { + if (!(_f instanceof BFSFolder)) return false; + BFSFolder f = (BFSFolder)_f; + initialize(); + return childrenMap.equals(f.childrenMap); + } + } }