Example usage for java.util HashSet addAll

List of usage examples for java.util HashSet addAll

Introduction

In this page you can find the example usage for java.util HashSet addAll.

Prototype

boolean addAll(Collection<? extends E> c);

Source Link

Document

Adds all of the elements in the specified collection to this set if they're not already present (optional operation).

Usage

From source file:io.seldon.api.state.ZkSubscriptionHandler.java

public Collection<ChildData> getImmediateChildren(String node) {
    HashSet<ChildData> toReturn = new HashSet<>();

    TreeCache cache = findParentCache(node);
    if (cache == null)
        return Collections.EMPTY_LIST;

    Map<String, ChildData> children = cache.getCurrentChildren(node);
    if (children == null)
        return toReturn;
    for (ChildData child : children.values())
        toReturn.addAll(getChildren(child.getPath(), cache));
    toReturn.addAll(children.values());/*from  ww  w  .  ja  v  a 2 s  .  com*/
    return toReturn;
}

From source file:ca.sfu.federation.model.InputTable.java

/**
 * Get all dependancies for the Inputs in this InputTable.
 * @return SystolicArrayElements upon which this InputTable is dependant.
 * TODO: need to think about caching the dependancy list and how updates on the user input on Inputs can propagate dependancy updates to the SAE
 * TODO: need to think about whether order of dep list is significant, and therefore should be changed to a List output
 *///w ww .  j  av  a  2  s . c  om
public Map getDependancies() {
    // init
    HashSet dep = new HashSet();
    // add dependancies for each input to the set
    Iterator e = this.inputs.iterator();
    while (e.hasNext()) {
        Input input = (Input) e.next();
        dep.addAll((HashSet) input.getDependancies());
    }
    // convert to map
    // should revisit this at some point .. doesn't make sense any more
    LinkedHashMap result = new LinkedHashMap();
    Iterator iter = dep.iterator();
    while (iter.hasNext()) {
        INamed named = (INamed) iter.next();
        result.put(named.getName(), named);
    }
    // return result
    return (Map) result;
}

From source file:it.iit.genomics.cru.simsearch.bundle.utils.AnnotationsFromTrack.java

public int getNumberOfMatchings(String annotationType) {
    HashSet<String> matching = new HashSet<>();
    matching.addAll(matchingMappedByAnnotationType.get(annotationType));
    return matching.size();
}

From source file:org.apache.hadoop.yarn.server.resourcemanager.monitor.capacity.FifoIntraQueuePreemptionPlugin.java

private PriorityQueue<TempAppPerPartition> createTempAppForResCalculation(String partition,
        Collection<FiCaSchedulerApp> apps, TAPriorityComparator taComparator) {
    PriorityQueue<TempAppPerPartition> orderedByPriority = new PriorityQueue<>(100, taComparator);

    // have an internal temp app structure to store intermediate data(priority)
    for (FiCaSchedulerApp app : apps) {

        Resource used = app.getAppAttemptResourceUsage().getUsed(partition);
        Resource amUsed = null;//from   www .  ja v  a2 s. com
        if (!app.isWaitingForAMContainer()) {
            amUsed = app.getAMResource(partition);
        }
        Resource pending = app.getTotalPendingRequestsPerPartition().get(partition);
        Resource reserved = app.getAppAttemptResourceUsage().getReserved(partition);

        used = (used == null) ? Resources.createResource(0, 0) : used;
        amUsed = (amUsed == null) ? Resources.createResource(0, 0) : amUsed;
        pending = (pending == null) ? Resources.createResource(0, 0) : pending;
        reserved = (reserved == null) ? Resources.createResource(0, 0) : reserved;

        HashSet<String> partitions = new HashSet<String>(
                app.getAppAttemptResourceUsage().getNodePartitionsSet());
        partitions.addAll(app.getTotalPendingRequestsPerPartition().keySet());

        // Create TempAppPerQueue for further calculation.
        TempAppPerPartition tmpApp = new TempAppPerPartition(app, Resources.clone(used),
                Resources.clone(amUsed), Resources.clone(reserved), Resources.clone(pending));

        // Set ideal allocation of app as 0.
        tmpApp.idealAssigned = Resources.createResource(0, 0);

        orderedByPriority.add(tmpApp);
    }
    return orderedByPriority;
}

From source file:com.tamingtext.tagrecommender.TestStackOverflowTagger.java

public void execute() {
    PrintStream out = null;/*from  w w w  . ja v  a 2s .  c  o m*/

    try {
        OpenObjectIntHashMap<String> tagCounts = new OpenObjectIntHashMap<String>();
        OpenObjectIntHashMap<String> tagCorrect = new OpenObjectIntHashMap<String>();
        loadTags(tagCounts);

        StackOverflowStream stream = new StackOverflowStream();
        stream.open(inputFile.getAbsolutePath());

        out = new PrintStream(new FileOutputStream(outputFile));

        int correctTagCount = 0;
        int postCount = 0;

        HashSet<String> postTags = new HashSet<String>();
        float postPctCorrect;

        int totalSingleCorrect = 0;
        int totalHalfCorrect = 0;

        for (StackOverflowPost post : stream) {
            correctTagCount = 0;
            postCount++;

            postTags.clear();
            postTags.addAll(post.getTags());
            for (String tag : post.getTags()) {
                if (tagCounts.containsKey(tag)) {
                    tagCounts.adjustOrPutValue(tag, 1, 1);
                }
            }

            ScoreTag[] tags = client.getTags(post.getTitle() + "\n" + post.getBody(), maxTags);

            for (ScoreTag tag : tags) {
                if (postTags.contains(tag.getTag())) {
                    correctTagCount += 1;
                    tagCorrect.adjustOrPutValue(tag.getTag(), 1, 1);
                }
            }

            if (correctTagCount > 0) {
                totalSingleCorrect += 1;
            }

            postPctCorrect = correctTagCount / (float) postTags.size();
            if (postPctCorrect >= 0.50f) {
                totalHalfCorrect += 1;
            }

            if ((postCount % 100) == 0) {
                dumpStats(System.err, postCount, totalSingleCorrect, totalHalfCorrect);
            }

        }

        dumpStats(System.err, postCount, totalSingleCorrect, totalHalfCorrect);
        dumpStats(out, postCount, totalSingleCorrect, totalHalfCorrect);
        dumpTags(out, tagCounts, tagCorrect);
    } catch (Exception ex) {
        throw (RuntimeException) new RuntimeException().initCause(ex);
    } finally {
        if (out != null) {
            out.close();
        }
    }
}

From source file:com.izforge.izpack.core.rules.process.ExistsCondition.java

@Override
public Set<String> getVarRefs() {
    HashSet<String> vars = new HashSet<String>(2);
    switch (contentType) {
    case VARIABLE:
        if (this.content != null) {
            // variable is used in this case
            vars.add(this.content);
        }//from   w w w .j  av  a2  s .c  o m
        break;
    case FILE:
        if (this.content != null) {
            // variables are resolved here
            vars.addAll(ValueUtils.parseUnresolvedVariableNames(this.content));
        }
        break;
    default:
        throw new CompilerException("Unimplemented contentType");
    }
    return vars;
}

From source file:edu.uga.cs.fluxbuster.clustering.DomainCluster.java

/**
 * Gets the domain names in the cluster.
 *
 * @return the set of domain names/*from   www .  ja va  2s. com*/
 */
public Set<String> getDomains() {
    HashSet<String> retval = new HashSet<String>();
    retval.addAll(this.domains);
    return retval;
}

From source file:DirectoryWalker.java

/**
 * Get all the Directories in the starting directory (and sub dirs)
 * returns only files ending this the filename
 * @param startingDirectory/*  w w w .  j  a  va2s.  c o  m*/
 * @return filesFound (as HashSet)
 * @exception java.io.IOException
 */
public static HashSet getDirs(String startingDirectory) throws java.io.IOException {

    //Local Variables
    String tmpFullFile;
    String tmpSubDir;
    File startDir = new File(startingDirectory);
    File tmpFile;
    String[] thisDirContents;
    HashSet dirsFound = new HashSet();
    HashSet subDirFilesFound;

    //Check that this is a valid directory
    if (!startDir.isDirectory()) {
        throw new java.io.IOException(startingDirectory + " was not a valid directory");
    }

    //Add the current directory to the output list
    dirsFound.add(startingDirectory);

    //Get the contents of the current directory
    thisDirContents = startDir.list();

    if (thisDirContents != null) {
        //Now loop through , apply filter , or adding them to list of sub dirs
        for (int a = 0; a < thisDirContents.length; a++) {

            //Get Handle to (full) file (inc path)  
            tmpFullFile = FileUtil.combineFileAndDirectory(thisDirContents[a], startingDirectory);

            tmpFile = new File(tmpFullFile);

            //We're only interested in directories
            if (tmpFile.isDirectory()) {

                //Add this to the directory list
                dirsFound.add(tmpFullFile);

                //Now Do Recursive Call (to this method)if Directory
                tmpSubDir = FileUtil.combineFileAndDirectory(thisDirContents[a], startingDirectory);
                subDirFilesFound = DirectoryWalker.getDirs(tmpSubDir);
                dirsFound.addAll(subDirFilesFound);
            }

        }
    }

    return dirsFound;

}

From source file:org.hyperic.hq.measurement.server.session.TemplateManagerImpl.java

/**
 * Set the measurement templates to be "designated" for a monitorable type.
 *///from  w w  w .  ja  va 2s. c  o m
public void setDesignatedTemplates(String mType, Integer[] desigIds) {

    List<MeasurementTemplate> derivedTemplates = measurementTemplateDAO.findDerivedByMonitorableType(mType);
    HashSet<Integer> designates = new HashSet<Integer>();
    designates.addAll(Arrays.asList(desigIds));

    for (MeasurementTemplate template : derivedTemplates) {

        // Never turn off Availability as an indicator
        if (template.isAvailability())
            continue;

        boolean designated = designates.contains(template.getId());
        if (designated != template.isDesignate())
            template.setDesignate(designated);
    }
}