List of usage examples for java.util ArrayDeque ArrayDeque
public ArrayDeque()
From source file:de.escalon.hypermedia.spring.hydra.PagedResourcesSerializer.java
@Override public void serialize(PagedResources pagedResources, JsonGenerator jgen, SerializerProvider serializerProvider) throws IOException { final SerializationConfig config = serializerProvider.getConfig(); JavaType javaType = config.constructType(pagedResources.getClass()); JsonSerializer<Object> serializer = BeanSerializerFactory.instance.createSerializer(serializerProvider, javaType);//from w w w . j av a2 s. c o m // replicate pretty much everything from JacksonHydraSerializer // since we must reorganize the internals of pagedResources to get a hydra collection // with partial page view, we have to serialize pagedResources with an // unwrapping serializer Deque<LdContext> contextStack = (Deque<LdContext>) serializerProvider.getAttribute(KEY_LD_CONTEXT); if (contextStack == null) { contextStack = new ArrayDeque<LdContext>(); serializerProvider.setAttribute(KEY_LD_CONTEXT, contextStack); } // TODO: filter next/previous/first/last from link list - maybe create new PagedResources without them? List<Link> links = pagedResources.getLinks(); List<Link> filteredLinks = new ArrayList<Link>(); for (Link link : links) { String rel = link.getRel(); if (navigationRels.contains(rel)) { continue; } else { filteredLinks.add(link); } } PagedResources toRender = new PagedResources(pagedResources.getContent(), pagedResources.getMetadata(), filteredLinks); jgen.writeStartObject(); serializeContext(toRender, jgen, serializerProvider, contextStack); jgen.writeStringField(JsonLdKeywords.AT_TYPE, "hydra:Collection"); // serialize with PagedResourcesMixin serializer.unwrappingSerializer(NameTransformer.NOP).serialize(toRender, jgen, serializerProvider); PagedResources.PageMetadata metadata = pagedResources.getMetadata(); jgen.writeNumberField("hydra:totalItems", metadata.getTotalElements()); // begin hydra:view jgen.writeObjectFieldStart("hydra:view"); jgen.writeStringField(JsonLdKeywords.AT_TYPE, "hydra:PartialCollectionView"); writeRelLink(pagedResources, jgen, Link.REL_NEXT); writeRelLink(pagedResources, jgen, "previous"); // must also translate prev to its synonym previous writeRelLink(pagedResources, jgen, Link.REL_PREVIOUS, "previous"); writeRelLink(pagedResources, jgen, Link.REL_FIRST); writeRelLink(pagedResources, jgen, Link.REL_LAST); jgen.writeEndObject(); // end hydra:view jgen.writeEndObject(); contextStack = (Deque<LdContext>) serializerProvider.getAttribute(KEY_LD_CONTEXT); if (!contextStack.isEmpty()) { contextStack.pop(); } }
From source file:name.abhijitsarkar.algorithms.core.Sorter.java
public static int[] bucketSort(int[] arr) { int[][] buckets = scatter(arr); ArrayDeque<int[]> stack = new ArrayDeque<int[]>(); for (int[] bucket : buckets) { if (bucket != null) { stack.add(mergeSort(bucket)); }//ww w.j a va 2s . c o m } return gather(stack); }
From source file:bachelorthesis.captchabuilder.builder.CaptchaBuilder.java
/** * Constructor//w w w.j a v a2s. co m * * @param width the width of the captcha to be created * @param height the width of the captcha to be created * @param buildSequence string arguments to create the captcha * <p/> * @throws ParseException */ public CaptchaBuilder(int width, int height, String buildSequence) throws ParseException { this.builders = new ArrayDeque<>(); this.setBuildSequence(buildSequence); img = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB); answer = ""; }
From source file:org.apache.hadoop.hive.ql.parse.ASTNode.java
/** * For every node in this subtree, make sure it's start/stop token's * are set. Walk depth first, visit bottom up. Only updates nodes * with at least one token index < 0. * * In contrast to the method in the parent class, this method is * iterative.// w w w. j a v a2 s .co m */ @Override public void setUnknownTokenBoundaries() { Deque<ASTNode> stack1 = new ArrayDeque<ASTNode>(); Deque<ASTNode> stack2 = new ArrayDeque<ASTNode>(); stack1.push(this); while (!stack1.isEmpty()) { ASTNode next = stack1.pop(); stack2.push(next); if (next.children != null) { for (int i = next.children.size() - 1; i >= 0; i--) { stack1.push((ASTNode) next.children.get(i)); } } } while (!stack2.isEmpty()) { ASTNode next = stack2.pop(); if (next.children == null) { if (next.startIndex < 0 || next.stopIndex < 0) { next.startIndex = next.stopIndex = next.token.getTokenIndex(); } } else if (next.startIndex >= 0 && next.stopIndex >= 0) { continue; } else if (next.children.size() > 0) { ASTNode firstChild = (ASTNode) next.children.get(0); ASTNode lastChild = (ASTNode) next.children.get(next.children.size() - 1); next.startIndex = firstChild.getTokenStartIndex(); next.stopIndex = lastChild.getTokenStopIndex(); } } }
From source file:com.core.controller.AlgoritmoController.java
public static String busquedaProfundidad(Grafo g, String inicio, String fin) { Deque<String> pila = new ArrayDeque<>(); Deque<String> padresPila = new ArrayDeque<>(); List<String> explorados = new ArrayList<>(); List<String> padresExplorados = new ArrayList<>(); String nodoActual, nodoPadre; String result = "Algoritmo de Busqueda Primero en Profundidad"; result += "\nCantidad de nodos: " + g.getNodos().size(); result += "\nCantidad de aristas: " + g.getAristas().size(); pila.push(inicio);/*from w w w. ja v a2s.co m*/ padresPila.push("#"); while (true) { result += "\nPila: " + Arrays.toString(pila.toArray()); if (pila.isEmpty()) { result += "\nNo se encontro el nodo destino"; break; } nodoActual = pila.pop(); nodoPadre = padresPila.pop(); explorados.add(nodoActual); padresExplorados.add(nodoPadre); if (nodoActual.equals(fin)) { result += "\nNodo destino alcanzado"; //Mostrar camino String nodo = nodoActual; String secuenciaResultado = ""; while (nodo != "#") { secuenciaResultado = nodo + " " + secuenciaResultado; nodo = padresExplorados.get(explorados.indexOf(nodo)); } result += "\nCamino solucion: " + secuenciaResultado; break; } List<String> vecinos = g.nodosVecinos(nodoActual); for (int i = vecinos.size() - 1; i >= 0; i--) { String a = vecinos.get(i); if (!explorados.contains(a)) { if (pila.contains(a)) { pila.remove(a); padresPila.remove(nodoActual); } pila.push(a); padresPila.push(nodoActual); } } } return result; }
From source file:org.synku4j.wbxml.marshal.impl.DefaultWbxmlMarshaller.java
@Override public <T> T unmarshal(WbxmlContext cntx, InputStream is, Class<T> targetClass, String... filter) throws IOException, WbxmlMarshallerException { T target;//from ww w .j ava2 s . c o m try { target = targetClass.newInstance(); } catch (Exception e) { if (log.isWarnEnabled()) { log.warn("Unable to create an instance of the target class", e); } throw new WbxmlMarshallerException("Exception raised creating new instance of(" + targetClass + ")", e); } final ParseStackEntry pse = new ParseStackEntry(target); final Deque<ParseStackEntry> parseStack = new ArrayDeque<ParseStackEntry>(); parseStack.push(pse); return target; }
From source file:com.offbynull.peernetic.playground.chorddht.model.SuccessorTable.java
/** * Trims all successors below {@code successor}, then adds {@code successor} to the beginning of the successor list. If * {@code successor} is the base pointer, all other successors will be cleared out. * @param successor new immediate successor * @throws NullPointerException if any arguments are {@code null} * @throws IllegalArgumentException if {@code successor}'s id has a different limit bit size than the base pointer's id *//*from ww w . j av a 2s . co m*/ public void updateTrim(Pointer successor) { Validate.notNull(successor); Id baseId = basePtr.getId(); Id successorId = successor.getId(); Validate.isTrue(IdUtils.getBitLength(successorId) == limit); if (baseId.equals(successorId)) { // test above makes sure if this is true, successor will be of correct type table = new ArrayDeque<>(); table.add(successor); return; } while (!table.isEmpty()) { Pointer ptr = table.removeFirst(); Id ptrId = ptr.getId(); if (Id.comparePosition(baseId, ptrId, successorId) > 0) { table.addFirst(ptr); break; } } table.addFirst(successor); if (table.size() > limit) { table.removeLast(); } }
From source file:com.cinchapi.concourse.lang.Parser.java
/** * Convert a valid and well-formed list of {@link Symbol} objects into a * Queue in postfix notation./*from w ww . j a v a 2s . co m*/ * <p> * NOTE: This method will group non-conjunctive symbols into * {@link Expression} objects. * </p> * * @param symbols * @return the symbols in postfix notation */ public static Queue<PostfixNotationSymbol> toPostfixNotation(List<Symbol> symbols) { Deque<Symbol> stack = new ArrayDeque<Symbol>(); Queue<PostfixNotationSymbol> queue = new LinkedList<PostfixNotationSymbol>(); symbols = groupExpressions(symbols); for (Symbol symbol : symbols) { if (symbol instanceof ConjunctionSymbol) { while (!stack.isEmpty()) { Symbol top = stack.peek(); if (symbol == ConjunctionSymbol.OR && (top == ConjunctionSymbol.OR || top == ConjunctionSymbol.AND)) { queue.add((PostfixNotationSymbol) stack.pop()); } else { break; } } stack.push(symbol); } else if (symbol == ParenthesisSymbol.LEFT) { stack.push(symbol); } else if (symbol == ParenthesisSymbol.RIGHT) { boolean foundLeftParen = false; while (!stack.isEmpty()) { Symbol top = stack.peek(); if (top == ParenthesisSymbol.LEFT) { foundLeftParen = true; break; } else { queue.add((PostfixNotationSymbol) stack.pop()); } } if (!foundLeftParen) { throw new SyntaxException( MessageFormat.format("Syntax error in {0}: Mismatched parenthesis", symbols)); } else { stack.pop(); } } else { queue.add((PostfixNotationSymbol) symbol); } } while (!stack.isEmpty()) { Symbol top = stack.peek(); if (top instanceof ParenthesisSymbol) { throw new SyntaxException( MessageFormat.format("Syntax error in {0}: Mismatched parenthesis", symbols)); } else { queue.add((PostfixNotationSymbol) stack.pop()); } } return queue; }
From source file:org.swiftexplorer.util.FileUtils.java
public static Queue<Path> getAllFilesPath(Path srcDir, boolean inludeDir) throws IOException { Queue<Path> queue = new ArrayDeque<Path>(); if (srcDir == null || !Files.isDirectory(srcDir)) return queue; TreePathFinder tpf = new TreePathFinder(queue, inludeDir); Files.walkFileTree(srcDir, tpf); return queue; }
From source file:com.espertech.esper.filter.FilterServiceImpl.java
public final long evaluate(EventBean theEvent, Collection<FilterHandle> matches, String statementId) { long version = filtersVersion; numEventsEvaluated.incrementAndGet(); ArrayDeque<FilterHandle> allMatches = new ArrayDeque<FilterHandle>(); // Finds all matching filters retryableMatchEvent(theEvent, allMatches); // Add statement matches to collection passed for (FilterHandle match : allMatches) { if (match.getStatementId().equals(statementId)) { matches.add(match);//from ww w . j av a2 s . c o m } } if ((AuditPath.isAuditEnabled) && (!filterServiceListeners.isEmpty())) { for (FilterServiceListener listener : filterServiceListeners) { listener.filtering(theEvent, matches, statementId); } } return version; }