java.io.File#equals ( )源码实例Demo

下面列出了java.io.File#equals ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: hottub   文件: WindowsFileChooserUI.java
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;
                }
            }
        }
    }
}
 
源代码2 项目: rtg-tools   文件: Diagnostic.java
/**
 * 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;
}
 
源代码3 项目: netbeans   文件: FilesystemHandler.java
@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());
        }
    }
}
 
源代码4 项目: JDKSourceCode1.8   文件: WindowsFileChooserUI.java
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;
                }
            }
        }
    }
}
 
源代码5 项目: dragonwell8_jdk   文件: MetalFileChooserUI.java
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;
                }
            }
        }
    }
}
 
源代码6 项目: netbeans   文件: GitUtils.java
/**
 * 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;
}
 
源代码7 项目: BiglyBT   文件: TagBase.java
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 );
			}
		}
	}
}
 
源代码8 项目: portecle   文件: JMenuRecentFiles.java
/**
 * 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;
}
 
源代码9 项目: netbeans   文件: FileEditor.java
/** 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;
}
 
源代码10 项目: netbeans   文件: ImportZIP.java
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;
}
 
源代码11 项目: roboconf-platform   文件: CompletionUtils.java
/**
 * 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;
}
 
源代码12 项目: javaide   文件: ManifestMerger.java
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;
}
 
源代码13 项目: megan-ce   文件: MeganizeDAACommand.java
/**
 * 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;
}
 
源代码14 项目: jdk8u-jdk   文件: FileSystemView.java
/**
 * 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;
}
 
源代码15 项目: FxDock   文件: CKit.java
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;
	}
}
 
源代码16 项目: pumpernickel   文件: OpenDocumentAction.java
/**
 * 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;
}
 
源代码17 项目: birt   文件: ResourceAction.java
/**
 * 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;
}
 
源代码18 项目: netbeans   文件: MercurialInterceptor.java
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();
    }
}
 
源代码19 项目: Pushjet-Android   文件: BaseDirSelector.java
public boolean isSelected(File basedir, String filename, File file) {
    return basedir.equals(this.baseDir);
}
 
源代码20 项目: bubble   文件: DirectoryListingManager.java
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;
}