List of usage examples for java.util Deque isEmpty
boolean isEmpty();
From source file:cz.cuni.mff.ksi.jinfer.autoeditor.automatonvisualizer.layouts.AutomatonToDot.java
public String convertToDot(Automaton<T> automaton, Transformer<Step<T>, String> edgeLabelTransformer) { StringBuilder sb = new StringBuilder(); sb.append("digraph finite_state_machine {\n" + "\trankdir=LR;\n" + "\tnode [shape = circle];\n"); List<State<T>> finiteStates = new LinkedList<State<T>>(); Deque<State<T>> queue = new ArrayDeque<State<T>>(); Set<State<T>> visited = new HashSet<State<T>>(); queue.addLast(automaton.getInitialState()); visited.add(automaton.getInitialState()); while (!queue.isEmpty()) { State<T> actual = queue.removeFirst(); if (actual.getFinalCount() > 0) { finiteStates.add(actual);//from w w w .j a va2 s. co m } for (Step<T> step : automaton.getDelta().get(actual)) { sb.append("\t"); sb.append(step.getSource().getName()); sb.append(" -> "); sb.append(step.getDestination().getName()); sb.append(" [ label = \""); sb.append(edgeLabelTransformer.transform(step)); sb.append("|"); sb.append(step.getUseCount()); sb.append("\" ];\n"); if (!visited.contains(step.getDestination())) { queue.addLast(step.getDestination()); visited.add(step.getDestination()); } } } sb.append("\n}"); return sb.toString(); }
From source file:org.polymap.rhei.form.BasePageContainer.java
protected void updateEnabled() { if (pageBody == null || pageBody.isDisposed()) { return;// w ww . java 2 s .com } Deque<Control> deque = new LinkedList(Collections.singleton(pageBody)); while (!deque.isEmpty()) { Control control = deque.pop(); String variant = (String) control.getData(RWT.CUSTOM_VARIANT); log.debug("VARIANT: " + variant + " (" + control.getClass().getSimpleName() + ")"); log.warn("!!! NOT YET (RE)IMPLEMENTED !!!"); // // form fields // if (variant == null // || variant.equals( CSS_FORMFIELD ) || variant.equals( CSS_FORMFIELD_DISABLED ) // || variant.equals( CUSTOM_VARIANT_VALUE ) || variant.equals( CUSTOM_VARIANT_VALUE )) { // UIUtils.setVariant( control, enabled ? CSS_FORMFIELD : CSS_FORMFIELD_DISABLED ); // } // // form // else if (variant.equals( CSS_FORM ) || variant.equals( CSS_FORM_DISABLED )) { // UIUtils.setVariant( control, enabled ? CSS_FORM : CSS_FORM_DISABLED ); // } // // labeler Label // String labelVariant = (String)control.getData( WidgetUtil.CUSTOM_VARIANT ); // if (control instanceof Label // && (labelVariant.equals( CSS_FORMFIELD ) || labelVariant.equals( CSS_FORMFIELD_DISABLED ))) { // control.setFont( enabled // ? JFaceResources.getFontRegistry().get( JFaceResources.DEFAULT_FONT ) // : JFaceResources.getFontRegistry().getBold( JFaceResources.DEFAULT_FONT ) ); // // if (!enabled) { // control.setBackground( Graphics.getColor( 0xED, 0xEF, 0xF1 ) ); // } // } // Composite if (control instanceof Composite) { control.setEnabled(enabled); deque.addAll(Arrays.asList(((Composite) control).getChildren())); } variant = (String) control.getData(RWT.CUSTOM_VARIANT); log.debug(" -> " + variant + " (" + control.getClass().getSimpleName() + ")"); } }
From source file:logicProteinHypernetwork.analysis.reactions.ComplexMultigraph.java
public Set<Integer> bfs() { Set<Integer> visited = new HashSet<Integer>(); Deque<Integer> todo = new ArrayDeque<Integer>(); todo.add(0);//ww w . ja v a 2s. com while (!todo.isEmpty()) { int u = todo.remove(); visited.add(u); for (int v : getNeighbors(u)) { todo.add(v); } } return visited; }
From source file:logicProteinHypernetwork.analysis.reactions.ComplexMultigraph.java
private void subtract(Set<Interaction> impossible, int vertex) throws NotConnectedException { Set<Integer> visited = new HashSet<Integer>(); Deque<Integer> todo = new ArrayDeque<Integer>(); todo.add(vertex);// www . ja v a 2s . c o m while (!todo.isEmpty()) { int u = todo.remove(); visited.add(u); for (int e : getIncidentEdges(u)) { Interaction i = edgesToInteractions.get(e); if (impossible.contains(i)) { removeEdge(e); edgesToInteractions.remove(e); interactionToEdges.remove(i, e); impossible.remove(i); } } for (int v : getNeighbors(u)) { todo.add(v); } } if (visited.size() < getVertexCount()) { throw new NotConnectedException(); } }
From source file:com.reprezen.swaggerparser.test.BigParseTest.java
private Object getFromModelObject(JsonOverlay<?> modelObj, Deque<PathKey> path) { if (modelObj == null) { throw new NullPointerException("Attempt to get value of a null overlay"); } else if (path.isEmpty()) { return modelObj.get(); } else {//from www . j a v a2s .c o m PathKey key = path.remove(); if (modelObj instanceof CollectionOverlay<?>) { JsonOverlay<?> item = getFromCollectionOverlay((CollectionOverlay<?>) modelObj, key); return getFromModelObject(item, path); } else if (modelObj instanceof ObjectOverlay<?>) { path.addFirst(key); ArrayDeque<PathKey> origPath = Queues.newArrayDeque(path); Optional<? extends JsonOverlay<?>> field; try { field = getField((ObjectOverlay<?>) modelObj, path); } catch (IllegalArgumentException | IllegalAccessException e) { throw new IllegalStateException("Cannot access object overlay field value", e); } if (field.isPresent()) { return getFromModelObject(field.get(), path); } else { throw new IllegalArgumentException( "Path does not identify an object overlay field: " + origPath); } } else { throw new UnsupportedOperationException("Attempt to get a component from a primitive overlay"); } } }
From source file:com.icantrap.collections.dawg.DawgBuilder.java
/** * The number of nodes - currently - in the structure that will become the Dawg. * @return the number of nodes/*from w w w . jav a 2 s . c o m*/ */ public int nodeCount() { int nodeCount = 0; Deque<Node> stack = new LinkedList<Node>(); stack.push(root); while (!stack.isEmpty()) { Node ptr = stack.pop(); ++nodeCount; for (Node nextChild : ptr.nextChildren) stack.push(nextChild); if (null != ptr.child) stack.push(ptr.child); } return nodeCount; }
From source file:org.deeplearning4j.text.corpora.treeparser.BinarizeTreeTransformer.java
@Override public Tree transform(Tree t) { if (t == null) return null; Deque<Pair<Tree, String>> stack = new ArrayDeque<>(); stack.add(new Pair<>(t, t.label())); String originalLabel = t.label(); while (!stack.isEmpty()) { Pair<Tree, String> curr = stack.pop(); Tree node = curr.getFirst();/* w w w .j a v a 2 s. c o m*/ for (Tree child : node.children()) stack.add(new Pair<>(child, curr.getSecond())); if (node.children().size() > 2) { List<String> children = new ArrayList<>(); for (int i = 0; i < node.children().size(); i++) children.add(node.children().get(i).label()); Tree copy = node.clone(); //clear out children node.children().clear(); Tree currNode = node; for (int i = 1; i < children.size() - 1; i++) { if (factor.equals("right")) { Tree newNode = new Tree(currNode); List<String> subChildren = children.subList(i, Math.min(i + horizontonalMarkov, children.size())); newNode.setLabel(originalLabel + "-" + "(" + StringUtils.join(subChildren, "-")); newNode.setParent(currNode); currNode.children().add(copy.children().remove(0)); currNode.firstChild().setParent(currNode); currNode.children().add(newNode); currNode = newNode; } else { Tree newNode = new Tree(currNode); newNode.setParent(copy.firstChild()); List<String> childLabels = children .subList(Math.max(children.size() - i - horizontonalMarkov, 0), i); Collections.reverse(childLabels); newNode.setLabel(originalLabel + "-" + "(" + StringUtils.join(childLabels, "-")); currNode.children().add(newNode); currNode.firstChild().setParent(currNode); currNode.children().add(copy.children().remove(copy.children().size() - 1)); currNode.lastChild().setParent(currNode); currNode = newNode; } } currNode.children().addAll(new ArrayList<>(copy.children())); } } addPreTerminal(t); return t; }
From source file:com.core.controller.AlgoritmoController.java
public static Solucion busquedaProfundidadConSolucion(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; Solucion result = new Solucion("Algoritmo de Busqueda Primero en Profundidad"); result.agregarPaso("Cantidad de nodos: " + g.getNodos().size()); result.agregarPaso("Cantidad de aristas: " + g.getAristas().size()); pila.push(inicio);//ww w . j a va2 s. c o m padresPila.push("#"); while (true) { result.agregarPaso("Pila: " + Arrays.toString(pila.toArray())); if (pila.isEmpty()) { result.agregarPaso("No se encontro el nodo destino"); break; } nodoActual = pila.pop(); nodoPadre = padresPila.pop(); explorados.add(nodoActual); padresExplorados.add(nodoPadre); if (nodoActual.equals(fin)) { 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); 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); } } } //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]; System.out.println("Solucion: " + solucion); 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:com.griddynamics.banshun.DependencySorter.java
private List<Location> sortLocations() { Deque<Location> stack = new LinkedList<>(locations); List<Location> sorted = pullLocationListHead(stack); if (stack.isEmpty()) { return sorted; }//from w ww .ja v a 2 s. c om List<Location> tail = pullLocationListTail(stack); if (!stack.isEmpty()) { String message = "Cyclic dependencies found in child contexts: "; if (prohibitCycles) { throw new BeanCreationException(message + stack); } log.warn(message + "{}", stack); } conflictContextGroup = new ArrayList<>(stack); sorted.addAll(stack); //add conflict locations sorted.addAll(tail); //add rest return sorted; }
From source file:org.onehippo.cms7.essentials.dashboard.instruction.FileInstruction.java
private void processDirectories(final Deque<String> directories) throws IOException { if (!directories.isEmpty()) { folderMessage = directories.size() > 1 ? directories.size() - 1 + " directories" : "directory"; createdFolders = directories.getLast().substring(directories.getFirst().length()); createdFoldersTarget = directories.getLast(); Files.createDirectories(new File(directories.getLast()).toPath()); eventBus.post(new InstructionEvent(messageFolderCreate)); }/*from w ww . ja v a2 s .c o m*/ }