List of usage examples for java.util LinkedList LinkedList
public LinkedList()
From source file:protocol_whatsapp.User.java
public User(String _userName, String _phoneNumber) { this._userName = _userName; this._phoneNumber = _phoneNumber; this._massegesQueue = new LinkedList(); this._cookie = new BasicClientCookie((_userName + "Cookie"), _userName); }
From source file:Main.java
/** * Returns a list of objects of <code>expectedType</code> contained in the given <code>collection</code>. Any * objects in the collection that are not assignable to the given <code>expectedType</code> are filtered out. * <p>/*from w ww. j a va2 s. co m*/ * The order of the items in the list is the same as the order they were provided by the collection. The given * <code>collection</code> remains unchanged by this method. * <p> * If the given collection is null, en empty list is returned. * * @param collection An iterable (e.g. Collection) containing the unfiltered items. * @param expectedType The type items in the returned List must be assignable to. * @param <T> The type items in the returned List must be assignable to. * @return a list of objects of <code>expectedType</code>. May be empty, but never <code>null</code>. */ public static <T> List<T> filterByType(Iterable<?> collection, Class<T> expectedType) { List<T> filtered = new LinkedList<>(); if (collection != null) { for (Object item : collection) { if (item != null && expectedType.isInstance(item)) { filtered.add(expectedType.cast(item)); } } } return filtered; }
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);/*from w w w . j a v a2 s. c om*/ 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:com.stimulus.archiva.presentation.DomainBean.java
public static List<DomainBean> getDomainBeans(List<Domains.Domain> Domains) { List<DomainBean> DomainBeans = new LinkedList<DomainBean>(); for (Domains.Domain domain : Domains) DomainBeans.add(new DomainBean(domain)); return DomainBeans; }
From source file:com.jstar.eclipse.processing.annotations.FileAnnotations.java
public FileAnnotations(final String sourceFileName) { this.sourceFileName = sourceFileName; classAnnotations = new LinkedList<ClassAnnotations>(); importAnnotations = new LinkedList<ImportObject>(); }
From source file:edu.eci.arsw.loannetsim.LoanNetworkSimulation.java
public static List<Lender> setupLoanNetwork(int ni, ApplicationContext ac) { List<Lender> il = new LinkedList<>(); for (int i = 0; i < ni; i++) { Lender i1 = ac.getBean(Lender.class); i1.setLoanNetworkPopulation(il); i1.setLenderName("Lender #" + i); il.add(i1);/*from w w w . j a va2 s . co m*/ } return il; }
From source file:fi.smaa.libror.MaximalVectorComputation.java
/** * Implements the Best algorithm as described in Godfrey & al., VLDB Journal, 2007. * /*from w w w . j a v a2 s .c o m*/ * @param mat The matrix of values (each row = 1 vector of input) * * @return Matrix containing rows from the input s.t. none are dominated */ public static RealMatrix computeBEST(RealMatrix mat) { LinkedList<RealVector> list = matrixToListOfRows(mat); LinkedList<RealVector> results = new LinkedList<RealVector>(); while (list.size() > 0) { Iterator<RealVector> iter = list.iterator(); RealVector b = iter.next(); // Get the first iter.remove(); while (iter.hasNext()) { // Find a max RealVector t = iter.next(); if (dominates(b, t)) { iter.remove(); } else if (dominates(t, b)) { iter.remove(); b = t; } } results.add(b); iter = list.iterator(); while (iter.hasNext()) { // Clean up RealVector t = iter.next(); if (dominates(b, t)) { iter.remove(); } } } return listOfRowsToMatrix(results); }
From source file:Main.java
/** * Normalize a uri containing ../ and ./ paths. * * @param uri The uri path to normalize// ww w. j av a 2s .c o m * @return The normalized uri */ public static String normalize(String uri) { if ("".equals(uri)) { return uri; } int leadingSlashes; for (leadingSlashes = 0; leadingSlashes < uri.length() && uri.charAt(leadingSlashes) == '/'; ++leadingSlashes) { } boolean isDir = (uri.charAt(uri.length() - 1) == '/'); StringTokenizer st = new StringTokenizer(uri, "/"); LinkedList clean = new LinkedList(); while (st.hasMoreTokens()) { String token = st.nextToken(); if ("..".equals(token)) { if (!clean.isEmpty() && !"..".equals(clean.getLast())) { clean.removeLast(); if (!st.hasMoreTokens()) { isDir = true; } } else { clean.add(".."); } } else if (!".".equals(token) && !"".equals(token)) { clean.add(token); } } StringBuffer sb = new StringBuffer(); while (leadingSlashes-- > 0) { sb.append('/'); } for (Iterator it = clean.iterator(); it.hasNext();) { sb.append(it.next()); if (it.hasNext()) { sb.append('/'); } } if (isDir && sb.length() > 0 && sb.charAt(sb.length() - 1) != '/') { sb.append('/'); } return sb.toString(); }
From source file:com.insightml.evaluation.functions.Gini.java
private static <T> double gini(final T[] preds, final Object[] expected, final boolean doPerfect) { final List<Pair<Object, T>> sortedByPdesc = new LinkedList<>(); for (int i = 0; i < preds.length; ++i) { sortedByPdesc.add(new Pair<>(expected[i], preds[i])); }/* www . j ava 2 s. c om*/ final boolean isBinary = sortedByPdesc.get(0).getSecond() instanceof Boolean; Collections.sort(sortedByPdesc, (o1, o2) -> { if (doPerfect) { if (isBinary) { return ((Boolean) o1.getFirst()).booleanValue() ? -1 : 1; } return (Double) o1.getFirst() >= (Double) o2.getFirst() ? -1 : 1; } return (Double) o1.getSecond() >= (Double) o2.getSecond() ? -1 : 1; }); double sum = 0; double giniSum = 0; for (final Pair<Object, T> prediction : sortedByPdesc) { if (isBinary) { sum += (Boolean) prediction.getFirst() ? 1 : 0; } else { sum += (Double) prediction.getFirst(); } giniSum += sum; } giniSum = giniSum / sum - (sortedByPdesc.size() + 1.0) / 2; return giniSum / sortedByPdesc.size(); }
From source file:com.microsoft.rest.pipeline.HttpRequestInterceptorAdapter.java
/** * Initialize a new instance of HttpRequestInterceptorAdapter. */ public HttpRequestInterceptorAdapter() { filters = new LinkedList<ServiceRequestFilter>(); }