Example usage for java.util Queue poll

List of usage examples for java.util Queue poll

Introduction

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

Prototype

E poll();

Source Link

Document

Retrieves and removes the head of this queue, or returns null if this queue is empty.

Usage

From source file:org.kuali.rice.krad.uif.util.ComponentUtils.java

public static void updateChildIdsWithSuffixNested(Component component, String idSuffix) {
    @SuppressWarnings("unchecked")
    Queue<LifecycleElement> elementQueue = RecycleUtils.getInstance(LinkedList.class);
    try {/* w w  w.j  a  v a2 s  .com*/
        elementQueue.addAll(ViewLifecycleUtils.getElementsForLifecycle(component).values());

        while (!elementQueue.isEmpty()) {
            LifecycleElement currentElement = elementQueue.poll();
            if (currentElement == null) {
                continue;
            }

            if (currentElement instanceof Component) {
                updateIdWithSuffix((Component) currentElement, idSuffix);
                elementQueue.addAll(((Component) currentElement).getPropertyReplacerComponents());
            }

            elementQueue.addAll(ViewLifecycleUtils.getElementsForLifecycle(currentElement).values());
        }
    } finally {
        elementQueue.clear();
        RecycleUtils.recycle(elementQueue);
    }
}

From source file:org.ros.internal.message.new_style.ServiceLoader.java

private void findMessages(File searchPath) {
    CharsetDecoder decoder = Charset.forName("US-ASCII").newDecoder();
    FindServicesFilter filter = new FindServicesFilter();
    Queue<File> childPaths = Lists.newLinkedList();
    childPaths.addAll(listPathEntries(searchPath, filter));
    while (!childPaths.isEmpty()) {
        File servicePath = childPaths.poll();
        if (servicePath.isDirectory()) {
            childPaths.addAll(listPathEntries(servicePath, filter));
        } else {//from   w w  w  .j ava  2s  .c om
            try {
                addServiceDefinitionFromPaths(searchPath, servicePath, decoder);
            } catch (IOException e) {
                log.error("Failed to read service: " + servicePath.getAbsolutePath(), e);
            }
        }
    }
}

From source file:de.saxsys.synchronizefx.core.metamodel.executors.RepairingSingleValuePropertyCommandExecutor.java

@Override
public void execute(final SetPropertyValue command) {
    @SuppressWarnings("unchecked")
    final Property<Object> property = (Property<Object>) objectRegistry.getByIdOrFail(command.getPropertyId());
    final Queue<UUID> localCommands = propertyToChangeLog.get(property);

    if (!(localCommands == null || localCommands.isEmpty())) {
        if (localCommands.peek().equals(command.getCommandId())) {
            localCommands.poll();
        }//from  w  ww .jav  a2  s.c  o m
        return;
    }

    executor.execute(command);
}

From source file:org.ros.internal.message.new_style.MessageLoader.java

private void findMessages(File searchPath) {
    CharsetDecoder decoder = Charset.forName("US-ASCII").newDecoder();
    FindMessagesFilter filter = new FindMessagesFilter();
    Queue<File> childPaths = Lists.newLinkedList();
    childPaths.addAll(listPathEntries(searchPath, filter));
    while (!childPaths.isEmpty()) {
        File messagePath = childPaths.poll();
        if (messagePath.isDirectory()) {
            childPaths.addAll(listPathEntries(messagePath, filter));
        } else {/*from   w  ww . ja  v a 2  s .c  om*/
            try {
                addMessageDefinitionFromPaths(searchPath, messagePath, decoder);
            } catch (IOException e) {
                log.error("Failed to read message: " + messagePath.getAbsolutePath(), e);
            }
        }
    }
}

From source file:eu.stratosphere.nephele.streaming.taskmanager.runtime.chaining.StreamChain.java

@SuppressWarnings({ "rawtypes", "unchecked" })
void executeMapper(final Record record, final int chainIndex) throws Exception {

    final StreamChainLink chainLink = this.chainLinks.get(chainIndex);
    final Mapper mapper = chainLink.getMapper();

    chainLink.getInputGate().reportRecordReceived(record, 0);
    mapper.map(record);/*from   w ww.  j av a  2  s  .co  m*/

    final StreamOutputGate outputGate = chainLink.getOutputGate();

    final Queue outputCollector = mapper.getOutputCollector();

    if (chainIndex == this.chainLinks.size() - 1) {

        while (!outputCollector.isEmpty()) {
            outputGate.writeRecord((Record) outputCollector.poll());
        }

    } else {

        while (!outputCollector.isEmpty()) {
            final Record outputRecord = (Record) outputCollector.poll();
            outputGate.reportRecordEmitted(outputRecord);
            this.executeMapper(RecordUtils.createCopy(outputRecord), chainIndex + 1);
        }
    }
}

From source file:org.jboss.qa.phaser.Executor.java

public void execute() throws Exception {
    final List<ErrorReport> throwAtEnd = new LinkedList<>();
    invokeJobMethods(BeforeJob.class);

    final Queue<ExecutionNode> nodeQueue = new LinkedList<>(roots);
    boolean finalizeState = false;
    while (!nodeQueue.isEmpty()) {
        final ExecutionNode node = nodeQueue.poll();

        final ExecutionError err = node.execute(finalizeState);

        if (err != null) {
            final ExceptionHandling eh = err.getExceptionHandling();
            final ErrorReport errorReport = new ErrorReport("Exception thrown by phase execution:",
                    err.getThrowable());
            switch (eh.getReport()) {
            case THROW_AT_END:
                throwAtEnd.add(errorReport);
                break;
            case LOG:
                ErrorReporter.report(errorReport);
                break;
            default:
                log.debug("Exception by phase execution, continue.");
            }//from   www  .  j  a  v  a  2 s  . c om

            if (eh.getExecution() == ExceptionHandling.Execution.IMMEDIATELY_STOP) {
                break;
            } else if (eh.getExecution() == ExceptionHandling.Execution.FINALIZE) {
                finalizeState = true;
            }
        }
        nodeQueue.addAll(node.getChildNodes());
    }

    invokeJobMethods(AfterJob.class);
    ErrorReporter.finalErrorReport(throwAtEnd);
}

From source file:org.opennms.features.vaadin.topology.jung.BalloonLayoutAlgorithm.java

public void updateLayout(GraphContainer graph) {

    Graph g = new Graph(graph);

    int szl = g.getSemanticZoomLevel();

    Vertex rootItem = g.getDisplayVertex(g.getVertexByItemId(m_rootItemId), szl);

    Tree<Vertex, Edge> tree = new OrderedKAryTree<Vertex, Edge>(50);

    Queue<Vertex> q = new LinkedList<Vertex>();
    Set<Vertex> found = new HashSet<Vertex>();

    q.add(rootItem);//from   w  w  w  . j  a va  2  s  .c o  m

    tree.addVertex(rootItem);

    Vertex v;
    while ((v = q.poll()) != null) {
        List<Edge> edges = g.getEdgesForVertex(v, szl);
        for (Edge e : edges) {
            Vertex neighbor = e.getSource() != v ? e.getSource() : e.getTarget();
            tree.addEdge(e, v, neighbor);
            if (!found.contains(neighbor)) {
                q.add(neighbor);
            }
        }
    }

    BalloonLayout<Vertex, Edge> layout = new BalloonLayout<Vertex, Edge>(tree);
    layout.setInitializer(new Transformer<Vertex, Point2D>() {
        public Point2D transform(Vertex v) {
            return new Point(v.getX(), v.getY());
        }
    });

    for (Vertex vertex : g.getVertices(szl)) {
        layout.lock(vertex, vertex.isLocked());
    }

    layout.setSize(new Dimension(750, 750));

    List<Vertex> vertices = g.getVertices(szl);
    for (Vertex vertex : vertices) {
        Point2D point = layout.transform(v);
        vertex.setX((int) point.getX());
        vertex.setY((int) point.getY());
    }

}

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

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

    try {/* w w  w .j  a  v  a  2 s .  co m*/
        listOfGeoTags = SbicktAPI.getGeoTags(new Point3D(2.548, 2.548, 0));

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

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);//  w  w w  .ja  v a 2 s .c  o  m
    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:org.siddhiesb.transport.passthru.DeliveryAgent.java

public void errorConnecting(HttpRoute route, int errorCode, String message) {
    Queue<CommonContext> queue = waitingMessages.get(route);
    if (queue != null) {
        CommonContext msgCtx = queue.poll();
    } else {// ww w  .ja v  a2  s.c om
        throw new IllegalStateException("Queue cannot be null for: " + route);
    }
}