Example usage for java.util Queue isEmpty

List of usage examples for java.util Queue isEmpty

Introduction

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

Prototype

boolean isEmpty();

Source Link

Document

Returns true if this collection contains no elements.

Usage

From source file:org.apache.streams.local.tasks.BaseStreamsTask.java

@Override
public boolean isWaiting() {
    if (this.inQueues == null || this.inQueues.size() == 0) {
        return true;
    }//w ww.  j a v  a  2s.com
    boolean empty = true;
    for (Queue queue : this.inQueues) {
        empty = empty && queue.isEmpty();
    }
    return empty;
}

From source file:net.cellcloud.talk.HttpDialogueHandler.java

@Override
protected void doPost(HttpRequest request, HttpResponse response) throws IOException {
    HttpSession session = request.getSession();
    if (null != session) {
        try {// www.  ja  v a 2s .c om
            // ??
            JSONObject json = new JSONObject(new String(request.readRequestData(), Charset.forName("UTF-8")));
            // ? JSON ?
            String speakerTag = json.getString(Tag);
            String celletIdentifier = json.getString(Identifier);
            JSONObject primitiveJSON = json.getJSONObject(Primitive);
            // ?
            Primitive primitive = new Primitive(speakerTag);
            PrimitiveSerializer.read(primitive, primitiveJSON);
            // ?
            this.talkService.processDialogue(session, speakerTag, celletIdentifier, primitive);

            // ?
            // FIXME 2014/10/03 ??
            JSONObject responseData = new JSONObject();

            // ??
            Queue<Message> queue = session.getQueue();
            if (!queue.isEmpty()) {
                ArrayList<String> identifiers = new ArrayList<String>(queue.size());
                ArrayList<Primitive> primitives = new ArrayList<Primitive>(queue.size());
                for (int i = 0, size = queue.size(); i < size; ++i) {
                    // ?
                    Message message = queue.poll();
                    // 
                    Packet packet = Packet.unpack(message.get());
                    if (null != packet) {
                        // ? cellet identifier
                        byte[] identifier = packet.getSubsegment(1);

                        // ?????
                        byte[] primData = packet.getSubsegment(0);
                        ByteArrayInputStream stream = new ByteArrayInputStream(primData);

                        // ???
                        Primitive prim = new Primitive(Nucleus.getInstance().getTagAsString());
                        prim.read(stream);

                        // 
                        identifiers.add(Utils.bytes2String(identifier));
                        primitives.add(prim);
                    }
                }

                // ?
                JSONArray jsonPrimitives = this.convert(identifiers, primitives);
                responseData.put(Primitives, jsonPrimitives);
            }

            // ?
            responseData.put(Queue, queue.size());

            // ?
            this.respondWithOk(response, responseData);
        } catch (JSONException e) {
            Logger.log(HttpDialogueHandler.class, e, LogLevel.ERROR);
            this.respond(response, HttpResponse.SC_BAD_REQUEST);
        }
    } else {
        this.respond(response, HttpResponse.SC_UNAUTHORIZED);
    }
}

From source file:org.silverpeas.tools.file.regexpr.RegExprMatcher.java

private void analyse(File startFile) throws Exception {
    Queue<File> fileQueue = new ArrayDeque<>(100000);
    fileQueue.add(startFile);/*from w  ww.j  av  a 2  s. com*/
    while (!fileQueue.isEmpty()) {
        File file = fileQueue.poll();
        if (file.isFile()) {
            if (config.getFileFilter().accept(file)) {
                boolean fileMatched = false;
                for (PatternConfig patternConfig : config.getPatternConfigs()) {
                    boolean found = patternConfig.pattern.matcher(FileUtils.readFileToString(file)).find();
                    fileMatched = (found && patternConfig.mustMatch) || (!found && !patternConfig.mustMatch);
                    if (!fileMatched) {
                        break;
                    }
                }
                if (fileMatched) {
                    System.out.println(file.getPath());
                    nbMatchedFiles++;
                }
                nbAnalysedFiles++;
            }
        } else if (file.isDirectory() && config.getDirFilter().accept(file)) {
            for (File subFile : file.listFiles()) {
                fileQueue.add(subFile);
            }
        } else {
            int i = 0;
        }
    }
}

From source file:ubic.gemma.job.progress.ProgressStatusServiceImpl.java

@Override
public synchronized List<ProgressData> getProgressStatus(String taskId) {
    if (taskId == null)
        throw new IllegalArgumentException("task id cannot be null");
    SubmittedTask task = taskRunningService.getSubmittedTask(taskId);

    List<ProgressData> statusObjects = new Vector<ProgressData>();

    if (task == null) {
        log.warn("It looks like job " + taskId + " has gone missing; assuming it is dead or finished already");

        // We should assume it is dead.
        ProgressData data = new ProgressData();
        data.setTaskId(taskId);//from   ww  w.j  av  a  2  s .  c om
        data.setDone(true);
        data.setDescription("The job has gone missing; it has already finished or failed.");
        statusObjects.add(data);

        return statusObjects;
    }

    assert task.getTaskId() != null;
    assert task.getTaskId().equals(taskId);

    Queue<String> updates = task.getProgressUpdates();
    String progressMessage = "";
    while (!updates.isEmpty()) {
        String update = updates.poll();
        progressMessage += update + "\n";
    }

    if (task.isDone()) {
        ProgressData data;
        if (task.getStatus() == SubmittedTask.Status.COMPLETED) {
            log.debug("Job " + taskId + " is done");
            data = new ProgressData(taskId, 1, progressMessage + "Done!", true);
        } else if (task.getStatus() == SubmittedTask.Status.FAILED) {
            data = new ProgressData(taskId, 1, progressMessage + "Failed!", true);
            data.setFailed(true);
        } else {
            data = new ProgressData(taskId, 1, progressMessage + "Possibly canceled.", true);
        }
        statusObjects.add(data);
    } else {
        statusObjects.add(new ProgressData(taskId, 1, progressMessage, false));
    }

    return statusObjects;
}

From source file:asia.stampy.server.listener.subscription.AbstractAcknowledgementListenerAndInterceptor.java

private boolean hasMessageAck(String messageId, HostPort hostPort) {
    Queue<String> ids = messages.get(hostPort);
    if (ids == null || ids.isEmpty())
        return false;

    return ids.contains(messageId);
}

From source file:fungus.MycoGraph.java

public Set<Set<MycoNode>> findConnectedComponents() {
    Set<Set<MycoNode>> components = new HashSet<Set<MycoNode>>();
    Set<MycoNode> unseen = new HashSet<MycoNode>(this.getVertices());
    Queue<MycoNode> queue = new LinkedList<MycoNode>();

    Set<MycoNode> workingComponent = null;
    MycoNode current;/*from w  w  w . j av a 2 s  . c  o m*/
    while ((!unseen.isEmpty()) || (!queue.isEmpty())) {
        if (queue.isEmpty()) {
            // Queue an arbitary unvisited node
            MycoNode n = unseen.iterator().next();
            queue.offer(n);
            unseen.remove(n);
            // Start new component
            workingComponent = new HashSet<MycoNode>();
            components.add(workingComponent);
        }
        current = queue.remove();
        workingComponent.add(current);
        for (MycoNode neighbor : current.getHyphaLink().getNeighbors()) {
            if (unseen.contains(neighbor)) {
                queue.offer(neighbor);
                unseen.remove(neighbor);
            }
        }
    }
    return components;
}

From source file:org.phenotips.solr.HPOScriptService.java

/**
 * Get the HPO IDs of the specified phenotype and all its ancestors.
 *
 * @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
 *///w w  w.j  av a2 s.c o  m
@SuppressWarnings("unchecked")
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)));
        Object rawParents = crt.get("is_a");
        if (rawParents == null) {
            continue;
        }
        List<String> parents;
        if (rawParents instanceof String) {
            parents = Collections.singletonList(String.valueOf(rawParents));
        } else {
            parents = (List<String>) rawParents;
        }
        for (String pid : parents) {
            nodes.add(this.get(StringUtils.substringBefore(pid, " ")));
        }
    }
    return results;
}

From source file:geotag.example.sbickt.SbicktAPITest.java

@Test
public void testGetGeoTags() {
    Queue<GeoTag> listOfGeoTags = new LinkedList<GeoTag>();

    try {/*from w  w w.j  av a2  s .  c om*/
        listOfGeoTags = SbicktAPI.getGeoTags(new Point3D(2.548, 2.548, 0));

        assertNotNull(listOfGeoTags);

        while (!listOfGeoTags.isEmpty()) {
            listOfGeoTags.poll().prettyPrint();
        }
    } catch (Exception e) {
        fail(e.toString());
    }
}

From source file:ubic.gemma.core.job.progress.ProgressStatusServiceImpl.java

@Override
public synchronized List<ProgressData> getProgressStatus(String taskId) {
    if (taskId == null)
        throw new IllegalArgumentException("task id cannot be null");
    SubmittedTask<?> task = taskRunningService.getSubmittedTask(taskId);

    List<ProgressData> statusObjects = new Vector<>();

    if (task == null) {
        ProgressStatusServiceImpl.log.warn(
                "It looks like job " + taskId + " has gone missing; assuming it is dead or finished already");

        // We should assume it is dead.
        ProgressData data = new ProgressData();
        data.setTaskId(taskId);/* w w  w  .  jav a  2 s  . co  m*/
        data.setDone(true);
        data.setDescription("The job has gone missing; it has already finished or failed.");
        statusObjects.add(data);

        return statusObjects;
    }

    assert task.getTaskId() != null;
    assert task.getTaskId().equals(taskId);

    Queue<String> updates = task.getProgressUpdates();
    StringBuilder progressMessage = new StringBuilder();
    while (!updates.isEmpty()) {
        String update = updates.poll();
        progressMessage.append(update).append("\n");
    }

    if (task.isDone()) {
        ProgressData data;
        switch (task.getStatus()) {
        case COMPLETED:
            ProgressStatusServiceImpl.log.debug("Job " + taskId + " is done");
            data = new ProgressData(taskId, 1, progressMessage + "Done!", true);
            break;
        case FAILED:
            data = new ProgressData(taskId, 1, progressMessage + "Failed!", true);
            data.setFailed(true);
            break;
        default:
            data = new ProgressData(taskId, 1, progressMessage + "Possibly canceled.", true);
            break;
        }
        statusObjects.add(data);
    } else {
        statusObjects.add(new ProgressData(taskId, 1, progressMessage.toString(), false));
    }

    return statusObjects;
}

From source file:DecorateMutationsSNP.java

/**
 * This function returns the set of leaves in the ARG that are reachable from a node give in input 
 * @param root integer value representing the ID of the node in the arg
 * @param arg  object of the class PopulationARG
 * @see PopulationARG//from w  ww . jav a 2 s . com
 * @see Node
 * @return the set of integer values representing the leaves in the ARG that are reachable from a node give in input (root)
 */
public static TreeSet<Integer> computeLeaves(int root, PopulationARG arg) {

    TreeSet<Integer> leaves = new TreeSet<Integer>();
    Queue<Integer> q = new LinkedList<Integer>();
    boolean visited[] = new boolean[arg.getNodeSet().size()];
    /*System.out.println("ID Population = "+arg.getId_pop());
    System.out.println("Population Kind = "+arg.getKind());
    System.out.println("Extant units = "+arg.getExtantUnits());
    System.out.println("Node set size = "+arg.getNodeSet().size());*/

    for (int i = 0; i < visited.length; i++) {
        visited[i] = false;
    }

    //System.out.println("Root = "+root);
    //If root is a leaf I have to add just that leaf in leaves, no reason to do the visit
    if (root >= 0 && root < arg.getExtantUnits()) {
        leaves.add(new Integer(root));
    }
    //Else bfv to search for all the leaves of the subtree with root root
    else {
        visited[root] = true;
        q.add(new Integer(root));

        while (!q.isEmpty()) {
            // remove a labeled vertex from the queue
            int w = ((Integer) q.remove()).intValue();

            // mark unreached vertices adjacent from w
            Iterator<Integer> it_edges = arg.getGraphEdges().keySet().iterator();
            while (it_edges.hasNext()) {
                Integer keyE = it_edges.next();
                Edge e = arg.getGraphEdges().get(keyE);
                //if I have found an edge with w has father
                if (e.getId_fath() == w) {
                    int u = e.getId_son();
                    //System.out.println("Visiting edge "+w+"-"+u);
                    if (!visited[u]) {
                        q.add(new Integer(u));
                        visited[u] = true;
                        //System.out.println("Visiting node :"+u);
                        if (u >= 0 && u < arg.getExtantUnits()) {
                            //System.out.println("u is a leaf :"+u);

                            //u is a leaf node 
                            leaves.add(u);
                        }
                    }
                } //end if w is a father of the edge
            } //for all edge..select the one that has w has father and take u as son
        } //end while  
    } // end else root is not a leaf
    return leaves;
}