Example usage for java.io File equals

List of usage examples for java.io File equals

Introduction

In this page you can find the example usage for java.io File equals.

Prototype

public boolean equals(Object obj) 

Source Link

Document

Tests this abstract pathname for equality with the given object.

Usage

From source file:net.sf.jabref.importer.ImportCustomizationDialog.java

/**
 * Converts a path relative to a base-path into a class name.
 *
 * @param basePath  base path//from w  ww  .  j av  a2s. com
 * @param path  path that includes base-path as a prefix
 * @return  class name
 */
private static String pathToClass(File basePath, File path) {
    String className = null;
    File actualPath = path;
    // remove leading basepath from path
    while (!actualPath.equals(basePath)) {
        className = actualPath.getName() + (className == null ? "" : "." + className);
        actualPath = actualPath.getParentFile();
    }
    if (className != null) {
        int lastDot = className.lastIndexOf('.');
        if (lastDot < 0) {
            return className;
        }
        className = className.substring(0, lastDot);
    }
    return className;
}

From source file:com.bc.util.io.FileUtils.java

public static boolean directoryContainsFile(File treeRoot, File file) {
    File fileToLookForInTreeRoot = file;
    while (fileToLookForInTreeRoot != null) {
        if (treeRoot.equals(fileToLookForInTreeRoot)) {
            return true;
        }//ww w  .ja  v a2  s .  c o m
        fileToLookForInTreeRoot = fileToLookForInTreeRoot.getParentFile();
    }
    return false;
}

From source file:org.alfresco.extension.bulkimport.source.fs.FilesystemSourceUtils.java

private final static boolean isInDirectoryImpl(final File directory, final File suspectedChild) {
    boolean result = false;

    if (directory != null && suspectedChild != null) {
        if (suspectedChild.equals(directory)) {
            result = true;//w  w w .  j  ava2  s  .co  m
        } else {
            result = isInDirectoryImpl(directory, suspectedChild.getParentFile());
        }
    }

    return (result);
}

From source file:org.apache.maven.shared.release.util.ReleaseUtil.java

public static File getStandardPom(MavenProject project) {
    if (project == null) {
        return null;
    }//from www  . j ava  2 s. c  om

    File pom = project.getFile();

    if (pom == null) {
        return null;
    }

    File releasePom = getReleasePom(project);
    if (pom.equals(releasePom)) {
        pom = new File(pom.getParent(), POMv4);
    }

    return pom;
}

From source file:org.apache.maven.shared.release.util.ReleaseUtil.java

public static int getBaseWorkingDirectoryParentCount(String basedir, String workingDirectory) {
    int num = 0;//w  w  w  .j ava 2s . c o m

    // we can safely assume case-insensitivity as we are just backtracking, not comparing. This helps with issues
    // on Windows with C: vs c:
    workingDirectory = FilenameUtils.normalize(workingDirectory.toLowerCase(Locale.ENGLISH));
    basedir = FilenameUtils.normalize(basedir.toLowerCase(Locale.ENGLISH));

    // MRELEASE-663
    // For Windows is does matter if basedir ends with a file-separator or not to be able to compare.
    // Using the parent of a dummy file makes it possible to compare them OS-independent
    File workingDirectoryFile = new File(workingDirectory, ".tmp").getParentFile();
    File basedirFile = new File(basedir, ".tmp").getParentFile();

    if (!workingDirectoryFile.equals(basedirFile) && workingDirectory.startsWith(basedir)) {
        do {
            workingDirectoryFile = workingDirectoryFile.getParentFile();
            num++;
        } while (!workingDirectoryFile.equals(basedirFile));
    }
    return num;
}

From source file:arena.utils.FileUtils.java

public static String constructOurCanonicalVersion(File current, File stopPoint) {
    int backOnes = 0;
    StringBuffer ourCanonicalVersion = new StringBuffer();
    while ((current != null) && !current.equals(stopPoint)) {
        if (current.getName().equals("..")) {
            backOnes++;/*from  ww  w.  jav a  2  s  .  co m*/
        } else if (current.getName().equals(".")) {
            // skip - do nothing
        } else if (backOnes > 0) {
            backOnes--;
        } else {
            ourCanonicalVersion.insert(0, "/" + current.getName());
        }
        current = current.getParentFile();
    }
    return ourCanonicalVersion.toString();
}

From source file:eu.stratosphere.library.clustering.DistributedOnePassKMeans.Util.java

private static File createAndRegisterTempFile(String fileName) throws IOException {
    File baseDir = new File(System.getProperty("java.io.tmpdir"));
    File f = new File(baseDir, fileName);

    if (f.exists()) {
        deleteRecursively(f);/*from   ww w . jav  a2  s  . c  o m*/
    }

    File parentToDelete = f;
    while (true) {
        File parent = parentToDelete.getParentFile();
        if (parent == null) {
            throw new IOException("Missed temp dir while traversing parents of a temp file.");
        }
        if (parent.equals(baseDir)) {
            break;
        }
        parentToDelete = parent;
    }

    Files.createParentDirs(f);
    tempFiles.add(parentToDelete);
    return f;
}

From source file:org.apache.oodt.cas.filemgr.versioning.VersioningUtils.java

public static List<String> getURIsFromDir(File dirRoot) {
    List<String> uris;

    if (dirRoot == null) {
        throw new IllegalArgumentException("null");
    }/*from   w ww .  ja v  a  2 s .  c om*/
    if (!dirRoot.isDirectory()) {
        dirRoot = dirRoot.getParentFile();
    }

    uris = new Vector<String>();

    Stack<File> stack = new Stack<File>();
    stack.push(dirRoot);
    while (!stack.isEmpty()) {
        File dir = stack.pop();
        // add the reference for the dir
        // except if it's the rootDir, then, skip it
        if (!dir.equals(dirRoot)) {
            uris.add(dir.toURI().toString());
        }

        File[] files = dir.listFiles(FILE_FILTER);

        if (files != null) {
            for (File file : files) {
                // add the file references
                uris.add(file.toURI().toString());
            }
        }

        File[] subdirs = dir.listFiles(DIR_FILTER);
        if (subdirs != null) {
            for (File subdir : subdirs) {
                stack.push(subdir);
            }
        }
    }

    return uris;
}

From source file:net.sf.nmedit.nordmodular.NmFileService.java

public static boolean isFileAlreadyOpen(File file) {
    final DefaultDocumentManager dm = Nomad.sharedInstance().getDocumentManager();
    for (Document d : dm.getDocuments()) {
        if (d instanceof PatchDocument) {
            if (file.equals(d.getFile()))
                return true;
        }// w ww.j  a va 2s  .  co m
    }
    return false;
}

From source file:org.onos.yangtools.yang2sources.plugin.Util.java

static Collection<File> listFiles(File root, File[] excludedFiles, Log log) throws FileNotFoundException {
    if (!root.exists()) {
        if (log != null) {
            log.warn(Util.message("YANG source directory %s not found. No code will be generated.",
                    YangToSourcesProcessor.LOG_PREFIX, root.toString()));
        }//ww w.j  ava2 s  .c o  m
        return Collections.emptyList();
    }
    Collection<File> result = new ArrayList<>();
    Collection<File> yangFiles = FileUtils.listFiles(root, new String[] { YANG_SUFFIX }, true);
    for (File f : yangFiles) {
        boolean excluded = false;
        for (File ex : excludedFiles) {
            if (ex.equals(f)) {
                excluded = true;
                break;
            }
        }
        if (excluded) {
            if (log != null) {
                log.info(Util.message("%s file excluded %s", YangToSourcesProcessor.LOG_PREFIX,
                        Util.YANG_SUFFIX.toUpperCase(), f));
            }
        } else {
            result.add(f);
        }
    }

    return result;
}