Example usage for java.util Queue add

List of usage examples for java.util Queue add

Introduction

In this page you can find the example usage for java.util Queue add.

Prototype

boolean add(E e);

Source Link

Document

Inserts the specified element into this queue if it is possible to do so immediately without violating capacity restrictions, returning true upon success and throwing an IllegalStateException if no space is currently available.

Usage

From source file:org.lunarray.model.descriptor.scanner.AnnotationScannerUtil.java

/**
 * Tests if the marker marks the annotation.
 * /*from   w  w  w .  j  a  v a 2  s .  com*/
 * @param marker
 *            The marker.
 * @param annotation
 *            The annotation. May not be null.
 * @param transitive
 *            Whether or not to transitively traverse.
 * @return True if and only if the marker marks the annotation.
 */
private boolean isMarkedInternal(final Class<? extends Annotation> marker,
        final Class<? extends Annotation> annotation, final boolean transitive) {
    Validate.notNull(annotation, "Annotation type may not be null.");
    boolean marked = false;
    if (annotation.equals(marker)) {
        marked = true;
    } else if (transitive) {
        final Set<Class<? extends Annotation>> processed = AnnotationScannerUtil.createSet();
        final Queue<Class<? extends Annotation>> process = new LinkedList<Class<? extends Annotation>>();
        process.add(annotation);
        marked = this.isMarkedTransiviteProcess(marker, processed, process);
    }
    return marked;
}

From source file:edu.toronto.cs.phenotips.solr.HPOScriptService.java

/**
 * Get the HPO IDs of the specified phenotype and all its ancestors.
 * /*w  w w.j a  v  a  2  s .  c o m*/
 * @param id the HPO identifier to search for, in the {@code HP:1234567} format
 * @return the full set of ancestors-or-self IDs, or an empty set if the requested ID was not found in the index
 */
public Set<String> getAllAncestorsAndSelfIDs(final String id) {
    Set<String> results = new HashSet<String>();
    Queue<SolrDocument> nodes = new LinkedList<SolrDocument>();
    SolrDocument crt = this.get(id);
    if (crt == null) {
        return results;
    }
    nodes.add(crt);
    while (!nodes.isEmpty()) {
        crt = nodes.poll();
        results.add(String.valueOf(crt.get(ID_FIELD_NAME)));
        @SuppressWarnings("unchecked")
        List<String> parents = (List<String>) crt.get("is_a");
        if (parents == null) {
            continue;
        }
        for (String pid : parents) {
            nodes.add(this.get(StringUtils.substringBefore(pid, " ")));
        }
    }
    return results;
}

From source file:it.geosolutions.geobatch.imagemosaic.ImageMosaicUpdateTest.java

/**
 * @param event /*from  w  ww  .  ja  v a 2  s .  co  m*/
 * @param cmdFile 
 * 
 */
private void runAction(FileSystemEventType event, File cmdFile) {
    // queue
    Queue<EventObject> queue = new LinkedList<EventObject>();
    queue.add(new FileSystemEvent(cmdFile, event));

    try {
        action.execute(queue);
    } catch (ActionException e) {
        fail(e.getLocalizedMessage());
    }
}

From source file:flexflux.analyses.randomConditions.RandomConditions.java

@Override
public RandomConditionsResult runAnalysis() {

    if (inputs == null) {
        return null;
    }/*w ww .jav a 2s.co m*/

    double startTime = System.currentTimeMillis();

    RandomConditionsResult result = new RandomConditionsResult(inputs);

    Queue<Integer> tasks = new LinkedBlockingQueue<Integer>();

    for (int i = 0; i < numberSimulations; i++) {
        tasks.add(i);
    }

    for (int i = 0; i < Vars.maxThread; i++) {

        ThreadRandomConditions thread = new ThreadRandomConditions(tasks, gaussianMean, gaussianStd, minInputs,
                maxInputs, inputRandomParameters, type, result);
        threads.add(thread);
    }

    if (Vars.verbose) {
        System.err.println("Progress : ");

        System.err.print("[");
        for (int i = 0; i < 50; i++) {
            System.err.print(" ");
        }
        System.err.print("]\n");
        System.err.print("[");
    }

    for (ThreadRandomConditions thread : threads) {
        thread.start();
    }

    for (ThreadRandomConditions thread : threads) {
        // permits to wait for the threads to end
        try {
            thread.join();
        } catch (InterruptedException e) {
            // e.printStackTrace();
        }
    }

    if (Vars.verbose) {
        System.err.print("]\n");
    }

    // we remove the threads to permit another analysis
    while (threads.size() > 0) {
        threads.remove(0);
    }

    if (Vars.verbose) {
        System.err.println("Random conditions over " + ((System.currentTimeMillis() - startTime) / 1000) + "s "
                + Vars.maxThread + " threads");
    }
    return result;
}

From source file:org.rhq.plugins.cassandra.itest.DiscoveryAndConfigurationTest.java

private Set<Resource> findResourcesForTest(Resource parent, Set<String> ignoredResourceTypes,
        Set<String> ignoredResourceNames) {
    Set<Resource> foundResources = new HashSet<Resource>();

    Queue<Resource> discoveryQueue = new LinkedList<Resource>();
    discoveryQueue.add(parent);

    while (!discoveryQueue.isEmpty()) {
        Resource currentResource = discoveryQueue.poll();

        if (ignoredResourceTypes.contains(currentResource.getResourceType().getName())
                || ignoredResourceNames.contains(currentResource.getName())) {
            continue;
        }//from   ww  w .j a  va  2s  . com

        log.info("Discovered resource of type: " + currentResource.getResourceType().getName());
        if (currentResource.getResourceType().getPlugin().equals(PLUGIN_NAME)) {
            foundResources.add(currentResource);
        }

        if (currentResource.getChildResources() != null) {
            for (Resource child : currentResource.getChildResources()) {
                discoveryQueue.add(child);
            }
        }
    }

    return foundResources;
}

From source file:org.kuali.kfs.module.purap.document.validation.impl.PurchasingAccountsPayableObjectCodeOverrideBranchingValidation.java

/**
 * Creates a Queue which represents a FIFO path of what properties to visit, based on the given property path
 * @param path the path to convert to a Queue
 * @return a Queue representing the path
 *//*from  w ww.ja  v  a  2  s  .  co m*/
protected Queue<String> convertPathToQueue(String path) {
    Queue<String> pathQueue = new LinkedList<String>();
    for (String property : path.split("\\.")) {
        pathQueue.add(property);
    }
    return pathQueue;
}

From source file:org.apache.hadoop.mapred.LinuxUtilizationGauger.java

/**
 * A function computes the Memory and CPU usage of all subprocess
 * @param pid            PID of the process we are interested in
 * @param pidToContent   Map between pid and the PS content
 * @param pidToChildPid  Map between pid and pid of its child process
 * @return A 2-element array which contants CPU and memory usage
 *///  w w  w. java2 s .co  m
private double[] getSubProcessUsage(String pid, Map<String, String[]> pidToContent,
        Map<String, LinkedList<String>> pidToChildPid) {
    double cpuMemUsage[] = new double[2];

    Queue<String> pidQueue = new LinkedList<String>();
    pidQueue.add(pid);
    while (!pidQueue.isEmpty()) {
        pid = pidQueue.poll();
        for (String child : pidToChildPid.get(pid)) {
            pidQueue.add(child);
        }
        String[] psContent = pidToContent.get(pid);
        double cpuUsage = Double.parseDouble(psContent[PCPU]);
        cpuUsage = percentageToGHz(cpuUsage);
        double memUsage = Double.parseDouble(psContent[RSS]);
        // "ps -eo rss" gives memory in kB. We convert it in GB
        memUsage /= 1000000d;
        cpuMemUsage[0] += cpuUsage;
        cpuMemUsage[1] += memUsage;
    }
    return cpuMemUsage;
}

From source file:org.aksw.simba.cetus.tools.ClassModelCreator.java

public static boolean inferSubClassRelations(Model classModel) {
    Set<Resource> subClasses = new HashSet<Resource>();
    ResIterator resIterator = classModel.listSubjectsWithProperty(RDFS.subClassOf);
    while (resIterator.hasNext()) {
        subClasses.add(resIterator.next());
    }/* w  w w  .  j a  v a  2  s . c o m*/
    LOGGER.info("Found " + subClasses.size() + " sub classes.");

    Queue<Resource> queue = new LinkedList<Resource>();
    int count = 0, count2 = 0;
    Resource resource, next;
    NodeIterator nodeIterator;
    Set<Resource> equalClasses = new HashSet<Resource>();
    Set<Resource> alreadySeen = new HashSet<Resource>();
    for (Resource subClass : subClasses) {
        equalClasses.clear();
        equalClasses.add(subClass);
        nodeIterator = classModel.listObjectsOfProperty(subClass, OWL.equivalentClass);
        while (nodeIterator.hasNext()) {
            equalClasses.add(nodeIterator.next().asResource());
        }
        resIterator = classModel.listSubjectsWithProperty(OWL.equivalentClass, subClass);
        while (resIterator.hasNext()) {
            equalClasses.add(resIterator.next());
        }
        for (Resource equalClass : equalClasses) {
            nodeIterator = classModel.listObjectsOfProperty(equalClass, RDFS.subClassOf);
            while (nodeIterator.hasNext()) {
                queue.add(nodeIterator.next().asResource());
            }
        }
        alreadySeen.clear();
        while (!queue.isEmpty()) {
            resource = queue.poll();
            // mark this resource as super class of the sub class
            classModel.add(subClass, RDFS.subClassOf, resource);
            ++count2;
            if (!classModel.contains(resource, RDF.type, RDFS.Class)) {
                classModel.add(resource, RDF.type, RDFS.Class);
            }

            nodeIterator = classModel.listObjectsOfProperty(resource, RDFS.subClassOf);
            while (nodeIterator.hasNext()) {
                next = nodeIterator.next().asResource();
                if (!alreadySeen.contains(next)) {
                    queue.add(next);
                    alreadySeen.add(next);
                }
            }
        }
        ++count;
        if ((count % 100000) == 0) {
            LOGGER.info("processed " + count + " sub classes.");
        }
    }
    LOGGER.info("Added " + count2 + " properties.");
    return true;
}

From source file:edu.emory.cci.aiw.cvrg.eureka.etl.ksb.PropositionDefinitionFinder.java

private void readParentsForSearchResult(PropositionDefinition pf, LinkedHashSet<String> nodesToLoad)
        throws PropositionFinderException {
    try {//from w ww .  ja v  a2  s  .c o m
        Queue<PropositionDefinition> toProcessQueue = new LinkedList<>();
        Stack<String> processedStack = new Stack<>();
        toProcessQueue.add(pf);
        while (!toProcessQueue.isEmpty()) {
            PropositionDefinition currentPropDef = toProcessQueue.remove();
            List<PropositionDefinition> parents;
            synchronized (parentsCache) {
                parents = parentsCache.get(currentPropDef.getId());
                if (parents == null) {
                    parents = knowledgeSource.readParents(currentPropDef);
                    parentsCache.put(currentPropDef.getId(), parents);
                }
            }
            for (PropositionDefinition parent : parents) {
                toProcessQueue.add(parent);
                processedStack.add(parent.getId());
            }
        }
        getNodesToLoad(processedStack, nodesToLoad);
    } catch (KnowledgeSourceReadException e) {
        throw new PropositionFinderException(e);
    }
}

From source file:org.wso2.carbon.dataservices.core.DBUtils.java

/**
 * This method is used to embed syntaxes associated with UDT attribute notations to
 * a queue of string tokens extracted from a UDT parameter.
 *
 * @param tokens      Queue of string tokens
 * @param syntaxQueue Syntax embedded tokens
 * @param isIndex     Flag to determine whether a particular string token is an inidex
 *                    or a column name/* w ww .ja v  a2s . c  o  m*/
 */
public static void getSyntaxEmbeddedQueue(Queue<String> tokens, Queue<String> syntaxQueue, boolean isIndex) {
    if (!tokens.isEmpty()) {
        if ("[".equals(tokens.peek())) {
            isIndex = true;
            tokens.poll();
            syntaxQueue.add("INEDX_START");
            syntaxQueue.add(tokens.poll());
        } else if ("]".equals(tokens.peek())) {
            isIndex = false;
            tokens.poll();
            syntaxQueue.add("INDEX_END");
        } else if (".".equals(tokens.peek())) {
            tokens.poll();
            syntaxQueue.add("DOT");
            syntaxQueue.add("COLUMN");
            syntaxQueue.add(tokens.poll());
        } else {
            if (isIndex) {
                syntaxQueue.add("INDEX");
                syntaxQueue.add(tokens.poll());
            } else {
                syntaxQueue.add("COLUMN");
                syntaxQueue.add(tokens.poll());
            }
        }
        getSyntaxEmbeddedQueue(tokens, syntaxQueue, isIndex);
    }
}