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:com.cburch.logisim.circuit.CircuitWires.java

void propagate(CircuitState circState, Set<Location> points) {
    BundleMap map = getBundleMap();/*ww  w  .ja  v  a 2s .  com*/
    CopyOnWriteArraySet<WireThread> dirtyThreads = new CopyOnWriteArraySet<WireThread>(); // affected threads

    // get state, or create a new one if current state is outdated
    State s = circState.getWireData();
    if (s == null || s.bundleMap != map) {
        // if it is outdated, we need to compute for all threads
        s = new State(map);
        for (WireBundle b : map.getBundles()) {
            WireThread[] th = b.threads;
            if (b.isValid() && th != null) {
                for (WireThread t : th) {
                    dirtyThreads.add(t);
                }
            }
        }
        circState.setWireData(s);
    }

    // determine affected threads, and set values for unwired points
    for (Location p : points) {
        WireBundle pb = map.getBundleAt(p);
        if (pb == null) { // point is not wired
            circState.setValueByWire(p, circState.getComponentOutputAt(p));
        } else {
            WireThread[] th = pb.threads;
            if (!pb.isValid() || th == null) {
                // immediately propagate NILs across invalid bundles
                CopyOnWriteArraySet<Location> pbPoints = pb.points;
                if (pbPoints == null) {
                    circState.setValueByWire(p, Value.NIL);
                } else {
                    for (Location loc2 : pbPoints) {
                        circState.setValueByWire(loc2, Value.NIL);
                    }
                }
            } else {
                for (WireThread t : th) {
                    dirtyThreads.add(t);
                }
            }
        }
    }

    if (dirtyThreads.isEmpty())
        return;

    // determine values of affected threads
    HashSet<ThreadBundle> bundles = new HashSet<ThreadBundle>();
    for (WireThread t : dirtyThreads) {
        Value v = getThreadValue(circState, t);
        s.thr_values.put(t, v);
        bundles.addAll(t.getBundles());
    }

    // now propagate values through circuit
    for (ThreadBundle tb : bundles) {
        WireBundle b = tb.b;

        Value bv = null;
        if (!b.isValid() || b.threads == null) {
            ; // do nothing
        } else if (b.threads.length == 1) {
            bv = s.thr_values.get(b.threads[0]);
        } else {
            Value[] tvs = new Value[b.threads.length];
            boolean tvs_valid = true;
            for (int i = 0; i < tvs.length; i++) {
                Value tv = s.thr_values.get(b.threads[i]);
                if (tv == null) {
                    tvs_valid = false;
                    break;
                }
                tvs[i] = tv;
            }
            if (tvs_valid)
                bv = Value.create(tvs);
        }

        if (bv != null) {
            for (Location p : b.points) {
                circState.setValueByWire(p, bv);
            }
        }
    }
}

From source file:net.refractions.udig.catalog.internal.CatalogImpl.java

/**
 * Performs a search on this catalog based on the specified inputs. The pattern uses the
 * following conventions: use " " to surround a phase use + to represent 'AND' use - to
 * represent 'OR' use ! to represent 'NOT' use ( ) to designate scope The bbox provided shall be
 * in Lat - Long, or null if the search is not to be contained within a specified area.
 * //www. j  a v  a 2  s.com
 * @see net.refractions.udig.catalog.ICatalog#search(java.lang.String,
 *      com.vividsolutions.jts.geom.Envelope)
 * @param pattern
 * @param bbox used for an intersection test
 * @return
 */
public synchronized List<IResolve> search(String pattern, Envelope bbox, IProgressMonitor monitor2) {
    IProgressMonitor monitor = monitor2;
    if (monitor == null)
        monitor = new NullProgressMonitor();
    if ((pattern == null || "".equals(pattern.trim())) //$NON-NLS-1$
            && (bbox == null || bbox.isNull())) {
        return new LinkedList<IResolve>();
    }

    AST ast = null;
    if (pattern != null && !"".equals(pattern.trim())) //$NON-NLS-1$
        ast = ASTFactory.parse(pattern);

    // TODO check cuncurrency issues here

    List<IResolve> result = new LinkedList<IResolve>();
    HashSet<IService> tmp = new HashSet<IService>();
    tmp.addAll(this.services);
    try {
        monitor.beginTask(Messages.CatalogImpl_finding, tmp.size() * 10);
        Iterator<IService> services = tmp.iterator();
        if (services != null) {
            while (services.hasNext()) {
                IService service = services.next();
                if (check(service, ast)) {
                    result.add(service);
                }
                Iterator<? extends IGeoResource> resources;
                SubProgressMonitor submonitor = new SubProgressMonitor(monitor, 10);
                try {
                    List<? extends IGeoResource> t = service.resources(submonitor);
                    resources = t == null ? null : t.iterator();
                    while (resources != null && resources.hasNext()) {
                        IGeoResource resource = resources.next();
                        if (check(resource, ast, bbox)) {
                            result.add(resource);
                        }
                    }
                } catch (IOException e) {
                    CatalogPlugin.log(null, e);
                } finally {
                    submonitor.done();
                }
            }
        }
        return result;
    } finally {
        monitor.done();
    }
}

From source file:amie.keys.CSAKey.java

public HashSet<HashSet<Integer>> powerSet(HashSet<Integer> originalSet) {
    HashSet<HashSet<Integer>> sets = new HashSet<HashSet<Integer>>();
    if (originalSet.isEmpty()) {
        sets.add(new HashSet<Integer>());
        return sets;
    }/*from  w  w w  . j a v a2s .  c o m*/
    List<Integer> list = new ArrayList<Integer>(originalSet);
    int head = list.get(0);
    HashSet<Integer> rest = new HashSet<Integer>(list.subList(1, list.size()));
    for (HashSet<Integer> set : powerSet(rest)) {
        HashSet<Integer> newSet = new HashSet<Integer>();
        newSet.add(head);
        newSet.addAll(set);
        sets.add(newSet);
        sets.add(set);
    }
    return sets;
}

From source file:org.jactr.core.runtime.controller.OldController.java

final public void waitForStart() throws InterruptedException {
    try {/*  ww  w  . j  a v a  2 s .c  om*/
        _lock.lock();
        /*
         * this is a tad complicated since a model might terminate before wait for
         * Start is even called..
         */
        HashSet<IModel> runningOrTerminated = new HashSet<IModel>(_runningModels);
        runningOrTerminated.addAll(_terminatedModels);
        while (!runningOrTerminated.containsAll(ACTRRuntime.getRuntime().getModels())) {
            _start.await();
            // update the contents
            runningOrTerminated.addAll(_runningModels);
            runningOrTerminated.addAll(_terminatedModels);
        }
    } finally {
        _lock.unlock();
    }
}

From source file:ch.unil.genescore.pathway.GeneSetLibrary.java

License:asdf

/** removes metaGenes that didn't have a score. has to be removed 
 * from metaGenes_ and geneSets_./*from ww w  . java 2 s  . co  m*/
 * */
public void removeMetaGenesWithoutScore() {

    HashSet<MetaGene> metaGenesToBeRemoved = new HashSet<MetaGene>();

    for (GeneSet set : geneSets_) {

        metaGenesToBeRemoved.addAll(set.removeMetaGenesWithoutScore());
    }
    for (MetaGene metaGeneToBeRemoved : metaGenesToBeRemoved)
        metaGenes_.remove(metaGeneToBeRemoved.id_);

}

From source file:och.comp.chats.ChatsAccService.java

public synchronized void reloadAccs() {
    HashSet<String> existsAccs = new HashSet<>();
    read.lock();/*from w ww  . j  av  a2 s .co  m*/
    try {
        existsAccs.addAll(accsById.keySet());
    } finally {
        read.unlock();
    }

    ArrayList<String> added = new ArrayList<>();
    ArrayList<String> removed = new ArrayList<>();
    ArrayList<String> updated = new ArrayList<>();

    List<String> curAccs = getAccIdsNames(root);
    for (String accId : curAccs) {

        File accDir = getAccDir(accId);
        if (hasRemoveReqFlag(accDir))
            continue;

        boolean exists = existsAccs.remove(accId);
        if (exists) {
            boolean isUpdated = reloadAcc(accId);
            if (isUpdated)
                updated.add(accId);
        } else {
            createAcc(accId);
            added.add(accId);
        }
    }

    removed.addAll(existsAccs);
    for (String accountId : existsAccs) {
        removeAcc(accountId);
    }

    if (added.size() > 0)
        log.info("loaded " + added.size() + " accs: " + added);
    if (updated.size() > 0)
        log.info("updated " + updated.size() + " accs: " + updated);
    if (removed.size() > 0)
        log.info("removed " + removed.size() + " accs: " + existsAccs);

}

From source file:org.apache.accumulo.tserver.InMemoryMap.java

public void delete(long waitTime) {

    synchronized (this) {
        if (deleted)
            throw new IllegalStateException("Double delete");

        deleted = true;/*ww  w  .j a  va 2 s  . co m*/
    }

    long t1 = System.currentTimeMillis();

    while (activeIters.size() > 0 && System.currentTimeMillis() - t1 < waitTime) {
        sleepUninterruptibly(50, TimeUnit.MILLISECONDS);
    }

    if (activeIters.size() > 0) {
        // dump memmap exactly as is to a tmp file on disk, and switch scans to that temp file
        try {
            Configuration conf = CachedConfiguration.getInstance();
            FileSystem fs = FileSystem.getLocal(conf);

            String tmpFile = memDumpDir + "/memDump" + UUID.randomUUID() + "." + RFile.EXTENSION;

            Configuration newConf = new Configuration(conf);
            newConf.setInt("io.seqfile.compress.blocksize", 100000);

            AccumuloConfiguration siteConf = SiteConfiguration.getInstance();

            if (getOrCreateSampler() != null) {
                siteConf = createSampleConfig(siteConf);
            }

            FileSKVWriter out = new RFileOperations().newWriterBuilder().forFile(tmpFile, fs, newConf)
                    .withTableConfiguration(siteConf).build();

            InterruptibleIterator iter = map.skvIterator(null);

            HashSet<ByteSequence> allfams = new HashSet<ByteSequence>();

            for (Entry<String, Set<ByteSequence>> entry : lggroups.entrySet()) {
                allfams.addAll(entry.getValue());
                out.startNewLocalityGroup(entry.getKey(), entry.getValue());
                iter.seek(new Range(), entry.getValue(), true);
                dumpLocalityGroup(out, iter);
            }

            out.startDefaultLocalityGroup();
            iter.seek(new Range(), allfams, false);

            dumpLocalityGroup(out, iter);

            out.close();

            log.debug("Created mem dump file " + tmpFile);

            memDumpFile = tmpFile;

            synchronized (activeIters) {
                for (MemoryIterator mi : activeIters) {
                    mi.switchNow();
                }
            }

            // rely on unix behavior that file will be deleted when last
            // reader closes it
            fs.delete(new Path(memDumpFile), true);

        } catch (IOException ioe) {
            log.error("Failed to create mem dump file ", ioe);

            while (activeIters.size() > 0) {
                sleepUninterruptibly(100, TimeUnit.MILLISECONDS);
            }
        }

    }

    SimpleMap tmpMap = map;

    synchronized (this) {
        map = null;
    }

    tmpMap.delete();
}

From source file:amie.keys.CSAKey.java

private Graph mergeGraphs(Graph currentGraph, Graph graph2, HashSet<Node> currentGraphTopNodes,
        HashSet<Integer> conditionProperties) {
    HashSet<Node> childrenNodes = new HashSet<>();
    for (Node currentGraphNewtopNode : currentGraphTopNodes) {
        if (currentGraphNewtopNode.toExplore) {
            //   System.out.println("currentGraphNewtopNode:"+currentGraphNewtopNode);
            if (graph2.graph.containsKey(currentGraphNewtopNode)) {
                // System.out.println("yes");
                Node nodeInGraphNew2 = graph2.getNode(currentGraphNewtopNode);
                if (!nodeInGraphNew2.toExplore) {
                    //   System.out.println("no2");
                    currentGraphNewtopNode.toExplore = false;
                    currentGraph.createOrGetNode(currentGraphNewtopNode);
                } else {
                    // System.out.println("yes2");
                    HashSet<Integer> allProperties = new HashSet<>();
                    allProperties.addAll(conditionProperties);
                    allProperties.addAll(currentGraphNewtopNode.set);
                    //  System.out.println("allProperties:"+allProperties);
                    if (!containsSubSet(allProperties)) {
                        //  System.out.println("no3");
                        currentGraphNewtopNode.toExplore = false;
                        currentGraph.createOrGetNode(currentGraphNewtopNode);
                    }//from   ww w  .  j a v  a 2 s  .c  o m
                }
            } else {
                //   System.out.println("no");
                currentGraphNewtopNode.toExplore = false;
                currentGraph.createOrGetNode(currentGraphNewtopNode);
            }
        }

        if (currentGraph.graph.get(currentGraphNewtopNode) != null) {
            childrenNodes.addAll(currentGraph.graph.get(currentGraphNewtopNode));
        }
    }
    if (!childrenNodes.isEmpty()) {
        mergeGraphs(currentGraph, graph2, childrenNodes, conditionProperties);
    }
    return currentGraph;
}

From source file:aml.match.Alignment.java

/**
  * @return the list of all source classes that have mappings
 *///from ww  w. j a v  a 2s. c  o m
public Set<Integer> getSources() {
    HashSet<Integer> sMaps = new HashSet<Integer>();
    sMaps.addAll(sourceMaps.keySet());
    return sMaps;
}

From source file:aml.match.Alignment.java

/**
  * @return the list of all target classes that have mappings
 *//* w w  w .j  a v a  2  s  .  co  m*/
public Set<Integer> getTargets() {
    HashSet<Integer> tMaps = new HashSet<Integer>();
    tMaps.addAll(targetMaps.keySet());
    return tMaps;
}