List of usage examples for java.util Deque contains
boolean contains(Object o);
From source file:Main.java
public static void main(String[] args) { Deque<Integer> deque = new ArrayDeque<Integer>(8); deque.add(20);/* w w w . ja v a 2 s.c o m*/ deque.add(30); deque.add(10); deque.add(18); System.out.println(deque); // deque contains element 10 boolean retval = deque.contains(10); if (retval == true) { System.out.println("element 10 is contained in the deque"); } else { System.out.println("element 10 is not contained in the deque"); } }
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);/* w w w. j a va2 s. c o 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:com.darkstar.beanCartography.utils.finder.Finder.java
/** * Process the bean context stack.//from www . j a va2 s . c om * * @param stack stack of objects left to search * @param visited set of objects already searched */ protected void visit(Deque<BeanContext> stack, Set<BeanContext> visited) { BeanContext target = stack.pop(); if (target == null) return; if (visited.contains(target)) return; visited.add(target); // process this object and check the filters. if passed filter then run interceptors... filtersInterceptors.entrySet().stream().filter(entry -> entry.getKey().accept(target.getSource())) .forEach(entry -> entry.getValue().intercept(target.getSource())); // process this object's contained objects (i.e. see what we need to add to the stack)... if (NameUtils.isImmutable(target.getSource().getClass())) return; Object fieldValue = null; try { while (target.hasNextFieldValue()) { fieldValue = target.nextFieldValue(); // skip nulls... if (fieldValue == null) continue; // add pojo or container or whatever this is... if (!visited.contains(fieldValue) && !stack.contains(fieldValue)) stack.add(new BeanContext(fieldValue)); // arrays... if (fieldValue.getClass().isArray()) { if (!processArrays) continue; final Object arrayFieldValue = fieldValue; IntStream.range(0, Array.getLength(arrayFieldValue)).forEach(i -> { Object element = Array.get(arrayFieldValue, i); if (element != null && !visited.contains(element) && !stack.contains(element)) stack.add(new BeanContext(element)); }); // collections... } else if (fieldValue instanceof Collection<?>) { if (!processCollections) continue; ((Collection<?>) fieldValue).stream().filter( element -> element != null && !visited.contains(element) && !stack.contains(element)) .forEach(element -> stack.add(new BeanContext(element))); // maps... } else if (fieldValue instanceof Map<?, ?>) { if (!processMaps) continue; ((Map<?, ?>) fieldValue).entrySet().stream().forEach(entry -> { if (entry.getKey() != null && !visited.contains(entry.getKey()) && !stack.contains(entry.getKey())) stack.add(new BeanContext(entry.getKey())); if (entry.getValue() != null && !visited.contains(entry.getValue()) && !stack.contains(entry.getValue())) stack.add(new BeanContext(entry.getValue())); }); } } } catch (Exception e) { e.printStackTrace(); } }
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);//from w w w. ja v a 2s . c om 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:org.apache.oozie.workflow.lite.LiteWorkflowValidator.java
private void checkCycle(Deque<String> path, String nodeName) throws WorkflowException { if (path.contains(nodeName)) { path.addLast(nodeName);//from ww w. j a v a2 s . c o m throw new WorkflowException(ErrorCode.E0707, nodeName, Joiner.on("->").join(path)); } }
From source file:org.apache.pig.newplan.BaseOperatorPlan.java
/** * Move everything below a given operator to the new operator plan. The specified operator will * be moved and will be the root of the new operator plan * @param root Operator to move everything after * @param newPlan new operator plan to move things into * @throws PlanException /* w ww. ja va 2s.co m*/ */ public void moveTree(Operator root, BaseOperatorPlan newPlan) throws FrontendException { Deque<Operator> queue = new ArrayDeque<Operator>(); newPlan.add(root); root.setPlan(newPlan); queue.addLast(root); while (!queue.isEmpty()) { Operator node = queue.poll(); if (getSuccessors(node) != null) { for (Operator succ : getSuccessors(node)) { if (!queue.contains(succ)) { queue.addLast(succ); newPlan.add(succ); succ.setPlan(newPlan); newPlan.connect(node, succ); } } } } trimBelow(root); }
From source file:org.jaffa.qm.util.PropertyFilter.java
private static void getFieldList(Class clazz, List<String> fieldList, String prefix, Deque<Class> classStack) throws IntrospectionException { //To avoid recursion, bail out if the input Class has already been introspected if (classStack.contains(clazz)) { if (log.isDebugEnabled()) log.debug("Fields from " + clazz + " prefixed by " + prefix + " will be ignored, since the class has already been introspected as per the stack " + classStack);//from www .j a va 2 s .c o m return; } else classStack.addFirst(clazz); //Introspect the input Class BeanInfo beanInfo = Introspector.getBeanInfo(clazz); if (beanInfo != null) { PropertyDescriptor[] pds = beanInfo.getPropertyDescriptors(); if (pds != null) { for (PropertyDescriptor pd : pds) { if (pd.getReadMethod() != null && pd.getWriteMethod() != null) { String name = pd.getName(); String qualifieldName = prefix == null || prefix.length() == 0 ? name : prefix + '.' + name; Class type = pd.getPropertyType(); if (type.isArray()) type = type.getComponentType(); if (type == String.class || type == Boolean.class || Number.class.isAssignableFrom(type) || IDateBase.class.isAssignableFrom(type) || Currency.class.isAssignableFrom(type) || type.isPrimitive() || type.isEnum()) fieldList.add(qualifieldName); else getFieldList(type, fieldList, qualifieldName, classStack); } } } } classStack.removeFirst(); }
From source file:org.lilyproject.repository.impl.AbstractTypeManager.java
private void collectSubTypes(SchemaId recordTypeId, Set<SchemaId> result, Deque<SchemaId> parents, boolean recursive) throws InterruptedException { // the parent-stack is to protect against endless loops in the type hierarchy. If a type is a subtype // of itself, it will not be included in the result. Thus if record type A extends (directly or indirectly) // from A, and we search the subtypes of A, then the resulting set will not include A. parents.push(recordTypeId);//from w ww.j ava 2 s.c om Set<SchemaId> subtypes = schemaCache.findDirectSubTypes(recordTypeId); for (SchemaId subtype : subtypes) { if (!parents.contains(subtype)) { result.add(subtype); if (recursive) { collectSubTypes(subtype, result, parents, recursive); } } else { // Loop detected in type hierarchy, log a warning about this log.warn(formatSupertypeLoopError(subtype, parents)); } } parents.pop(); }
From source file:org.lilyproject.repository.impl.HBaseTypeManager.java
private RecordType updateRecordType(RecordType recordType, boolean refreshSubtypes, Deque<SchemaId> parents) throws RepositoryException, InterruptedException { // First update the record type RecordType updatedRecordType = updateRecordType(recordType); if (!refreshSubtypes) { return updatedRecordType; }//from w ww . jav a 2 s . c om parents.push(updatedRecordType.getId()); try { Set<SchemaId> subtypes = findDirectSubtypes(updatedRecordType.getId()); for (SchemaId subtype : subtypes) { if (!parents.contains(subtype)) { RecordType subRecordType = getRecordTypeById(subtype, null); for (Map.Entry<SchemaId, Long> supertype : subRecordType.getSupertypes().entrySet()) { if (supertype.getKey().equals(updatedRecordType.getId())) { if (!supertype.getValue().equals(updatedRecordType.getVersion())) { subRecordType.addSupertype(updatedRecordType.getId(), updatedRecordType.getVersion()); // Store the change, and recursively adjust the pointers in this record type's subtypes as well updateRecordType(subRecordType, true, parents); } break; } } } else { // Loop detected in type hierarchy, log a warning about this log.warn(formatSupertypeLoopError(subtype, parents)); } } } catch (RepositoryException e) { throw new RepositoryException("Error while refreshing subtypes of record type " + recordType.getName(), e); } parents.pop(); return updatedRecordType; }
From source file:org.mypsycho.util.PropertiesLoader.java
protected String resolveProperty(Bundle bundle, String key, Deque<String> refStack) { String fullKey = key;/*from w w w .ja va2 s. c o m*/ String localKey = key; int indexBundle = key.indexOf(MEMBER_TOKEN); Bundle definingBundle = bundle; if (indexBundle < 0) { // local name fullKey = bundle.getBasename() + MEMBER_TOKEN + key; } else if ((indexBundle > 0) && (key.indexOf(MEMBER_TOKEN, indexBundle + 1) < 0)) { String basename = key.substring(0, indexBundle); localKey = key.substring(indexBundle + 1); definingBundle = getBundle(basename, bundle.getLocale(), bundle.getContext()); } else { handle("malformedKey", key + " in " + bundle.getBasename()); } // else not a cross reference fullKey == localKey == key if (refStack.contains(fullKey)) { handle("recursivity", fullKey); return SUBST_TOKEN + key + END_TOKEN; } Object value = null; for (int fb = localKey.length(); (value == null) && (fb != -1); fb = localKey.lastIndexOf(FALLBACK_TOKEN, fb - 1)) { value = definingBundle.getDefinition(localKey.substring(0, fb)); } // value = definingBundle.getDefinition(localKey); if (value == null) { // not defined if (env != null) { // Extension Point value = env.getProperty(key); if (value != null) { return (String) value; } } handle("undefined", fullKey); return SUBST_TOKEN + key + END_TOKEN; } if (value instanceof String) { // already substituted return (String) value; } // else unresolved value refStack.addLast(fullKey); String newValue = resolveExpression(definingBundle, ((String[]) value)[0], refStack); refStack.removeLast(); definingBundle.putValue(localKey, newValue); return newValue; }