List of usage examples for java.util List clear
void clear();
From source file:Main.java
/** * Return a List containing all the elements of the specified Iterable that compare as being * equal to the maximum element./*www . j a v a2s .c o m*/ * * @throws NoSuchElementException if the Iterable is empty. */ public static <T> List<T> maxList(Iterable<T> iterable, Comparator<? super T> comp) { Iterator<T> itr = iterable.iterator(); T max = itr.next(); List<T> maxes = new ArrayList<T>(); maxes.add(max); if (itr.hasNext()) { do { T elem = itr.next(); int cmp = comp.compare(max, elem); if (cmp <= 0) { if (cmp < 0) { max = elem; maxes.clear(); } maxes.add(elem); } } while (itr.hasNext()); } else if (0 != comp.compare(max, max)) { // The main point of this test is to compare the sole element to something, // in case it turns out to be incompatible with the Comparator for some reason. // In that case, we don't even get to this IAE, we've probably already bombed out // with an NPE or CCE. For example, the Comparable version could be called with // a sole element of null. (Collections.max() gets this wrong.) throw new IllegalArgumentException(); } return maxes; }
From source file:com.taobao.tddl.jdbc.group.util.ExceptionUtils.java
/** * sqlException error loglog,/* w w w .j a v a 2s.c o m*/ * * list * * @param logger * @param message * @param sqlExceptions */ public static void printSQLExceptionToErrorLog(Log logger, String message, List<SQLException> sqlExceptions) { if (sqlExceptions != null && !sqlExceptions.isEmpty()) { for (SQLException sqlException : sqlExceptions) { logger.error(message, sqlException); } sqlExceptions.clear(); } }
From source file:com.chiorichan.util.StringUtil.java
/** * Scans a string list for entries that are not lower case. * //from w w w. java2s . c o m * @param stringList * The original list to check. * @return The corrected string list. */ public static List<String> toLowerCase(List<String> stringList) { String[] array = toLowerCase(stringList.toArray(new String[0])); try { stringList.clear(); } catch (UnsupportedOperationException e) { // In this case we can't preserve the original list type. stringList = Lists.newArrayList(); } for (String s : array) stringList.add(s); return stringList; }
From source file:edu.uci.ics.asterix.optimizer.rules.LoadRecordFieldsRule.java
/** * Pushes one field-access assignment above toPushThroughChildRef * /*from ww w . ja va 2s .c o m*/ * @param toPush * @param toPushThroughChildRef */ private static void pushAccessAboveOpRef(AssignOperator toPush, Mutable<ILogicalOperator> toPushThroughChildRef, IOptimizationContext context) throws AlgebricksException { List<Mutable<ILogicalOperator>> tpInpList = toPush.getInputs(); tpInpList.clear(); tpInpList.add(new MutableObject<ILogicalOperator>(toPushThroughChildRef.getValue())); toPushThroughChildRef.setValue(toPush); findAndEliminateRedundantFieldAccess(toPush); }
From source file:gov.nih.nci.ncicb.tcga.dcc.common.util.BeanToTextExporter.java
public static String beanListToText(final String type, final Writer out, final Map<String, String> columns, final List data, final DateFormat dateFormat) { CSVWriter writer = new CSVWriter(out); if ("tab".equals(type)) { writer = new CSVWriter(out, '\t', CSVWriter.NO_QUOTE_CHARACTER); }//from w w w .j a va 2 s .com List<String> cols = new LinkedList<String>(); try { //Writing the column headers for (Map.Entry<String, String> e : columns.entrySet()) { cols.add(e.getValue()); } writer.writeNext((String[]) cols.toArray(new String[columns.size()])); cols.clear(); //Writing the data if (data != null) { for (Object o : data) { for (Map.Entry<String, String> e : columns.entrySet()) { final Object obj = getAndInvokeGetter(o, e.getKey()); String value = getExportString(obj, dateFormat); if ("tab".equals(type)) { value = value.replace("\t", " "); } cols.add(value); } writer.writeNext((String[]) cols.toArray(new String[columns.size()])); cols.clear(); } } writer.close(); out.flush(); out.close(); } catch (Exception e) { logger.debug(FancyExceptionLogger.printException(e)); return "An error occurred."; } return out.toString(); }
From source file:Main.java
public static void sortFileByDate(List<File> allFileList) { File[] files = new File[allFileList.size()]; for (int i = 0; i < allFileList.size(); i++) { files[i] = allFileList.get(i);/* ww w.ja va 2 s .co m*/ } Arrays.sort(files, new Comparator<File>() { public int compare(File f1, File f2) { return Long.valueOf(f1.lastModified()).compareTo(f2.lastModified()); } }); allFileList.clear(); allFileList.addAll(Arrays.asList(files)); }
From source file:edu.uci.ics.asterix.optimizer.rules.LoadRecordFieldsRule.java
private static void pushFieldAssign(AssignOperator a2, AbstractLogicalOperator topOp, IOptimizationContext context) throws AlgebricksException { if (topOp.getInputs().size() == 1 && !topOp.hasNestedPlans()) { Mutable<ILogicalOperator> topChild = topOp.getInputs().get(0); // plugAccessAboveOp(a2, topChild, context); List<Mutable<ILogicalOperator>> a2InptList = a2.getInputs(); a2InptList.clear(); a2InptList.add(topChild);//from ww w . j a va 2s. c om // and link it as child in the op. tree topOp.getInputs().set(0, new MutableObject<ILogicalOperator>(a2)); findAndEliminateRedundantFieldAccess(a2); } else { // e.g., a join LinkedList<LogicalVariable> usedInAccess = new LinkedList<LogicalVariable>(); VariableUtilities.getUsedVariables(a2, usedInAccess); LinkedList<LogicalVariable> produced2 = new LinkedList<LogicalVariable>(); VariableUtilities.getProducedVariables(topOp, produced2); if (OperatorPropertiesUtil.disjoint(produced2, usedInAccess)) { for (Mutable<ILogicalOperator> inp : topOp.getInputs()) { HashSet<LogicalVariable> v2 = new HashSet<LogicalVariable>(); VariableUtilities.getLiveVariables(inp.getValue(), v2); if (!OperatorPropertiesUtil.disjoint(usedInAccess, v2)) { pushAccessAboveOpRef(a2, inp, context); return; } } if (topOp.hasNestedPlans()) { AbstractOperatorWithNestedPlans nestedOp = (AbstractOperatorWithNestedPlans) topOp; for (ILogicalPlan plan : nestedOp.getNestedPlans()) { for (Mutable<ILogicalOperator> root : plan.getRoots()) { HashSet<LogicalVariable> v2 = new HashSet<LogicalVariable>(); VariableUtilities.getLiveVariables(root.getValue(), v2); if (!OperatorPropertiesUtil.disjoint(usedInAccess, v2)) { pushAccessAboveOpRef(a2, root, context); return; } } } } throw new AsterixRuntimeException("Field access " + getFirstExpr(a2) + " does not correspond to any input of operator " + topOp); } } }
From source file:com.strider.datadefender.FileDiscoverer.java
private static List<FileMatchMetaData> uniqueList(List<FileMatchMetaData> finalList) { HashSet hs = new HashSet(); hs.addAll(finalList);/* ww w . j a v a 2s . c om*/ finalList.clear(); finalList.addAll(hs); return finalList; }
From source file:net.tirasa.ilgrosso.resetdb.Main.java
private static void resetMySQL(final Connection conn) throws Exception { final Statement statement = conn.createStatement(); ResultSet resultSet = statement .executeQuery("SELECT concat('DROP VIEW IF EXISTS ', table_name, ' CASCADE;')" + "FROM information_schema.views;"); final List<String> drops = new ArrayList<String>(); while (resultSet.next()) { drops.add(resultSet.getString(1)); }/*from w w w . ja v a 2s . c om*/ resultSet.close(); for (String drop : drops) { statement.executeUpdate(drop.substring(0, drop.length() - 1)); } drops.clear(); drops.add("SET FOREIGN_KEY_CHECKS = 0;"); resultSet = statement.executeQuery("SELECT concat('DROP TABLE IF EXISTS ', table_name, ' CASCADE;')" + "FROM information_schema.tables;"); while (resultSet.next()) { drops.add(resultSet.getString(1)); } resultSet.close(); drops.add("SET FOREIGN_KEY_CHECKS = 1;"); for (String drop : drops) { statement.executeUpdate(drop.substring(0, drop.length() - 1)); } statement.close(); conn.close(); }
From source file:edu.illinois.enforcemop.examples.apache.pool.TestObjectPool.java
private static void clear(final MethodCallPoolableObjectFactory factory, final List expectedMethods) { factory.getMethodCalls().clear();/*from w w w .j a v a 2 s . co m*/ expectedMethods.clear(); }