Example usage for java.util LinkedHashSet contains

List of usage examples for java.util LinkedHashSet contains

Introduction

In this page you can find the example usage for java.util LinkedHashSet contains.

Prototype

boolean contains(Object o);

Source Link

Document

Returns true if this set contains the specified element.

Usage

From source file:pt.lsts.neptus.util.logdownload.LogsDownloaderWorkerActions.java

private void testingForLogFilesFromEachLogFolderAndFillInfo(LinkedList<LogFolderInfo> tmpLogFolderList) {

    long timeF1 = System.currentTimeMillis();

    Object[] objArray = new Object[gui.logFolderList.myModel.size()];
    gui.logFolderList.myModel.copyInto(objArray);
    for (Object comp : objArray) {
        if (stopLogListProcessing)
            break;

        try {//from   ww w. j  a  va 2  s  . com
            LogFolderInfo logFolder = (LogFolderInfo) comp;

            int indexLFolder = tmpLogFolderList.indexOf(logFolder);
            LinkedHashSet<LogFileInfo> logFilesTmp = (indexLFolder != -1)
                    ? tmpLogFolderList.get(indexLFolder).getLogFiles()
                    : new LinkedHashSet<LogFileInfo>();
            for (LogFileInfo logFx : logFilesTmp) {
                if (stopLogListProcessing)
                    break;

                if (!logFolder.getLogFiles().contains(logFx)) {
                    // The file or directory is new
                    logFolder.addFile(logFx);
                } else {
                    // The file or directory is already known so let us update
                    LogFileInfo lfx = logFolder.getLogFile(logFx.getName()/* fxStr */);
                    if (lfx.getSize() == -1) {
                        lfx.setSize(logFx.getSize());
                    } else if (lfx.getSize() != logFx.getSize()) {
                        // System.out.println("//////////// " + lfx.getSize() + "  " + logFx.getSize());
                        if (lfx.getState() == LogFolderInfo.State.SYNC)
                            lfx.setState(LogFolderInfo.State.INCOMPLETE);
                        else if (lfx.getState() == LogFolderInfo.State.LOCAL)
                            lfx.setState(LogFolderInfo.State.INCOMPLETE);
                        lfx.setSize(logFx.getSize());
                        lfx.setFile(logFx.getFile());
                    } else if (lfx.getSize() == logFx.getSize()) {
                        if (lfx.getState() == LogFolderInfo.State.LOCAL)
                            lfx.setState(LogFolderInfo.State.SYNC);
                    }
                    lfx.setHost(logFx.getHost());

                    if (logFx.isDirectory()) {
                        ArrayList<LogFileInfo> notMatchElements = new ArrayList<>();
                        notMatchElements.addAll(lfx.getDirectoryContents());
                        for (LogFileInfo lfi : logFx.getDirectoryContents()) {
                            boolean alreadyExists = false;
                            for (LogFileInfo lfiLocal : lfx.getDirectoryContents()) {
                                if (lfi.equals(lfiLocal)) {
                                    alreadyExists = true;
                                    notMatchElements.remove(lfiLocal);
                                    lfi.setSize(lfiLocal.getSize());
                                    lfi.setFile(lfiLocal.getFile());
                                    lfi.setHost(lfiLocal.getHost());
                                }
                            }
                            if (!alreadyExists) {
                                lfx.getDirectoryContents().add(lfi);
                                lfx.setState(LogFolderInfo.State.INCOMPLETE);
                            }
                        }
                        for (LogFileInfo lfi : notMatchElements) {
                            lfx.getDirectoryContents().remove(lfi);
                        }
                    }

                    if (lfx.isDirectory()) {
                        if (!LogsDownloaderWorkerUtil.getFileTarget(lfx.getName(),
                                worker.getDirBaseToStoreFiles(), worker.getLogLabel()).exists()) {
                            for (LogFileInfo lfi : lfx.getDirectoryContents()) {
                                if (!LogsDownloaderWorkerUtil.getFileTarget(lfi.getName(),
                                        worker.getDirBaseToStoreFiles(), worker.getLogLabel()).exists()) {
                                    if (lfx.getState() != LogFolderInfo.State.NEW
                                            && lfx.getState() != LogFolderInfo.State.DOWNLOADING)
                                        lfx.setState(LogFolderInfo.State.INCOMPLETE);
                                    break;
                                }
                            }
                        } else {
                            long sizeD = LogsDownloaderWorkerUtil.getDiskSizeFromLocal(lfx, worker);
                            if (lfx.getSize() != sizeD && lfx.getState() == LogFolderInfo.State.SYNC)
                                lfx.setState(LogFolderInfo.State.INCOMPLETE);
                        }
                    } else {
                        if (!LogsDownloaderWorkerUtil.getFileTarget(lfx.getName(),
                                worker.getDirBaseToStoreFiles(), worker.getLogLabel()).exists()) {
                            if (lfx.getState() != LogFolderInfo.State.NEW
                                    && lfx.getState() != LogFolderInfo.State.DOWNLOADING) {
                                lfx.setState(LogFolderInfo.State.INCOMPLETE);
                                // System.out.println("//////////// " + lfx.getName() + "  " + LogsDownloaderUtil.getFileTarget(lfx.getName()).exists());
                            }
                        } else {
                            long sizeD = LogsDownloaderWorkerUtil.getDiskSizeFromLocal(lfx, worker);
                            if (lfx.getSize() != sizeD && lfx.getState() == LogFolderInfo.State.SYNC)
                                lfx.setState(LogFolderInfo.State.INCOMPLETE);
                        }
                    }
                }
            }

            // Put LOCAL state on files not in server
            LinkedHashSet<LogFileInfo> toDelFL = new LinkedHashSet<LogFileInfo>();
            for (LogFileInfo lfx : logFolder.getLogFiles()) {
                if (!logFilesTmp.contains(lfx)
                /* !res.keySet().contains(lfx.getName()) */) {
                    lfx.setState(LogFolderInfo.State.LOCAL);
                    if (!LogsDownloaderWorkerUtil
                            .getFileTarget(lfx.getName(), worker.getDirBaseToStoreFiles(), worker.getLogLabel())
                            .exists()) {
                        toDelFL.add(lfx);
                        // logFolder.getLogFiles().remove(lfx); //This cannot be done here
                    }
                }
            }
            for (LogFileInfo lfx : toDelFL)
                logFolder.getLogFiles().remove(lfx);
        } catch (Exception e) {
            NeptusLog.pub().debug(e.getMessage());
        }
    }

    NeptusLog.pub().warn(".......Testing for log files from each log folder "
            + (System.currentTimeMillis() - timeF1) + "ms");
}

From source file:org.codehaus.mojo.jsimport.AbstractImportMojo.java

/**
 * Build up the dependency graph and global symbol table by parsing the project's dependencies.
 * //ww  w  .jav  a 2 s  . c  o m
 * @param scope compile or test.
 * @param fileDependencyGraphModificationTime the time that the dependency graph was updated. Used for file time
 *            comparisons to check the age of them.
 * @param processedFiles an insert-ordered set of files that have been processed.
 * @param targetFolder Where the target files live.
 * @param workFolder Where we can create some long lived information that may be useful to subsequent builds.
 * @param compileWorkFolder Ditto but in the case of testing it points to where the compile working folder is.
 * @return true if the dependency graph has been updated.
 * @throws MojoExecutionException if something bad happens.
 */
private boolean buildDependencyGraphForDependencies(Scope scope, long fileDependencyGraphModificationTime,
        LinkedHashSet<File> processedFiles, File targetFolder, File workFolder, File compileWorkFolder)
        throws MojoExecutionException {
    File targetJsFolder = new File(targetFolder, "js");

    boolean fileDependencyGraphUpdated = false;

    // Determine how we need to filter things both for direct filtering and transitive filtering.

    String scopeStr = (scope == Scope.COMPILE ? Artifact.SCOPE_COMPILE : Artifact.SCOPE_TEST);

    AndArtifactFilter jsArtifactFilter = new AndArtifactFilter();
    jsArtifactFilter.add(new ScopeArtifactFilter(scopeStr));
    jsArtifactFilter.add(new TypeArtifactFilter("js"));

    AndArtifactFilter wwwZipArtifactFilter = new AndArtifactFilter();
    wwwZipArtifactFilter.add(new ScopeArtifactFilter(scopeStr));
    wwwZipArtifactFilter.add(new TypeArtifactFilter("zip"));
    wwwZipArtifactFilter.add(new ArtifactFilter() {
        public boolean include(Artifact artifact) {
            return artifact.hasClassifier() && artifact.getClassifier().equals("www");
        }
    });

    // Determine the artifacts to resolve and associate their transitive dependencies.

    Map<Artifact, LinkedHashSet<Artifact>> directArtifactWithTransitives = new HashMap<Artifact, LinkedHashSet<Artifact>>(
            dependencies.size());

    Set<Artifact> directArtifacts = new HashSet<Artifact>(dependencies.size());
    LinkedHashSet<Artifact> transitiveArtifacts = new LinkedHashSet<Artifact>();

    for (Dependency dependency : dependencies) {
        // Process imports and symbols of this dependencies' transitives
        // first.
        Artifact directArtifact = artifactFactory.createDependencyArtifact(dependency.getGroupId(),
                dependency.getArtifactId(), VersionRange.createFromVersion(dependency.getVersion()),
                dependency.getType(), dependency.getClassifier(), dependency.getScope());

        if (!jsArtifactFilter.include(directArtifact) && !wwwZipArtifactFilter.include(directArtifact)) {
            continue;
        }

        Set<Artifact> artifactsToResolve = new HashSet<Artifact>(1);
        artifactsToResolve.add(directArtifact);

        ArtifactResolutionResult result;
        try {
            result = resolver.resolveTransitively(artifactsToResolve, project.getArtifact(), remoteRepositories,
                    localRepository, artifactMetadataSource);
        } catch (ArtifactResolutionException e) {
            throw new MojoExecutionException("Problem resolving dependencies", e);
        } catch (ArtifactNotFoundException e) {
            throw new MojoExecutionException("Problem resolving dependencies", e);
        }

        // Associate the transitive dependencies with the direct dependency and aggregate all transitives for
        // collection later.

        LinkedHashSet<Artifact> directTransitiveArtifacts = new LinkedHashSet<Artifact>(
                result.getArtifacts().size());
        for (Object o : result.getArtifacts()) {
            Artifact resolvedArtifact = (Artifact) o;
            if (jsArtifactFilter.include(resolvedArtifact) && //
                    !resolvedArtifact.equals(directArtifact)) {
                directTransitiveArtifacts.add(resolvedArtifact);
            }
        }

        directArtifacts.add(directArtifact);
        transitiveArtifacts.addAll(directTransitiveArtifacts);
        directArtifactWithTransitives.put(directArtifact, directTransitiveArtifacts);
    }

    // Resolve the best versions of the transitives to use by asking Maven to collect them.

    Set<Artifact> collectedArtifacts = new HashSet<Artifact>(
            directArtifacts.size() + transitiveArtifacts.size());
    Map<ArtifactId, Artifact> indexedCollectedDependencies = new HashMap<ArtifactId, Artifact>(
            collectedArtifacts.size());
    try {
        // Note that we must pass an insert-order set into the collector. The collector appears to assume that order
        // is significant, even though it is undocumented.
        LinkedHashSet<Artifact> collectableArtifacts = new LinkedHashSet<Artifact>(directArtifacts);
        collectableArtifacts.addAll(transitiveArtifacts);

        ArtifactResolutionResult resolutionResult = artifactCollector.collect(collectableArtifacts,
                project.getArtifact(), localRepository, remoteRepositories, artifactMetadataSource, null, //
                Collections.EMPTY_LIST);
        for (Object o : resolutionResult.getArtifacts()) {
            Artifact collectedArtifact = (Artifact) o;
            collectedArtifacts.add(collectedArtifact);

            // Build up an index of of collected transitive dependencies so that we can we refer back to them as we
            // process the direct dependencies.
            ArtifactId collectedArtifactId = new ArtifactId(collectedArtifact.getGroupId(),
                    collectedArtifact.getArtifactId());
            indexedCollectedDependencies.put(collectedArtifactId, collectedArtifact);
        }

        if (getLog().isDebugEnabled()) {
            getLog().debug("Dependencies collected: " + collectedArtifacts.toString());
        }
    } catch (ArtifactResolutionException e) {
        throw new MojoExecutionException("Cannot collect dependencies", e);
    }

    // Now go through direct artifacts and process their transitives.

    LocalRepositoryCollector localRepositoryCollector = new LocalRepositoryCollector(project, localRepository,
            new File[] {});

    for (Entry<Artifact, LinkedHashSet<Artifact>> entry : directArtifactWithTransitives.entrySet()) {
        Artifact directArtifact = entry.getKey();
        LinkedHashSet<Artifact> directArtifactTransitives = entry.getValue();

        LinkedHashSet<String> transitivesAsImports = new LinkedHashSet<String>(
                directArtifactTransitives.size());

        for (Object o : directArtifactTransitives) {
            Artifact directTransitiveArtifact = (Artifact) o;

            // Get the transitive artifact that Maven decided was the best to use.

            ArtifactId directTransitiveArtifactId = new ArtifactId(directTransitiveArtifact.getGroupId(),
                    directTransitiveArtifact.getArtifactId());
            Artifact transitiveArtifact = indexedCollectedDependencies.get(directTransitiveArtifactId);

            List<File> transitiveArtifactFiles = getArtifactFiles(transitiveArtifact, targetFolder, workFolder,
                    compileWorkFolder, localRepositoryCollector);

            // Only process this dependency if we've not done so
            // already.
            for (File transitiveArtifactFile : transitiveArtifactFiles) {
                if (!processedFiles.contains(transitiveArtifactFile)) {
                    String localRepository = localRepositoryCollector
                            .findLocalRepository(transitiveArtifactFile.getAbsolutePath());
                    if (localRepository != null) {
                        if (processFileForImportsAndSymbols(new File(localRepository), targetJsFolder,
                                transitiveArtifactFile, fileDependencyGraphModificationTime,
                                directArtifactTransitives)) {

                            processedFiles.add(transitiveArtifactFile);

                            fileDependencyGraphUpdated = true;
                        }
                    } else {
                        throw new MojoExecutionException(
                                "Problem determining local repository for transitive file: "
                                        + transitiveArtifactFile);
                    }
                }

                // Add transitives to the artifacts set of dependencies -
                // as if they were @import statements themselves.
                transitivesAsImports.add(transitiveArtifactFile.getPath());
            }
        }

        // Now deal with the pom specified dependency.
        List<File> artifactFiles = getArtifactFiles(directArtifact, targetFolder, workFolder, compileWorkFolder,
                localRepositoryCollector);
        for (File artifactFile : artifactFiles) {
            String artifactPath = artifactFile.getAbsolutePath();

            // Process imports and symbols of this dependency if we've not
            // already done so.
            if (!processedFiles.contains(artifactFile)) {
                String localRepository = localRepositoryCollector
                        .findLocalRepository(artifactFile.getAbsolutePath());
                if (localRepository != null) {
                    if (processFileForImportsAndSymbols(new File(localRepository), targetJsFolder, artifactFile,
                            fileDependencyGraphModificationTime, null)) {
                        processedFiles.add(artifactFile);

                        fileDependencyGraphUpdated = true;
                    }
                } else {
                    throw new MojoExecutionException(
                            "Problem determining local repository for file: " + artifactFile);
                }
            }

            // Add in our transitives to the dependency graph if they're not
            // already there.
            LinkedHashSet<String> existingImports = fileDependencies.get(artifactPath);
            if (existingImports.addAll(transitivesAsImports)) {
                if (getLog().isDebugEnabled()) {
                    getLog().debug("Using transitives as import: " + transitivesAsImports + " for file: "
                            + artifactPath);
                }
                fileDependencyGraphUpdated = true;
            }
        }

    }

    return fileDependencyGraphUpdated;
}