List of usage examples for java.util Queue poll
E poll();
From source file:com.streamsets.pipeline.lib.util.ProtobufTypeUtil.java
private static List<DescriptorProtos.DescriptorProto> getAllMessageTypesInDescriptorProto( DescriptorProtos.FileDescriptorProto fileDescriptorProto) { Queue<DescriptorProtos.DescriptorProto> queue = new LinkedList<>(); queue.addAll(fileDescriptorProto.getMessageTypeList()); List<DescriptorProtos.DescriptorProto> result = new ArrayList<>(); while (!queue.isEmpty()) { DescriptorProtos.DescriptorProto descriptorProto = queue.poll(); queue.addAll(descriptorProto.getNestedTypeList()); result.add(descriptorProto);//from w w w . j ava 2 s . c om } return result; }
From source file:org.apache.lens.cube.parse.HQLParser.java
/** * Breadth first traversal of AST/* w w w .j av a 2s.co m*/ * * @param root node from where to start bft * @param visitor action to take on each visit * @throws LensException */ public static void bft(ASTNode root, ASTNodeVisitor visitor) throws LensException { if (root == null) { throw new NullPointerException("Root cannot be null"); } if (visitor == null) { throw new NullPointerException("Visitor cannot be null"); } Queue<TreeNode> queue = new LinkedList<>(); queue.add(new TreeNode(null, root)); while (!queue.isEmpty()) { TreeNode node = queue.poll(); visitor.visit(node); ASTNode astNode = node.getNode(); for (int i = 0; i < astNode.getChildCount(); i++) { queue.offer(new TreeNode(node, (ASTNode) astNode.getChild(i))); } } }
From source file:org.apache.gobblin.http.ApacheHttpRequestBuilder.java
@Override public ApacheHttpRequest<GenericRecord> buildRequest(Queue<BufferedRecord<GenericRecord>> buffer) { return buildWriteRequest(buffer.poll()); }
From source file:org.kuali.rice.krad.uif.util.ComponentUtils.java
/** * places a key, value pair in each context map of a list of components * * @param elements the list of elements/*w w w. j a v a 2 s . c om*/ * @param contextName a value to be used as a key to retrieve the object * @param contextValue the value to be placed in the context */ public static void pushObjectToContext(Collection<? extends LifecycleElement> elements, String contextName, Object contextValue) { if (elements == null || elements.isEmpty()) { return; } Queue<LifecycleElement> elementQueue = new LinkedList<LifecycleElement>(); try { elementQueue.addAll(elements); while (!elementQueue.isEmpty()) { LifecycleElement currentElement = elementQueue.poll(); if (currentElement == null) { continue; } if (currentElement instanceof Component) { ((Component) currentElement).pushObjectToContext(contextName, contextValue); } elementQueue.addAll(ViewLifecycleUtils.getElementsForLifecycle(currentElement).values()); } } finally { elementQueue.clear(); RecycleUtils.recycle(elementQueue); } }
From source file:io.netty.handler.codec.compression.JdkZlibTest.java
@Test // verifies backward compatibility public void testConcatenatedStreamsReadFirstOnly() throws IOException { EmbeddedChannel chDecoderGZip = new EmbeddedChannel(createDecoder(ZlibWrapper.GZIP)); try {/* w w w. jav a 2 s . c om*/ byte[] bytes = IOUtils.toByteArray(getClass().getResourceAsStream("/multiple.gz")); assertTrue(chDecoderGZip.writeInbound(Unpooled.copiedBuffer(bytes))); Queue<Object> messages = chDecoderGZip.inboundMessages(); assertEquals(1, messages.size()); ByteBuf msg = (ByteBuf) messages.poll(); assertEquals("a", msg.toString(CharsetUtil.UTF_8)); ReferenceCountUtil.release(msg); } finally { assertFalse(chDecoderGZip.finish()); chDecoderGZip.close(); } }
From source file:org.kuali.rice.krad.uif.util.ComponentUtils.java
/** * Replace all IDs from a component and its children with new generated ID values. * * <p>If there are features that depend on a static id of this * component, this call may cause errors.</p> * * @param components A list of component to clear all IDs from. * @see AssignIdsTask For a complete description of the algorithm. *//* w w w . j a va2 s . co m*/ public static void clearAndAssignIds(List<? extends Component> components) { if (components == null || components.isEmpty()) { return; } int hash = 1; @SuppressWarnings("unchecked") Queue<LifecycleElement> toClear = RecycleUtils.getInstance(LinkedList.class); toClear.addAll(components); try { while (!toClear.isEmpty()) { LifecycleElement element = toClear.poll(); hash = generateId(element, hash); for (LifecycleElement nested : ViewLifecycleUtils.getElementsForLifecycle(element).values()) { if (nested != null) { toClear.add(nested); } } if (element instanceof Component) { List<Component> propertyReplacerComponents = ((Component) element) .getPropertyReplacerComponents(); if (propertyReplacerComponents == null) { continue; } for (Component nested : propertyReplacerComponents) { if (nested != null) { toClear.add(nested); } } } } } finally { toClear.clear(); RecycleUtils.recycle(toClear); } }
From source file:org.kuali.rice.krad.uif.util.ComponentUtils.java
public static void prefixBindingPathNested(Component component, String addBindingPrefix) { @SuppressWarnings("unchecked") Queue<LifecycleElement> elementQueue = RecycleUtils.getInstance(LinkedList.class); elementQueue.offer(component);/*from w ww. j av a 2 s . co m*/ try { while (!elementQueue.isEmpty()) { LifecycleElement currentElement = elementQueue.poll(); if (currentElement == null) { continue; } if (currentElement instanceof DataBinding) { if (LOG.isDebugEnabled()) { LOG.info("setting nested binding prefix '" + addBindingPrefix + "' on " + currentElement); } prefixBindingPath((DataBinding) currentElement, addBindingPrefix); } elementQueue.addAll(ViewLifecycleUtils.getElementsForLifecycle(currentElement).values()); } } finally { elementQueue.clear(); RecycleUtils.recycle(elementQueue); } }
From source file:com.github.rvesse.airline.model.MetadataLoader.java
/** * Loads global meta-data//w w w. ja v a2 s . c o m * * @param name * CLI name * @param description * CLI description * @param defaultCommand * Default Command * @param defaultGroupCommands * Default Group Commands * @param groups * Command Groups * @param parserConfig * Parser Configuration * @param restrictions * Restrictions * @return Global meta-data */ public static <C> GlobalMetadata<C> loadGlobal(String name, String description, CommandMetadata defaultCommand, Iterable<CommandMetadata> defaultGroupCommands, Iterable<CommandGroupMetadata> groups, Iterable<GlobalRestriction> restrictions, ParserMetadata<C> parserConfig) { List<OptionMetadata> globalOptions = new ArrayList<>(); if (defaultCommand != null) { globalOptions.addAll(defaultCommand.getGlobalOptions()); } for (CommandMetadata command : defaultGroupCommands) { globalOptions.addAll(command.getGlobalOptions()); } for (CommandGroupMetadata group : groups) { for (CommandMetadata command : group.getCommands()) { globalOptions.addAll(command.getGlobalOptions()); } // Remember to also search sub-groups for global options Queue<CommandGroupMetadata> subGroups = new LinkedList<CommandGroupMetadata>(); subGroups.addAll(group.getSubGroups()); while (subGroups.size() > 0) { CommandGroupMetadata subGroup = subGroups.poll(); for (CommandMetadata command : subGroup.getCommands()) { globalOptions.addAll(command.getGlobalOptions()); } subGroups.addAll(subGroup.getSubGroups()); } } globalOptions = ListUtils.unmodifiableList(mergeOptionSet(globalOptions)); return new GlobalMetadata<C>(name, description, globalOptions, defaultCommand, defaultGroupCommands, groups, restrictions, parserConfig); }
From source file:com.core.controller.AlgoritmoController.java
public static Solucion busquedaAmplitud(Grafo g, String nodoInicioNombre, String nodoFinNombre) { //funcionna bien Solucion result = new Solucion(); result.setPasos("Algoritmo de Busqueda Primero en Amplitud"); result.agregarPaso("Cantidad de nodos: " + g.getNodos().size()); result.agregarPaso("Cantidad de aristas: " + g.getAristas().size()); Queue<String> cola = new LinkedList<>(); Queue<String> padresCola = new LinkedList<>(); List<String> explorados = new ArrayList<>(); //LISTA-NODOS List<String> padresExplorados = new ArrayList<>(); String nodoActual, nodoPadre; cola.add(nodoInicioNombre);/* ww w. ja v a2s .co m*/ padresCola.add("#"); while (true) { System.out.println(cola); if (cola.isEmpty()) { result.agregarPaso("No se encontro el nodo destino"); break; } nodoActual = cola.poll(); nodoPadre = padresCola.poll(); explorados.add(nodoActual); padresExplorados.add(nodoPadre); if (nodoActual.equals(nodoFinNombre)) { result.agregarPaso("Nodo fin alcanzado"); //Mostrar camino String nodo = nodoActual; String secuenciaResultado = ""; while (nodo != "#") { secuenciaResultado = nodo + " " + secuenciaResultado; nodo = padresExplorados.get(explorados.indexOf(nodo)); } result.agregarPaso("Camino solucion: " + secuenciaResultado); break; } List<String> vecinos = g.nodosVecinos(nodoActual); Iterator<String> i = vecinos.iterator(); while (i.hasNext()) { String a = i.next(); if (!explorados.contains(a) && !cola.contains(a)) { cola.add(a); padresCola.add(nodoActual); } } } //Verifico la solucion y la guardo en Solucion if (result.getPasos().contains("Nodo fin alcanzado")) { String solucion = result.getPasos().split("Nodo fin alcanzado\n")[1]; String[] array = solucion.split(" "); // ArrayUtils.reverse(array); for (String nombreNodo : array) { System.out.println("--------------------------------------"); for (Map.Entry<String, Nodo> n : g.getNodos().entrySet()) { System.out.println("Comparando " + n.getKey() + " con " + nombreNodo); if (n.getKey().equals(nombreNodo)) { System.out.println("Son iguales! Agregando " + nombreNodo + " a la lista"); result.getNodos().add(n.getValue()); } } } System.out.println( "Nodos del resultado final en la lista: " + Arrays.toString(result.getNodos().toArray())); } return result; }
From source file:org.kuali.rice.krad.uif.util.ComponentUtils.java
/** * places a all entries from a map into each context map of a list of components * * @param components The list components. * @param sourceContext The source context map. *///from w w w . j av a 2 s. co m public static void pushAllToContext(List<? extends Component> components, Map<String, Object> sourceContext) { if (components == null || components.isEmpty()) { return; } @SuppressWarnings("unchecked") Queue<LifecycleElement> elementQueue = RecycleUtils.getInstance(LinkedList.class); try { elementQueue.addAll(components); while (!elementQueue.isEmpty()) { LifecycleElement currentElement = elementQueue.poll(); if (currentElement == null) { continue; } if (currentElement instanceof Component) { ((Component) currentElement).pushAllToContext(sourceContext); } elementQueue.addAll(ViewLifecycleUtils.getElementsForLifecycle(currentElement).values()); } } finally { elementQueue.clear(); RecycleUtils.recycle(elementQueue); } }