1 19 20 package org.netbeans.modules.turbo.keys; 21 22 import org.openide.filesystems.FileObject; 23 import org.openide.filesystems.FileSystem; 24 import org.openide.filesystems.FileUtil; 25 import org.openide.filesystems.FileStateInvalidException; 26 import org.openide.ErrorManager; 27 28 import java.io.File ; 29 30 36 public final class DiskFileKey { 37 private final FileObject fileObject; 38 private final int hashCode; 39 private String absolutePath; 40 41 42 public static DiskFileKey createKey(FileObject fo) { 43 return new DiskFileKey(fo); 44 } 45 46 private DiskFileKey(FileObject fo) { 47 48 FileObject nativeFileObject = (FileObject) fo.getAttribute("VCS-Native-FileObject"); if (nativeFileObject == null) nativeFileObject = fo; 53 54 55 fileObject = fo; 56 hashCode = fo.getNameExt().hashCode(); 57 } 58 59 public boolean equals(Object o) { 60 if (this == o) return true; 61 62 if (o instanceof DiskFileKey) { 63 64 DiskFileKey key = (DiskFileKey) o; 65 66 if (hashCode != key.hashCode) return false; 67 FileObject fo2 = key.fileObject; 68 FileObject fo = fileObject; 69 70 if (fo == fo2) return true; 71 72 try { 73 FileSystem fs = fo.getFileSystem(); 74 FileSystem fs2 = fo2.getFileSystem(); 75 if (fs.equals(fs2)) { 76 return fo.equals(fo2); 77 } else { 78 if (absolutePath == null) { 80 File f = FileUtil.toFile(fo); 81 absolutePath = f.getAbsolutePath(); 82 } 83 if (key.absolutePath == null) { 84 File f2 = FileUtil.toFile(fo2); 85 key.absolutePath = f2.getAbsolutePath(); 86 } 87 return absolutePath.equals(key.absolutePath); 88 } 89 } catch (FileStateInvalidException e) { 90 ErrorManager err = ErrorManager.getDefault(); 91 err.notify(e); 92 } 93 } 94 return false; 95 } 96 97 public int hashCode() { 98 return hashCode; 99 } 100 101 public String toString() { 102 if (absolutePath != null) { 103 return absolutePath; 104 } 105 return fileObject.toString(); 106 } 107 } 108 | Popular Tags |