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:org.ayound.js.debug.ui.DebugMainFrame.java

public void openHtmlFile(File file) {

    for (int i = 0; i < mainPane.countComponents(); i++) {
        String tips = mainPane.getToolTipTextAt(i);
        if (file.equals(new File(tips))) {
            mainPane.setSelectedIndex(i);
            return;
        }/*from   w w  w.  j  a  v  a2 s. c  om*/
    }
    HtmlEditor editor = new HtmlEditor();
    editor.openFile(file);
    mainPane.addTab(file.getName(), null, editor, file.getAbsolutePath());
    mainPane.setSelectedComponent(editor);

}

From source file:org.ayound.js.debug.ui.DebugMainFrame.java

public void openJsFile(File file) {

    for (int i = 0; i < mainPane.countComponents(); i++) {
        String tips = mainPane.getToolTipTextAt(i);
        if (file.equals(new File(tips))) {
            mainPane.setSelectedIndex(i);
            return;
        }/*from  ww  w . j ava 2s. c om*/
    }
    JsEditor editor = new JsEditor();
    editor.openFile(file);
    mainPane.addTab(file.getName(), null, editor, file.getAbsolutePath());
    mainPane.setSelectedComponent(editor);

}

From source file:org.dbgl.model.Mount.java

public File canBeUsedFor(final File hostFile) {
    if (!unmounted) {
        File canHostFile = FileUtils.getCanMainFile(hostFile);
        File mountFile = FileUtils.canonicalToDosroot(getPathAsString());
        if (mountingType != MountingType.DIR && (FileUtils.isIsoFile(canHostFile.getPath())
                || FileUtils.isArchive(canHostFile.getPath()) || FileUtils.isFatImage(canHostFile.getPath()))) {
            return (mountFile.equals(canHostFile))
                    ? FileUtils.makeRelativeTo(FileUtils.canonicalToDosroot(hostFile.getPath()),
                            FileUtils.canonicalToDosroot(getHostPathAsString()))
                    : null;/*from ww w . ja va 2s  .  c  o  m*/
        }
        if (FileUtils.areRelated(mountFile, canHostFile)) {
            if ((hostFile.getPath().indexOf('~') > 0)) {
                if (hostFile.isAbsolute())
                    canHostFile = hostFile;
                else
                    canHostFile = new File(FileUtils.getDosRoot(), hostFile.getPath());
            }
            return FileUtils.makeRelativeTo(canHostFile, mountFile);
        }
    }
    return null;
}

From source file:de.jcup.egradle.core.util.FileSupport.java

/**
 * Checks if given file is inside given folder
 * // w w  w.  ja  va 2 s .  c  o m
 * @param file
 * @param expectedFolder
 * @return <code>true</code> when inside folder or one of its sub folders
 */
public boolean isInside(File file, File expectedFolder) {
    if (file == null) {
        return false;
    }
    if (expectedFolder == null) {
        return false;
    }
    boolean isInside = false;
    File parent = file;

    while (!isInside && parent != null) {
        parent = parent.getParentFile();

        if (parent == null) {
            continue;
        }

        if (expectedFolder.equals(parent)) {
            isInside = true;
        }

    }

    return isInside;
}

From source file:org.apache.maven.plugin.javadoc.JavadocUtil.java

/**
 * Method that gets the files or classes that would be included in the javadocs using the subpackages
 * parameter.//from w ww . ja  va  2 s  .c om
 *
 * @param sourceDirectory the directory where the source files are located
 * @param fileList        the list of all files found in the sourceDirectory
 * @param excludePackages package names to be excluded in the javadoc
 * @return a StringBuilder that contains the appended file names of the files to be included in the javadoc
 */
protected static List<String> getIncludedFiles(File sourceDirectory, String[] fileList,
        String[] excludePackages) {
    List<String> files = new ArrayList<String>();

    for (String aFileList : fileList) {
        boolean include = true;
        for (int k = 0; k < excludePackages.length && include; k++) {
            // handle wildcards (*) in the excludePackageNames
            String[] excludeName = excludePackages[k].split("[*]");

            if (excludeName.length == 0) {
                continue;
            }

            if (excludeName.length > 1) {
                int u = 0;
                while (include && u < excludeName.length) {
                    if (!"".equals(excludeName[u].trim()) && aFileList.contains(excludeName[u])) {
                        include = false;
                    }
                    u++;
                }
            } else {
                if (aFileList.startsWith(sourceDirectory.toString() + File.separatorChar + excludeName[0])) {
                    if (excludeName[0].endsWith(String.valueOf(File.separatorChar))) {
                        int i = aFileList.lastIndexOf(File.separatorChar);
                        String packageName = aFileList.substring(0, i + 1);
                        File currentPackage = new File(packageName);
                        File excludedPackage = new File(sourceDirectory, excludeName[0]);
                        if (currentPackage.equals(excludedPackage)
                                && aFileList.substring(i).contains(".java")) {
                            include = true;
                        } else {
                            include = false;
                        }
                    } else {
                        include = false;
                    }
                }
            }
        }

        if (include) {
            files.add(quotedPathArgument(aFileList));
        }
    }

    return files;
}

From source file:org.jsweet.input.typescriptdef.ast.Context.java

public CompilationUnit getCompilationUnit(File tsDefFile) {
    for (CompilationUnit compilUnit : compilationUnits) {
        if (tsDefFile.equals(compilUnit.file)) {
            return compilUnit;
        }// w  w  w .ja  va 2  s .co m
    }

    return null;
}

From source file:com.opendoorlogistics.core.distances.DistancesSingleton.java

/**
 * @param request//from ww w.j  a v  a2  s  .c om
 * @param processingApi
 */
private synchronized void initGraphhopperGraph(DistancesConfiguration request,
        final ProcessingApi processingApi) {
    String dir = request.getGraphhopperConfig().getGraphDirectory();

    File current = RelativeFiles.validateRelativeFiles(dir, AppConstants.GRAPHHOPPER_DIRECTORY);
    current = current.getAbsoluteFile();

    if (processingApi != null) {
        processingApi.postStatusMessage("Loading the road network graph: " + current.getAbsolutePath());
    }

    // check current file is valid
    if (!current.exists() || !current.isDirectory()) {
        throw new RuntimeException("Invalid Graphhopper directory: " + dir);
    }

    // check if last one has an invalid file
    if (lastCHGraph != null) {
        File file = new File(lastCHGraph.getGraphFolder());
        if (!file.exists() || !file.isDirectory()) {
            lastCHGraph.dispose();
            lastCHGraph = null;
        }
    }

    // check if using different file
    if (lastCHGraph != null) {
        File lastFile = new File(lastCHGraph.getGraphFolder());
        if (!lastFile.equals(current)) {
            lastCHGraph.dispose();
            lastCHGraph = null;
        }
    }

    // load the graph if needed
    if (lastCHGraph == null) {
        lastCHGraph = new CHMatrixGenWithGeomFuncs(current.getAbsolutePath());
    }
}

From source file:com.asakusafw.operation.tools.hadoop.fs.CleanTest.java

private File touch(String path, double day) throws IOException {
    File file = file(path);//  w w  w  . j a  v a  2  s  .c o m
    if (file.exists() == false) {
        file.getParentFile().mkdirs();
        try {
            file.createNewFile();
        } catch (IOException e) {
            throw new AssertionError(e);
        }
    }
    File root = folder.getRoot().getCanonicalFile();
    File current = file;
    while (true) {
        current = current.getCanonicalFile();
        if (root.equals(current)) {
            break;
        }
        boolean succeed = current.setLastModified((long) (day * TimeUnit.DAYS.toMillis(1)));
        if (succeed == false) {
            break;
        }
        current = current.getParentFile();
        if (current == null) {
            break;
        }
    }
    return file;
}

From source file:org.apache.flex.compiler.internal.projects.SourcePathManager.java

private void accumulateQNameFiles(Set<QNameFile> qNameFiles, File directory, String baseQName, String locale,
        Collection<ICompilerProblem> problems, int order) {
    assert directory.isDirectory();
    assert directory.equals(FilenameNormalization.normalize(directory));
    File[] files = directory.listFiles();
    if (files == null) {
        problems.add(new UnableToListFilesProblem(directory));
        return;//www .  j a v  a 2s.c om
    }
    for (final File file : directory.listFiles()) {
        assert file.equals(FilenameNormalization.normalize(file));

        if (file.isDirectory()) {
            accumulateQNameFiles(qNameFiles, file, baseQName + file.getName() + ".", locale, problems, order);
        } else if (compilerProject.getSourceCompilationUnitFactory().canCreateCompilationUnit(file)) {
            String className = FilenameUtils.getBaseName(file.getName());
            String qName = baseQName + className;
            qNameFiles.add(new QNameFile(qName, file, locale, order));
        }
    }
}

From source file:org.geoserver.importer.Directory.java

@Override
public void prepare(ProgressMonitor m) throws IOException {
    files = new ArrayList<FileData>();

    //recursively search for spatial files, maintain a queue of directories to recurse into
    LinkedList<File> q = new LinkedList<File>();
    q.add(file);//from   w ww .  ja va2s  . c  o m

    while (!q.isEmpty()) {
        File dir = q.poll();

        if (m.isCanceled()) {
            return;
        }
        m.setTask("Scanning " + dir.getPath());

        //get all the regular (non directory) files
        Set<File> all = new LinkedHashSet<File>(Arrays.asList(dir.listFiles(new FilenameFilter() {
            public boolean accept(File dir, String name) {
                return !new File(dir, name).isDirectory();
            }
        })));

        //scan all the files looking for spatial ones
        for (File f : dir.listFiles()) {
            if (f.isHidden()) {
                all.remove(f);
                continue;
            }
            if (f.isDirectory()) {
                if (!recursive && !f.equals(file)) {
                    //skip it
                    continue;
                }
                // @hacky - ignore __MACOSX
                // this could probably be dealt with in a better way elsewhere
                // like by having Directory ignore the contents since they
                // are all hidden files anyway
                if (!"__MACOSX".equals(f.getName())) {
                    Directory d = new Directory(f);
                    d.prepare(m);

                    files.add(d);
                }
                //q.push(f);
                continue;
            }

            //special case for .aux files, they are metadata but get picked up as readable 
            // by the erdas imagine reader...just ignore them for now 
            if ("aux".equalsIgnoreCase(FilenameUtils.getExtension(f.getName()))) {
                continue;
            }

            //determine if this is a spatial format or not
            DataFormat format = DataFormat.lookup(f);

            if (format != null) {
                SpatialFile sf = newSpatialFile(f, format);

                //gather up the related files
                sf.prepare(m);

                files.add(sf);

                all.removeAll(sf.allFiles());
            }
        }

        //take any left overs and add them as unspatial/unrecognized
        for (File f : all) {
            files.add(new ASpatialFile(f));
        }
    }

    format = format();
    //        //process ignored for files that should be grouped with the spatial files
    //        for (DataFile df : files) {
    //            SpatialFile sf = (SpatialFile) df;
    //            String base = FilenameUtils.getBaseName(sf.getFile().getName());
    //            for (Iterator<File> i = ignored.iterator(); i.hasNext(); ) {
    //                File f = i.next();
    //                if (base.equals(FilenameUtils.getBaseName(f.getName()))) {
    //                    //.prj file?
    //                    if ("prj".equalsIgnoreCase(FilenameUtils.getExtension(f.getName()))) {
    //                        sf.setPrjFile(f);
    //                    }
    //                    else {
    //                        sf.getSuppFiles().add(f);
    //                    }
    //                    i.remove();
    //                }
    //            }
    //        }
    //        
    //        //take any left overs and add them as unspatial/unrecognized
    //        for (File f : ignored) {
    //            files.add(new ASpatialFile(f));
    //        }
    //        
    //        return files;
    //        
    //        for (DataFile f : files()) {
    //            f.prepare();
    //        }
}