List of usage examples for java.util List clear
void clear();
From source file:Main.java
static public <T> void unique(List<T> list) { HashSet<T> h = new HashSet<T>(); for (T i : list) { h.add(i);// w w w .j av a 2 s .c o m } list.clear(); for (T i : h) { list.add(i); } }
From source file:Main.java
public static <T extends Comparable<? super T>> void sort(List<T> list) { List<T> sortableList = new ArrayList<>(list); Collections.sort(sortableList); list.clear(); list.addAll(sortableList);// ww w . j a va2s . c om }
From source file:Main.java
public static <T> List<T> popSubList(List<T> originList, int fromIndex, int toIndex) { List<T> subList = originList.subList(fromIndex, toIndex); List<T> result = new ArrayList<T>(subList); subList.clear(); return result; }
From source file:Main.java
/** * Removes the duplicates by modifying the source list and keeping the order of the elements. * * @param <T>//from w w w .j a v a 2 s . c o m * the generic type * @param list * the list * @return the same object as the argument */ public static <T> List<T> removeDuplicates(List<T> list) { Set<T> temp = createLinkedHashSet(list.size()); temp.addAll(list); list.clear(); list.addAll(temp); return list; }
From source file:Main.java
/** * Given a list of elements of type <T>, remove the duplicates from the list in place * /*from w ww . j a v a 2 s . c o m*/ * @param <T> * @param list */ public static <T> void removeDuplicates(List<T> list) { // uses LinkedHashSet to keep the order Set<T> set = new LinkedHashSet<T>(list); list.clear(); list.addAll(set); if (list instanceof ArrayList) { ((ArrayList<T>) list).trimToSize(); } }
From source file:Main.java
public static void fillLeftList(String[] pairsList, List<String> namesList, ArrayAdapter<String> adapter) { String[] names;/* ww w . jav a2 s . co m*/ if (pairsList.length != 0) { namesList.clear(); for (String s : pairsList) { names = s.split("-"); if (!namesList.contains(names[0])) { namesList.add(names[0]); } } if (adapter != null) { adapter.notifyDataSetChanged(); } } }
From source file:Main.java
public static long populate(List list, int size) { long start, stop, result = 0; for (int j = 0; j < 100; j++) { list.clear(); start = System.nanoTime(); for (int i = 0; i < size; i++) { list.add(i);/* ww w . jav a 2 s. c o m*/ } stop = System.nanoTime(); result += stop - start; } return result / 100; }
From source file:com.github.terma.m.server.Repo.java
private static void batchAdd(FastSelect<Event> fastSelect, List<Event> events) { fastSelect.addAll(events);/* w w w. ja v a 2 s.co m*/ events.clear(); }
From source file:Main.java
public static <T> List<T> mergeLists(List<T> oldList, List<T> newList) { //TreeSet setBoth = new TreeSet(newList); HashSet<T> setBoth = new HashSet<>(newList); setBoth.addAll(oldList);//from w ww . j ava 2 s . c o m oldList.clear(); oldList.addAll(setBoth); return oldList; }
From source file:edu.uci.ics.hyracks.algebricks.rewriter.rules.PushSelectDownRule.java
private static boolean propagateSelectionRec(Mutable<ILogicalOperator> sigmaRef, Mutable<ILogicalOperator> opRef2) throws AlgebricksException { AbstractLogicalOperator op2 = (AbstractLogicalOperator) opRef2.getValue(); if (op2.getInputs().size() != 1 || op2.getOperatorTag() == LogicalOperatorTag.DATASOURCESCAN) { return false; }/*ww w . j a v a 2 s . co m*/ SelectOperator sigma = (SelectOperator) sigmaRef.getValue(); LinkedList<LogicalVariable> usedInSigma = new LinkedList<LogicalVariable>(); sigma.getCondition().getValue().getUsedVariables(usedInSigma); LinkedList<LogicalVariable> produced2 = new LinkedList<LogicalVariable>(); VariableUtilities.getProducedVariables(op2, produced2); if (OperatorPropertiesUtil.disjoint(produced2, usedInSigma)) { // just swap opRef2.setValue(sigma); sigmaRef.setValue(op2); List<Mutable<ILogicalOperator>> sigmaInpList = sigma.getInputs(); sigmaInpList.clear(); sigmaInpList.addAll(op2.getInputs()); List<Mutable<ILogicalOperator>> op2InpList = op2.getInputs(); op2InpList.clear(); op2InpList.add(opRef2); propagateSelectionRec(opRef2, sigma.getInputs().get(0)); return true; } return false; }