Java Code Examples for java.io.File#equals()
The following examples show how to use
java.io.File#equals() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: WindowsFileChooserUI.java From hottub with GNU General Public License v2.0 | 6 votes |
private void calculateDepths() { depths = new int[directories.size()]; for (int i = 0; i < depths.length; i++) { File dir = directories.get(i); File parent = dir.getParentFile(); depths[i] = 0; if (parent != null) { for (int j = i-1; j >= 0; j--) { if (parent.equals(directories.get(j))) { depths[i] = depths[j] + 1; break; } } } } }
Example 2
Source File: FileEditor.java From netbeans with Apache License 2.0 | 6 votes |
/** Gets relative path of file to specified directory only for case the file * is in directory tree. * @param baseDir base directory * @param file file which relative path to <code>baseDir</code> is needed * @return relative path or <code>null</code> can't be resolved * or if the <code>file</code> is not under <code>baseDir</code> tree */ static String getChildRelativePath(File baseDir, File file) { // Handle hypothetical weird situations where file is in baseDir // but the prefixes do not match. E.g.: // file=\foo\bar.txt (assumed to be on C:) baseDir=c:\foo if (file.equals(baseDir)) { // The empty pathname, not ".", is correct here I think... // Try making new File(new File("/tmp", x)) for x in {".", ""} return ""; // NOI18N } StringBuilder buf = new StringBuilder(file.getPath().length()); buf.append(file.getName()); for (File parent = file.getParentFile(); parent != null; parent = parent.getParentFile()) { if (parent.equals(baseDir)) { return buf.toString(); } buf.insert(0, File.separatorChar); buf.insert(0, parent.getName()); } return null; }
Example 3
Source File: JMenuRecentFiles.java From portecle with GNU General Public License v2.0 | 6 votes |
/** * Find the recent files array index of the supplied file. * * @param fRecent Recent file to find * @return The array index of the recent file of -1 if there is none */ private int findRecentFile(File fRecent) { int iIndex = -1; for (int iCnt = 0; iCnt < m_jmirf.length; iCnt++) { if (m_jmirf[iCnt] == null) { break; } if (fRecent.equals(m_jmirf[iCnt].getFile())) { iIndex = iCnt; break; } } return iIndex; }
Example 4
Source File: TagBase.java From BiglyBT with GNU General Public License v2.0 | 6 votes |
public void setTagInitialSaveFolder( File folder ) { if ( tag_fl != null ){ File existing = getTagInitialSaveFolder(); if ( existing == null && folder == null ){ return; }else if ( existing == null || folder == null || !existing.equals( folder )){ boolean changed = writeStringAttribute( AT_FL_INIT_LOC, folder==null?null:folder.getAbsolutePath()); if (changed) { tag_type.fireMetadataChanged( this ); } } } }
Example 5
Source File: GitUtils.java From netbeans with Apache License 2.0 | 6 votes |
/** * Returns only those root files from the given context which belong to repository * @param ctx * @param repository * @return */ public static File[] filterForRepository(final VCSContext ctx, final File repository) { File[] files = null; if(ctx != null) { Set<File> s = ctx.getRootFiles(); files = s.toArray(new File[s.size()]); } if (files != null) { List<File> l = new LinkedList<File>(); for (File file : files) { File r = Git.getInstance().getRepositoryRoot(file); if (r != null && r.equals(repository)) { l.add(file); } } files = l.toArray(new File[l.size()]); } return files; }
Example 6
Source File: MetalFileChooserUI.java From dragonwell8_jdk with GNU General Public License v2.0 | 6 votes |
private void calculateDepths() { depths = new int[directories.size()]; for (int i = 0; i < depths.length; i++) { File dir = directories.get(i); File parent = dir.getParentFile(); depths[i] = 0; if (parent != null) { for (int j = i-1; j >= 0; j--) { if (parent.equals(directories.get(j))) { depths[i] = depths[j] + 1; break; } } } } }
Example 7
Source File: WindowsFileChooserUI.java From JDKSourceCode1.8 with MIT License | 6 votes |
private void calculateDepths() { depths = new int[directories.size()]; for (int i = 0; i < depths.length; i++) { File dir = directories.get(i); File parent = dir.getParentFile(); depths[i] = 0; if (parent != null) { for (int j = i-1; j >= 0; j--) { if (parent.equals(directories.get(j))) { depths[i] = depths[j] + 1; break; } } } } }
Example 8
Source File: FilesystemHandler.java From netbeans with Apache License 2.0 | 6 votes |
@Override public void afterCopy(final File from, final File to) { Subversion.LOG.log(Level.FINE, "afterCopy {0} -> {1}", new Object[]{from, to}); File[] files; synchronized(copiedFiles) { copiedFiles.add(from); files = copiedFiles.toArray(new File[copiedFiles.size()]); copiedFiles.clear(); } cache.refreshAsync(true, to); // refresh the whole target tree cache.refreshAsync(files); File parent = to.getParentFile(); if (parent != null) { if (from.equals(to)) { Subversion.LOG.log(Level.WARNING, "Wrong (identity) rename event for {0}", from.getAbsolutePath()); } } }
Example 9
Source File: Diagnostic.java From rtg-tools with BSD 2-Clause "Simplified" License | 6 votes |
/** * Switch the log to a (usually) different output file. * @param newLog the file where the log is to be written. * @return the log (so it can be closed). */ public static synchronized LogStream switchLog(final File newLog) { if (sLogStream != null) { userLog("Switching logfile to:" + newLog.getAbsolutePath()); final File file = sLogStream.file(); if (newLog.equals(file)) { return sLogStream; } //System.err.println("Will delete: " + file.getPath()); sLogStream.removeLog(); } //System.err.println("Switching logfile to:" + log); if (!newLog.getParentFile().exists()) { if (!newLog.getParentFile().mkdirs()) { throw new RuntimeException("Unable to create directory for log file."); } } sLogStream = new LogFile(newLog); sLogClosed = false; logEnvironment(); return sLogStream; }
Example 10
Source File: FileSystemView.java From jdk8u-jdk with GNU General Public License v2.0 | 5 votes |
/** * Determines if the given file is a root in the navigable tree(s). * Examples: Windows 98 has one root, the Desktop folder. DOS has one root * per drive letter, <code>C:\</code>, <code>D:\</code>, etc. Unix has one root, * the <code>"/"</code> directory. * * The default implementation gets information from the <code>ShellFolder</code> class. * * @param f a <code>File</code> object representing a directory * @return <code>true</code> if <code>f</code> is a root in the navigable tree. * @see #isFileSystemRoot */ public boolean isRoot(File f) { if (f == null || !f.isAbsolute()) { return false; } File[] roots = getRoots(); for (File root : roots) { if (root.equals(f)) { return true; } } return false; }
Example 11
Source File: CKit.java From FxDock with Apache License 2.0 | 5 votes |
protected static SB pathToRoot(SB sb, File root, File file, int level) { if(file == null) { return null; } else if(root.equals(file)) { if(level == 0) { return null; } else { return new SB(); } } else { File p = file.getParentFile(); sb = pathToRoot(sb, root, p, level + 1); if(sb == null) { return null; } else if(level > 0) { sb.append(file.getName()); sb.append("/"); } return sb; } }
Example 12
Source File: MeganizeDAACommand.java From megan-ce with GNU General Public License v3.0 | 5 votes |
/** * get directory if this file is currently open * * @param daaFile * @return directory */ private Director findOpenDirector(String daaFile) { final File file = new File(daaFile); if (file.isFile()) { for (IDirector dir : ProjectManager.getProjects()) { File aFile = new File(((Director) dir).getDocument().getMeganFile().getFileName()); if (aFile.isFile() && aFile.equals(file)) return (Director) dir; } } return null; }
Example 13
Source File: OpenDocumentAction.java From pumpernickel with MIT License | 5 votes |
/** * Open a file, or throw a UserCancelledException. * * @param documentFile * if null then this will invoke {@link #browseFile()} to choose * a File. If non-null then this is the document we'll try to * open. * * @return true if this call actually opened a new Document; false if the * Document was already opened and this method only called * {@link DocumentControls#setSelectedDocument(Document)}. */ public boolean openFile(File documentFile) { for (Document d : controls.getOpenDocuments()) { if (documentFile != null && documentFile.equals(d.getFile())) { controls.setSelectedDocument(d); return false; } } if (controls.isSingleDocumentInterface()) { CloseDocumentAction closeAction = controls .getAction(DocumentCommand.CLOSE); closeAction.prepareToCloseSingleDocumentInterface(); } if (documentFile == null) documentFile = browseFile(); if (documentFile == null) throw new UserCancelledException(true); Document newDocument = null; try { newDocument = createDocument(documentFile); } catch (Exception e2) { e2.printStackTrace(); } if (newDocument != null) { if (controls.isSingleDocumentInterface()) { controls.setDocuments(newDocument, new Document[] { newDocument }); } else { controls.getOpenDocuments().add(newDocument); controls.setSelectedDocument(newDocument); } } return true; }
Example 14
Source File: ManifestMerger.java From javaide with GNU General Public License v3.0 | 5 votes |
private static File insertSourceMarkers(@NonNull Node node, @Nullable File currentFile) { for (int i = 0; i < node.getChildNodes().getLength(); i++) { Node child = node.getChildNodes().item(i); short nodeType = child.getNodeType(); if (nodeType == Node.ELEMENT_NODE || nodeType == Node.COMMENT_NODE || nodeType == Node.DOCUMENT_NODE || nodeType == Node.CDATA_SECTION_NODE) { File file = MergerXmlUtils.getFileFor(child); if (file != null && !file.equals(currentFile)) { i += insertSourceMarker(node, child, file, false); currentFile = file; } currentFile = insertSourceMarkers(child, currentFile); } } Node lastElement = node.getLastChild(); while (lastElement != null && lastElement.getNodeType() == Node.TEXT_NODE) { lastElement = lastElement.getPreviousSibling(); } if (lastElement != null && lastElement.getNodeType() == Node.ELEMENT_NODE) { File parentFile = MergerXmlUtils.getFileFor(node); File lastFile = MergerXmlUtils.getFileFor(lastElement); if (lastFile != null && parentFile != null && !parentFile.equals(lastFile)) { insertSourceMarker(node, lastElement, parentFile, true); currentFile = parentFile; } } return currentFile; }
Example 15
Source File: CompletionUtils.java From roboconf-platform with Apache License 2.0 | 5 votes |
/** * Finds all the files that can be imported. * @param searchDirectory the search's directory * @param fileExtension the file extension to search for * @param editedFile the graph file that is being edited * @param fileContent the file content (not null) * @return a non-null set of (relative) file paths */ static Set<String> findFilesToImport( File searchDirectory, String fileExtension, File editedFile, String fileContent ) { // Find all the files Set<String> result = new TreeSet<> (); if( searchDirectory.exists()) { for( File f : Utils.listAllFiles( searchDirectory, fileExtension )) { if( f.equals( editedFile )) continue; String path = Utils.computeFileRelativeLocation( searchDirectory, f ); result.add( path ); } } // Remove those that are already imported Pattern importPattern = Pattern.compile( "\\b" + ParsingConstants.KEYWORD_IMPORT + "\\s+(.*)", Pattern.CASE_INSENSITIVE ); Matcher m = importPattern.matcher( fileContent ); while( m.find()) { String imp = m.group( 1 ).trim(); if( imp.endsWith( ";" )) imp = imp.substring( 0, imp.length() - 1 ); result.remove( imp.trim()); } return result; }
Example 16
Source File: ImportZIP.java From netbeans with Apache License 2.0 | 5 votes |
private static boolean isParentOf( final File dir, final File file) { File tempFile = file; while (tempFile != null && !tempFile.equals(dir)) { tempFile = tempFile.getParentFile(); } return tempFile != null; }
Example 17
Source File: ResourceAction.java From birt with Eclipse Public License 1.0 | 5 votes |
/** * Returns the current selected container. * * @return the current selected container. * @throws IOException * if an I/O error occurs. */ protected File getSelectedContainer( ) throws IOException { if ( includeFragment( getSelectedResources( ) ) ) { return null; } Collection<File> files = getSelectedFiles( ); File folder = null; for ( File file : files ) { File container = file.isDirectory( ) ? file : file.getParentFile( ); if ( container == null ) { return null; } if ( folder == null ) { folder = container; } else if ( !folder.equals( container ) ) { return null; } } return folder == null ? null : folder; }
Example 18
Source File: DirectoryListingManager.java From bubble with MIT License | 4 votes |
public DirectoryListingManager(List<Comic> comics, String libraryDir) { Collections.sort(comics, new Comparator<Comic>() { @Override public int compare(Comic lhs, Comic rhs) { String leftPath = lhs.getFile().getParentFile().getAbsolutePath(); String rightPath = rhs.getFile().getParentFile().getAbsolutePath(); return leftPath.compareTo(rightPath); } }); mComics = comics; mLibraryDir = new File(libraryDir != null ? libraryDir : "/"); List<String> directoryDisplays = new ArrayList<>(); for (Comic comic : mComics) { File comicDir = comic.getFile().getParentFile(); if (comicDir.equals(mLibraryDir)) { directoryDisplays.add("~ (" + comicDir.getName() + ")"); } else if (comicDir.getParentFile().equals(mLibraryDir)) { directoryDisplays.add(comicDir.getName()); } else { List<String> intermediateDirs = new ArrayList<>(); File current = comicDir; while (current != null && !current.equals(mLibraryDir)) { intermediateDirs.add(0, current.getName()); current = current.getParentFile(); } if (current == null) { // impossible, but occurs directoryDisplays.add(comicDir.getName()); } else { directoryDisplays.add(TextUtils.join(" | ", intermediateDirs)); } } } mDirectoryDisplays = directoryDisplays; }
Example 19
Source File: BaseDirSelector.java From Pushjet-Android with BSD 2-Clause "Simplified" License | 4 votes |
public boolean isSelected(File basedir, String filename, File file) { return basedir.equals(this.baseDir); }
Example 20
Source File: MercurialInterceptor.java From netbeans with Apache License 2.0 | 4 votes |
private void hgMoveImplementation(final File srcFile, final File dstFile) throws IOException { final File root = hg.getRepositoryRoot(srcFile); final File dstRoot = hg.getRepositoryRoot(dstFile); Mercurial.LOG.log(Level.FINE, "hgMoveImplementation(): File: {0} {1}", new Object[] {srcFile, dstFile}); // NOI18N boolean result = srcFile.renameTo(dstFile); if (!result && equalPathsIgnoreCase(srcFile, dstFile)) { Mercurial.LOG.log(Level.FINE, "hgMoveImplementation: magic workaround for filename case change {0} -> {1}", new Object[] { srcFile, dstFile }); //NOI18N File temp = FileUtils.generateTemporaryFile(dstFile.getParentFile(), srcFile.getName()); Mercurial.LOG.log(Level.FINE, "hgMoveImplementation: magic workaround, step 1: {0} -> {1}", new Object[] { srcFile, temp }); //NOI18N srcFile.renameTo(temp); Mercurial.LOG.log(Level.FINE, "hgMoveImplementation: magic workaround, step 2: {0} -> {1}", new Object[] { temp, dstFile }); //NOI18N result = temp.renameTo(dstFile); Mercurial.LOG.log(Level.FINE, "hgMoveImplementation: magic workaround completed"); //NOI18N } if (!result) { Mercurial.LOG.log(Level.WARNING, "Cannot rename file {0} to {1}", new Object[] {srcFile, dstFile}); IOException ex = new IOException(); Exceptions.attachLocalizedMessage(ex, NbBundle.getMessage(MercurialInterceptor.class, "MSG_MoveFailed", new Object[] { srcFile, dstFile })); //NOI18N throw ex; } if (root == null) { return; } // no need to do rename after in a background thread, code requiring the bg thread (see #125673) no more exists OutputLogger logger = OutputLogger.getLogger(root); try { if (root.equals(dstRoot) && !HgUtils.isIgnored(dstFile, false)) { // target does not lie under ignored folder and is in the same repo as src HgCommand.doRenameAfter(root, srcFile, dstFile, logger); } else { // just hg rm the old file HgCommand.doRemove(root, srcFile, logger); } } catch (HgException e) { Mercurial.LOG.log(Level.FINE, "Mercurial failed to rename: File: {0} {1}", new Object[]{srcFile.getAbsolutePath(), dstFile.getAbsolutePath()}); // NOI18N } finally { logger.closeLog(); } }