List of usage examples for java.util List remove
E remove(int index);
From source file:org.tsm.concharto.web.eventsearch.SearchSessionUtil.java
@SuppressWarnings("unchecked") private static void updateEventInSession(HttpServletRequest request, Long eventId, Event event) { List<Event> events = (List<Event>) WebUtils.getSessionAttribute(request, SearchHelper.SESSION_EVENT_SEARCH_RESULTS); if (events != null) { for (int i = 0; i < events.size(); i++) { if (events.get(i).getId().equals(eventId)) { if (event == null) { //the event was deleted, so we should remove it here events.remove(i); } else { //replace it events.set(i, event); }//ww w.j av a 2 s . c o m } } WebUtils.setSessionAttribute(request, SearchHelper.SESSION_EVENT_SEARCH_RESULTS, events); } }
From source file:com.aurel.track.admin.customize.lists.importList.ImportListBL.java
/** * Remove the options that won't be deleted * @param removableElements/* w w w . j av a 2 s . c o m*/ * @param optionBean */ private static void removeOptionElement(List<TOptionBean> removableElements, TOptionBean optionBean) { for (int i = 0; i < removableElements.size(); i++) { if (removableElements.get(i).getObjectID().equals(optionBean.getObjectID())) removableElements.remove(i); } }
From source file:Os.java
private static OsFamily[] determineAllFamilies() { // Determine all families the current OS belongs to Set allFamilies = new HashSet(); if (OS_FAMILY != null) { List queue = new ArrayList(); queue.add(OS_FAMILY);/* www. j ava2 s. c o m*/ while (queue.size() > 0) { final OsFamily family = (OsFamily) queue.remove(0); allFamilies.add(family); final OsFamily[] families = family.getFamilies(); for (int i = 0; i < families.length; i++) { OsFamily parent = families[i]; queue.add(parent); } } } return (OsFamily[]) allFamilies.toArray(new OsFamily[allFamilies.size()]); }
From source file:com.amazonaws.mobileconnectors.s3.transferutility.TransferStatusUpdater.java
/** * Unregisters the listener from the transfer. * * @param id id of the transfer/*from w ww. j a v a 2 s . c o m*/ * @param listener a listener object */ static void unregisterListener(int id, TransferListener listener) { if (listener == null) { throw new IllegalArgumentException("Listener can't be null"); } final List<TransferListener> list = LISTENERS.get(id); if (list == null || list.isEmpty()) { return; } list.remove(listener); }
From source file:Main.java
/** * Using like subList() but it take randoms elements. * * @param list//from w w w.ja v a 2 s. c o m * @param sizeOfSubList */ public static <E> void randomSubList(List<E> list, int sizeOfSubList) { List<E> subList = Collections.emptyList(); if (isNotEmpty(list) && list.size() > sizeOfSubList) { subList = new ArrayList<E>(sizeOfSubList); Random generator = new Random(); for (int i = 0; i < sizeOfSubList; i++) { int random = generator.nextInt(list.size()); subList.add(list.get(random)); list.remove(random); } } list.clear(); list.addAll(subList); }
From source file:com.gargoylesoftware.htmlunit.WebConsole.java
/** * This method removes and returns the first (i.e. at index 0) element in * the passed list if it exists. Otherwise, null is returned. * @param list the/*from w w w. ja v a 2 s.co m*/ * @return the first object in the list or null */ private static Object pop(final List<Object> list) { return list.isEmpty() ? null : list.remove(0); }
From source file:Main.java
/** @param phrase1 * @param phrase2/* w ww . j av a2 s .c om*/ * @return lexical similarity value in the range [0,1] */ public static double lexicalSimilarity(String phrase1, String phrase2) { List<String> pairs1 = wordLetterPairs(phrase1.toUpperCase()); List<String> pairs2 = wordLetterPairs(phrase2.toUpperCase()); int intersection = 0; int union = pairs1.size() + pairs2.size(); for (int i = 0; i < pairs1.size(); i++) { String pair1 = pairs1.get(i); for (int j = 0; j < pairs2.size(); j++) { String pair2 = pairs2.get(j); if (pair1.equals(pair2)) { intersection++; pairs2.remove(j); break; } } } return (2.0 * intersection) / union; }
From source file:com.silverpeas.util.MapUtil.java
/** * Centralizes the map removing that containing list collections * * @param <K>// w w w . ja va2 s .c o m * @param <V> * @param map * @param key * @param value * @return */ public static <K, V> List<V> removeValueList(final Map<K, List<V>> map, final K key, final V value) { List<V> result = null; if (map != null) { // Old value result = map.get(key); if (result != null) { result.remove(value); } } // map result return result; }
From source file:edu.msu.cme.rdp.alignment.pairwise.PairwiseKNN.java
private static <T> void insert(T n, List<T> list, Comparator<T> comp, int k) { int i = list.size(); list.add(n);// ww w. j a v a2 s .c o m while (i > 0 && comp.compare(list.get(i), list.get(i - 1)) > 0) { Collections.swap(list, i, i - 1); i--; } if (list.size() > k) { list.remove(k); } }
From source file:Main.java
/** * Resizes the passed list to N entries. Will add the specified object if * the list is smaller than the desired size, discard trailing entries if * larger. This is primarily used to presize a list that will be accessed * by index, but it may also be used to truncate a list for display. * * @return The list, as a convenience for callers * * @throws UnsupportedOperationException if the list does not implement * <code>RandomAccess</code> and its list iterator does not * support the <code>remove()</code> operation *///www .jav a2 s. com public static <T> List<T> resize(List<T> list, int newSize, T obj) { if (list instanceof ArrayList) ((ArrayList<T>) list).ensureCapacity(newSize); if (list.size() < newSize) { for (int ii = list.size(); ii < newSize; ii++) list.add(obj); } else if (list.size() > newSize) { if (list instanceof RandomAccess) { for (int ii = list.size() - 1; ii >= newSize; ii--) list.remove(ii); } else { ListIterator<T> itx = list.listIterator(newSize); while (itx.hasNext()) { itx.next(); itx.remove(); } } } return list; }