List of usage examples for java.util List remove
E remove(int index);
From source file:CookieUtils.java
/** * Maintain a list of CookieData objects (add, replace, or delete a cookie) * /*from ww w . jav a2 s . c o m*/ * @param cookieList * CookieData list * @param cookie * A CookieData object */ public static void storeCookie(List cookieList, CookieData cookie) { int size = cookieList.size(); for (int i = 0; i < size; i++) { CookieData cd = (CookieData) cookieList.get(i); if (cookie.equals(cd)) { if (cookie.getMaxAge() == 0) { cookieList.remove(i); return; } cookieList.set(i, cookie); return; } } if (cookie.getMaxAge() != 0) { cookieList.add(cookie); } }
From source file:Main.java
public static String camelCaseToSnakeCase(String camelCase) { List<String> tokens = new ArrayList<String>(); Matcher matcher = pattern.matcher(camelCase); String acronym = ""; while (matcher.find()) { String found = matcher.group(); if (found.matches("^[A-Z]$")) { acronym += found;/*w ww . jav a2s . c o m*/ } else { if (acronym.length() > 0) { // we have an acronym to add before we continue tokens.add(acronym); acronym = ""; } tokens.add(found.toLowerCase()); } } if (acronym.length() > 0) { tokens.add(acronym); } if (tokens.size() > 0) { StringBuilder sb = new StringBuilder(tokens.remove(0)); for (String s : tokens) { sb.append("_").append(s); } return sb.toString(); } else { return camelCase; } }
From source file:com.netflix.spinnaker.halyard.cli.command.v1.config.AbstractConfigCommand.java
/** * Provides consistent update semantics for updating a list of entries given a new list, entries to remove, and entries to add. * * @param old is the prior set of entries - these are modified to addTo and removeFrom. * @param setTo is a new set of entries. If provided, the old ones are discarded. * @param addTo is a single entry to add to old. * @param removeFrom is a single entry to remove from old. * @return the updated set of entries./*from w w w . ja v a 2s .co m*/ * @throws IllegalArgumentException when setTo and (addTo or removeFrom) are provided. */ protected static List<String> updateStringList(List<String> old, List<String> setTo, String addTo, String removeFrom) { if (old == null) { old = new ArrayList<>(); } boolean set = setTo != null && !setTo.isEmpty(); boolean add = addTo != null && !addTo.isEmpty(); boolean remove = removeFrom != null && !removeFrom.isEmpty(); if (set && (add || remove)) { throw new IllegalArgumentException( "If set is specified, neither addTo nor removeFrom can be specified"); } if (set) { return setTo; } else { if (add) { old.add(addTo); } if (remove) { old.remove(removeFrom); } return old; } }
From source file:com.conversantmedia.mapreduce.tool.RunJob.java
/** * Outputs the driver's list/*from w ww.jav a 2s . c om*/ * * @param driversMap map of driver metadata to output to console */ protected static void outputDriversTable(Map<String, DriverMeta> driversMap) { String[] colNames = new String[] { "Name", "Description", "Ver", "Class" }; String[] aligns = new String[] { "-", "-", "-", "-" }; int maxDescriptionWidth = 48; int widths[] = new int[colNames.length]; for (int i = 0; i < colNames.length; i++) { widths[i] = colNames[i].length(); } int padding = 2; for (Entry<String, DriverMeta> e : driversMap.entrySet()) { if (!e.getValue().hidden) { int i = 0; widths[i] = Math.max(e.getKey().length(), widths[i]); widths[i + 1] = Math.min(Math.max(e.getValue().description.length(), widths[i + 1]), maxDescriptionWidth); widths[i + 2] = Math.max(e.getValue().version.length(), widths[i + 2]); widths[i + 3] = Math.max(e.getValue().driverClass.getName().length(), widths[i + 3]); } } // sum widths int width = padding * widths.length - 1; for (int w : widths) { width += w; } String sep = StringUtils.repeat("=", width); System.out.println(sep); System.out.println(StringUtils.center("A V A I L A B L E D R I V E R S", width)); System.out.println(sep); String[] underscores = new String[colNames.length]; StringBuilder headersFormatSb = new StringBuilder(); StringBuilder valuesFormatSb = new StringBuilder(); for (int i = 0; i < widths.length; i++) { headersFormatSb.append("%-").append(widths[i] + padding).append("s"); valuesFormatSb.append("%").append(aligns[i]).append(widths[i] + padding).append("s"); underscores[i] = StringUtils.repeat("-", widths[i]); } String format = headersFormatSb.toString(); System.out.format(format, (Object[]) colNames); System.out.println(); System.out.format(format, (Object[]) underscores); System.out.println(); format = valuesFormatSb.toString(); List<String> descriptionLines = new ArrayList<>(); for (Entry<String, DriverMeta> e : driversMap.entrySet()) { if (!e.getValue().hidden) { descriptionLines.clear(); String description = e.getValue().description; if (description.length() > maxDescriptionWidth) { splitLine(descriptionLines, description, maxDescriptionWidth); description = descriptionLines.remove(0); } System.out.format(format, e.getKey(), description, StringUtils.center(e.getValue().version, widths[2]), e.getValue().driverClass.getName()); System.out.println(); while (!descriptionLines.isEmpty()) { System.out.format(format, "", descriptionLines.remove(0), "", ""); System.out.println(); } } } }
From source file:controllers.nwbib.Application.java
/** * @param id The resource ID to unstar//from ww w. j a v a 2 s.co m * @return An OK result */ public static Result unstar(String id) { List<String> starred = starredIds(); starred.remove(id); session(STARRED, String.join(" ", starred)); uncache(Arrays.asList(id)); uncacheLastSearchUrl(); return ok("Unstarred: " + id); }
From source file:gov.nih.nci.caIMAGE.util.NewDropdownUtil.java
/** * Add Other to the list in the first spot if it's not already there. * Removes it and put's it in the first spot if it is. *//*from w w w .j a va 2 s .c om*/ private static void addOtherOption(List inList) { DropdownOption theDropdownOption = new DropdownOption(Constants.Dropdowns.OTHER_OPTION, Constants.Dropdowns.OTHER_OPTION); if (!inList.contains(theDropdownOption)) { inList.add(0, theDropdownOption); } else { inList.remove(theDropdownOption); inList.add(0, theDropdownOption); } }
From source file:fll.scheduler.TableOptimizer.java
/** * Recursive function that computes permutations. To * be called from {@see #permutate(int)}. * /*from ww w. j a v a2s . co m*/ * @param arrayCount * @param elements the elements to compute permutations of * @param order * @param permutations the resulting permutations */ static private void permutate(final int arrayCount, final List<Integer> elements, final List<Integer> order, final List<List<Integer>> permutations) { if (elements.isEmpty()) { throw new IllegalArgumentException("Cannot permutate 0 elements"); } final int position = arrayCount - elements.size(); if (elements.size() == 1) { order.set(position, elements.get(0)); permutations.add(order); } else { for (int i = 0; i < elements.size(); ++i) { final int element = elements.get(i); final List<Integer> newOrder = new ArrayList<Integer>(order); newOrder.set(position, element); final List<Integer> newElements = new ArrayList<Integer>(elements); newElements.remove(i); permutate(arrayCount, newElements, newOrder, permutations); } } }
From source file:com.gargoylesoftware.htmlunit.runners.TestCaseCorrector.java
private static int addExpectation(final List<String> lines, int i, final String browserString, final ComparisonFailure comparisonFailure) { while (!lines.get(i).startsWith(" @Alerts")) { i--;// w w w . j a v a2s . c om } final List<String> alerts = CodeStyleTest.alertsToList(lines, i); for (final Iterator<String> it = alerts.iterator(); it.hasNext();) { if (it.next().startsWith(browserString + " = ")) { it.remove(); } } alerts.add(browserString + " = " + getActualString(comparisonFailure)); lines.remove(i); while (lines.get(i).startsWith(" ")) { lines.remove(i); } for (int x = 0; x < alerts.size(); x++) { String line = alerts.get(x); if (x == 0) { if (!line.contains(" = ")) { line = "DEFAULT = " + line; } line = " @Alerts(" + line; } else { line = " " + line; } if (x < alerts.size() - 1) { line += ","; } else { line += ")"; } lines.add(i++, line); } return i; }
From source file:com.flexive.shared.structure.FxStructureOption.java
/** * Clear the option with the given key - removing it from the list if it exists * * @param options list options to clear the option for * @param key key of the option to remove *///from w w w. j a v a 2 s. c o m public static void clearOption(List<FxStructureOption> options, String key) { if (key != null) key = key.trim().toUpperCase(); if (key == null || key.length() == 0 || options == null || options.size() == 0) return; synchronized (options) { for (FxStructureOption option : options) if (key.equals(option.getKey())) { options.remove(option); return; } } }
From source file:com.core.controller.AlgoritmoController.java
public static String busquedaEscaladaSimple(Grafo g, String inicio, String fin) { String result = "Algoritmo de Busqueda Escalada Simple"; result += "\nCantidad de nodos: " + g.getNodos().size(); result += "\nCantidad de aristas: " + g.getAristas().size(); List<String> explotados = new ArrayList<>(); String nodoActual = inicio;//from www. j a v a 2 s.co m explotados.add(nodoActual); boolean bandera; while (true) { int valorNodoActual = g.buscarNodo(nodoActual).getValor(); int valorNodoProx; if (nodoActual.equals(fin)) { result += "\nSe alcanzo el nodo destino"; break; } List<String> vecinos = g.nodosVecinos(nodoActual); for (int i = 0; i < vecinos.size(); i++) { if (explotados.contains(vecinos.get(i))) { vecinos.remove(i); } } if (vecinos.isEmpty()) { result += "\nNo se alcanzo el nodo destino"; break; } bandera = true; for (int i = 0; i < vecinos.size(); i++) { valorNodoProx = g.buscarNodo(vecinos.get(i)).getValor(); if (valorNodoActual > valorNodoProx) { nodoActual = vecinos.get(i); explotados.add(nodoActual); bandera = false; break; } } if (bandera) { result += "\nNo se alcanzo el nodo destino"; break; } } result += "\nExplotados: " + Arrays.toString(explotados.toArray()); return result; }