List of usage examples for java.util List clear
void clear();
From source file:io.druid.benchmark.datagen.SegmentGenerator.java
public QueryableIndex generate(final DataSegment dataSegment, final BenchmarkSchemaInfo schemaInfo, final int numRows) { // In case we need to generate hyperUniques. if (ComplexMetrics.getSerdeForType("hyperUnique") == null) { ComplexMetrics.registerSerde("hyperUnique", new HyperUniquesSerde(HyperLogLogHash.getDefault())); }/*from w w w. java2s. co m*/ final BenchmarkDataGenerator dataGenerator = new BenchmarkDataGenerator(schemaInfo.getColumnSchemas(), seed.getAndIncrement(), schemaInfo.getDataInterval(), numRows); final List<DimensionSchema> dimensions = new ArrayList<>(); for (BenchmarkColumnSchema columnSchema : schemaInfo.getColumnSchemas()) { if (schemaInfo.getAggs().stream().noneMatch(agg -> agg.getName().equals(columnSchema.getName()))) { switch (columnSchema.getType()) { case STRING: dimensions.add(new StringDimensionSchema(columnSchema.getName())); break; case LONG: dimensions.add(new LongDimensionSchema(columnSchema.getName())); break; case FLOAT: dimensions.add(new FloatDimensionSchema(columnSchema.getName())); break; default: throw new ISE("Unhandleable type[%s]", columnSchema.getType()); } } } final IncrementalIndexSchema indexSchema = new IncrementalIndexSchema.Builder() .withDimensionsSpec(new DimensionsSpec(dimensions, ImmutableList.of(), ImmutableList.of())) .withMetrics(schemaInfo.getAggsArray()).withRollup(schemaInfo.isWithRollup()).build(); final List<InputRow> rows = new ArrayList<>(); final List<QueryableIndex> indexes = new ArrayList<>(); for (int i = 0; i < numRows; i++) { final InputRow row = dataGenerator.nextRow(); rows.add(row); if ((i + 1) % 20000 == 0) { log.info("%,d/%,d rows generated.", i + 1, numRows); } if (rows.size() % MAX_ROWS_IN_MEMORY == 0) { indexes.add(makeIndex(dataSegment.getIdentifier(), indexes.size(), rows, indexSchema)); rows.clear(); } } log.info("%,d/%,d rows generated.", numRows, numRows); if (rows.size() > 0) { indexes.add(makeIndex(dataSegment.getIdentifier(), indexes.size(), rows, indexSchema)); rows.clear(); } if (indexes.isEmpty()) { throw new ISE("No rows to index?"); } else if (indexes.size() == 1) { return Iterables.getOnlyElement(indexes); } else { try { final QueryableIndex merged = TestHelper.getTestIndexIO() .loadIndex(TestHelper.getTestIndexMergerV9().merge( indexes.stream().map(QueryableIndexIndexableAdapter::new) .collect(Collectors.toList()), false, schemaInfo.getAggs().stream().map(AggregatorFactory::getCombiningFactory) .toArray(AggregatorFactory[]::new), new File(tempDir, "merged"), new IndexSpec())); for (QueryableIndex index : indexes) { index.close(); } return merged; } catch (IOException e) { throw Throwables.propagate(e); } } }
From source file:info.magnolia.templating.inheritance.DefaultInheritanceContentDecoratorTest.java
private Map<String, String> loadSessionConfigs(String resourceSuffix) throws IOException { InputStream stream = getClass() .getResourceAsStream(getClass().getSimpleName() + "_" + resourceSuffix + ".txt"); List<String> lines = IOUtils.readLines(stream); HashMap<String, String> sections = new HashMap<String, String>(); String sectionName = null;// ww w.j av a 2 s.co m List<String> sectionLines = new ArrayList<String>(); for (String line : lines) { if (line.equals("")) { continue; } if (line.startsWith("#")) { continue; } if (line.startsWith("[")) { if (sectionName != null) { sections.put(sectionName, StringUtils.join(sectionLines, "\n")); } sectionName = StringUtils.substringBetween(line, "[", "]"); sectionLines.clear(); continue; } sectionLines.add(line); } if (sectionName != null) { sections.put(sectionName, StringUtils.join(sectionLines, "\n")); } return sections; }
From source file:de.teamgrit.grit.checking.compile.JavaCompileChecker.java
/** * Invokes the compiler on a given file and reports the output. * * @param pathToSourceFolder/*w w w .jav a 2 s .com*/ * Specifies the folder where source files are located. * @param outputFolder * Directory where the resulting binaries are placed * @param compilerName * The compiler to be used (usually javac). * @param compilerFlags * Additional flags to be passed to the compiler. * @throws FileNotFoundException * Is thrown when the file in pathToProgramFile cannot be * opened * @throws BadCompilerSpecifiedException * Is thrown when the given compiler cannot be called * @return A {@link CompilerOutput} that contains all compiler messages and * flags on how the compile run went. * @throws BadFlagException * When javac doesn't recognize a flag, this exception is * thrown. * @throws CompilerOutputFolderExistsException * The output folder may not exist. This is thrown when it does * exist. */ @Override public CompilerOutput checkProgram(Path pathToSourceFolder, Path outputFolder, String compilerName, List<String> compilerFlags) throws FileNotFoundException, BadCompilerSpecifiedException, BadFlagException, CompilerOutputFolderExistsException { // First we build the command to invoke the compiler. This consists of // the compiler executable, the path of the // file to compile and compiler flags. List<String> compilerInvocation = createCompilerInvocation(pathToSourceFolder, outputFolder, compilerName, compilerFlags); // Now we build a launchable process from the given parameters and set // the working directory. CompilerOutput result = runJavacProcess(compilerInvocation, pathToSourceFolder, false); compilerInvocation.clear(); compilerInvocation.add("javac"); compilerInvocation.add("-cp"); // Add testDependencies to classpath String cp = ".:" + m_junitLocation + ":" + outputFolder.toAbsolutePath(); // Add all additional .jar files contained in javalib directory to the classpath if (!m_libLocation.toFile().exists()) { m_libLocation.toFile().mkdir(); } else { for (File f : FileUtils.listFiles(m_libLocation.toFile(), new String[] { "jar" }, false)) { cp = cp + ":" + f.getAbsolutePath(); } } compilerInvocation.add(cp); //make sure java uses utf8 for encoding compilerInvocation.add("-encoding"); compilerInvocation.add("UTF-8"); compilerInvocation.add("-d"); compilerInvocation.add(m_junitTestFilesLocation.toAbsolutePath().toString()); List<Path> foundUnitTests = exploreDirectory(m_junitTestFilesLocation); for (Path path : foundUnitTests) { compilerInvocation.add(path.toAbsolutePath().toString()); } runJavacProcess(compilerInvocation, m_junitTestFilesLocation, true); return result; }
From source file:model.Modele.java
/** * Methode qui sauvegarde les donnes dans des objets (RAM) * * @param file le fichier sauvegarder/* w ww. ja va 2 s . c o m*/ * @return le nom de fichier pour l'afficher sur la rubrique des donnes */ public String Save_data(File file) { String last_last_1 = null; String last_last_2 = null; try (BufferedReader br = new BufferedReader(new FileReader(file))) { final String fileName = file.toURI().toString(); String fileNamelast = null; String[] fileNames = fileName.toString().split("/"); String last_part = fileNames[7]; String[] parts = last_part.split("\\."); String last_last_part = parts[1]; last_last_1 = last_last_part.substring(0, 4); last_last_2 = last_last_part.substring(4, 6); List<String> row = new ArrayList<>(); String line; donnes = new ArrayList<>(); boolean line_one = false; double val_proggress = 0.0; while ((line = br.readLine()) != null) { if (line_one) { row.clear(); donnes.add(line); int i = 0; for (String retval : line.split(";")) { if (i == 0 || i == 1 || i == 7 || i == 9 || i == 14) { row.add(retval); } i++; } if (row.size() == 5) { String c; if (!row.get(2).equals("mq")) { Float kelvin = Float.parseFloat(row.get(2)); Float celsius = kelvin - 273.15F; c = Float.toString(celsius); } else { c = "0"; } //conversion des erreurs : if (row.get(0).equals("mq")) { row.set(0, "0"); } if (row.get(1).equals("mq")) { row.set(1, "0"); } if (row.get(2).equals("mq")) { row.set(2, "0"); } if (row.get(3).equals("mq")) { row.set(3, "0"); } if (row.get(4).equals("mq")) { row.set(4, "0"); } add_or_create(row, c); } } line_one = true; } } catch (IOException ex) { Logger.getLogger(Controller.class.getName()).log(Level.SEVERE, null, ex); } list_donnee.add("DATA existe, Date : " + last_last_1 + " - " + last_last_2); return "DATA existe, Date : " + last_last_1 + " - " + last_last_2; }
From source file:io.cloudslang.engine.queue.services.cleaner.QueueCleanerServiceTest.java
@Test public void cleanTest() throws Exception { List<ExecutionMessage> msgs = new ArrayList<>(); ExecutionMessage message15 = generateMessage(1, "group1", "1", ExecStatus.IN_PROGRESS, 1); ExecutionMessage message16 = generateMessage(1, "group1", "1", ExecStatus.FINISHED, 2); ExecutionMessage message25 = generateMessage(2, "group1", "2", ExecStatus.IN_PROGRESS, 1); ExecutionMessage message26 = generateMessage(2, "group1", "2", ExecStatus.FINISHED, 2); when(busyWorkersService.isWorkerBusy("myWorker")).thenReturn(true); msgs.clear(); msgs.add(message15);//from www . ja v a2 s. c om executionQueueService.enqueue(msgs); Set<Long> ids = queueCleanerService.getFinishedExecStateIds(); Assert.assertEquals(0, ids.size()); msgs.clear(); msgs.add(message16); executionQueueService.enqueue(msgs); executionQueueService.pollRecovery("myWorker", 100, ExecStatus.IN_PROGRESS, ExecStatus.FINISHED); ids = queueCleanerService.getFinishedExecStateIds(); Assert.assertEquals(1, ids.size()); msgs.clear(); msgs.add(message26); executionQueueService.enqueue(msgs); ids = queueCleanerService.getFinishedExecStateIds(); Assert.assertEquals(2, ids.size()); msgs.clear(); msgs.add(message25); executionQueueService.enqueue(msgs); ids = queueCleanerService.getFinishedExecStateIds(); Assert.assertEquals(2, ids.size()); queueCleanerService.cleanFinishedSteps(ids); ids = queueCleanerService.getFinishedExecStateIds(); Assert.assertEquals(0, ids.size()); }
From source file:edu.uci.ics.hyracks.algebricks.rewriter.rules.ExtractCommonOperatorsRule.java
private boolean rewriteForOneEquivalentClass(List<Mutable<ILogicalOperator>> members, IOptimizationContext context) throws AlgebricksException { List<Mutable<ILogicalOperator>> group = new ArrayList<Mutable<ILogicalOperator>>(); boolean rewritten = false; while (members.size() > 0) { group.clear(); Mutable<ILogicalOperator> candidate = members.remove(members.size() - 1); group.add(candidate);/* w w w.ja v a2 s . c o m*/ for (int i = members.size() - 1; i >= 0; i--) { Mutable<ILogicalOperator> peer = members.get(i); if (IsomorphismUtilities.isOperatorIsomorphic(candidate.getValue(), peer.getValue())) { group.add(peer); members.remove(i); } } boolean[] materializationFlags = computeMaterilizationFlags(group); if (group.isEmpty()) { continue; } candidate = group.get(0); ReplicateOperator rop = new ReplicateOperator(group.size(), materializationFlags); rop.setPhysicalOperator(new ReplicatePOperator()); rop.setExecutionMode(ExecutionMode.PARTITIONED); Mutable<ILogicalOperator> ropRef = new MutableObject<ILogicalOperator>(rop); AbstractLogicalOperator aopCandidate = (AbstractLogicalOperator) candidate.getValue(); List<Mutable<ILogicalOperator>> originalCandidateParents = childrenToParents.get(candidate); if (aopCandidate.getOperatorTag() == LogicalOperatorTag.EXCHANGE) { rop.getInputs().add(candidate); } else { AbstractLogicalOperator beforeExchange = new ExchangeOperator(); beforeExchange.setPhysicalOperator(new OneToOneExchangePOperator()); Mutable<ILogicalOperator> beforeExchangeRef = new MutableObject<ILogicalOperator>(beforeExchange); beforeExchange.getInputs().add(candidate); context.computeAndSetTypeEnvironmentForOperator(beforeExchange); rop.getInputs().add(beforeExchangeRef); } context.computeAndSetTypeEnvironmentForOperator(rop); for (Mutable<ILogicalOperator> parentRef : originalCandidateParents) { AbstractLogicalOperator parent = (AbstractLogicalOperator) parentRef.getValue(); int index = parent.getInputs().indexOf(candidate); if (parent.getOperatorTag() == LogicalOperatorTag.EXCHANGE) { parent.getInputs().set(index, ropRef); rop.getOutputs().add(parentRef); } else { AbstractLogicalOperator exchange = new ExchangeOperator(); exchange.setPhysicalOperator(new OneToOneExchangePOperator()); MutableObject<ILogicalOperator> exchangeRef = new MutableObject<ILogicalOperator>(exchange); exchange.getInputs().add(ropRef); rop.getOutputs().add(exchangeRef); context.computeAndSetTypeEnvironmentForOperator(exchange); parent.getInputs().set(index, exchangeRef); context.computeAndSetTypeEnvironmentForOperator(parent); } } List<LogicalVariable> liveVarsNew = new ArrayList<LogicalVariable>(); VariableUtilities.getLiveVariables(candidate.getValue(), liveVarsNew); ArrayList<Mutable<ILogicalExpression>> assignExprs = new ArrayList<Mutable<ILogicalExpression>>(); for (LogicalVariable liveVar : liveVarsNew) assignExprs.add(new MutableObject<ILogicalExpression>(new VariableReferenceExpression(liveVar))); for (Mutable<ILogicalOperator> ref : group) { if (ref.equals(candidate)) continue; ArrayList<LogicalVariable> liveVars = new ArrayList<LogicalVariable>(); Map<LogicalVariable, LogicalVariable> variableMappingBack = new HashMap<LogicalVariable, LogicalVariable>(); IsomorphismUtilities.mapVariablesTopDown(ref.getValue(), candidate.getValue(), variableMappingBack); for (int i = 0; i < liveVarsNew.size(); i++) { liveVars.add(variableMappingBack.get(liveVarsNew.get(i))); } AbstractLogicalOperator assignOperator = new AssignOperator(liveVars, assignExprs); assignOperator.setPhysicalOperator(new AssignPOperator()); AbstractLogicalOperator projectOperator = new ProjectOperator(liveVars); projectOperator.setPhysicalOperator(new StreamProjectPOperator()); AbstractLogicalOperator exchOp = new ExchangeOperator(); exchOp.setPhysicalOperator(new OneToOneExchangePOperator()); exchOp.getInputs().add(ropRef); MutableObject<ILogicalOperator> exchOpRef = new MutableObject<ILogicalOperator>(exchOp); rop.getOutputs().add(exchOpRef); assignOperator.getInputs().add(exchOpRef); projectOperator.getInputs().add(new MutableObject<ILogicalOperator>(assignOperator)); // set the types context.computeAndSetTypeEnvironmentForOperator(exchOp); context.computeAndSetTypeEnvironmentForOperator(assignOperator); context.computeAndSetTypeEnvironmentForOperator(projectOperator); List<Mutable<ILogicalOperator>> parentOpList = childrenToParents.get(ref); for (Mutable<ILogicalOperator> parentOpRef : parentOpList) { AbstractLogicalOperator parentOp = (AbstractLogicalOperator) parentOpRef.getValue(); int index = parentOp.getInputs().indexOf(ref); if (parentOp.getOperatorTag() == LogicalOperatorTag.EXCHANGE) { AbstractLogicalOperator parentOpNext = (AbstractLogicalOperator) childrenToParents .get(parentOpRef).get(0).getValue(); if (parentOpNext.isMap()) { index = parentOpNext.getInputs().indexOf(parentOpRef); parentOp = parentOpNext; } } ILogicalOperator childOp = parentOp.getOperatorTag() == LogicalOperatorTag.PROJECT ? assignOperator : projectOperator; if (parentOp.isMap()) { parentOp.getInputs().set(index, new MutableObject<ILogicalOperator>(childOp)); } else { AbstractLogicalOperator exchg = new ExchangeOperator(); exchg.setPhysicalOperator(new OneToOneExchangePOperator()); exchg.getInputs().add(new MutableObject<ILogicalOperator>(childOp)); parentOp.getInputs().set(index, new MutableObject<ILogicalOperator>(exchg)); context.computeAndSetTypeEnvironmentForOperator(exchg); } context.computeAndSetTypeEnvironmentForOperator(parentOp); } } rewritten = true; } return rewritten; }
From source file:com.shaie.solr.SplitShardTest.java
private void indexDocs(int numDocs) throws SolrServerException, IOException { final List<SolrInputDocument> docs = Lists.newArrayList(); for (int i = 0; i < numDocs; i++) { final SolrInputDocument doc = new SolrInputDocument(); doc.setField("id", "doc-" + i); doc.setField("body_t", generateRandomBody(random)); docs.add(doc);//from w ww . j a va 2s .c o m if (i > 0 && (i % 100) == 0) { System.out.println("Indexed " + i + " docs."); final UpdateResponse addDocsResponse = solrClient.add(COLLECTION_NAME, docs); assertThat(addDocsResponse.getStatus()).isEqualTo(0); docs.clear(); } } System.out.println("Indexed " + numDocs + " docs."); final UpdateResponse addDocsResponse = solrClient.add(COLLECTION_NAME, docs); assertThat(addDocsResponse.getStatus()).isEqualTo(0); System.out.println("Committing..."); final UpdateResponse commitResponse = solrClient.commit(COLLECTION_NAME, true, true); assertThat(commitResponse.getStatus()).isEqualTo(0); }
From source file:com.genentech.struchk.oeStruchk.OEStruchk.java
/** * Command line interface to {@link OEStruchk}. */// w w w . ja v a2s . com public static void main2(String[] args) throws ParseException { long start = System.currentTimeMillis(); int nMessages = 0; int nErrors = 0; int nStruct = 0; // create command line Options object Options options = new Options(); Option opt = new Option("f", true, "specify the configuration file name"); opt.setRequired(true); options.addOption(opt); CommandLineParser parser = new PosixParser(); CommandLine cmd = parser.parse(options, args); args = cmd.getArgs(); if (args.length < 1) { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("oeStruck", options); throw new Error("missing input file\n"); } String confFile = cmd.getOptionValue("f"); try { oemolistream ifs = new oemolistream(args[0]); oemolostream ofs = new oemolostream(args[1]); // create OEStruchk from config file OEStruchk strchk = new OEStruchk(new File(confFile).toURI().toURL(), CHECKConfig.TESTAssignStuctFlag, false); OEGraphMol mol = new OEGraphMol(); while (oechem.OEReadMolecule(ifs, mol)) { if (!strchk.applyRules(mol, null)) nErrors++; OEGraphMol outMol = strchk.getTransformedMol(null); List<Message> msgs = strchk.getStructureMessages(null); if (msgs.size() > 0) { nMessages += msgs.size(); StringBuilder sb = new StringBuilder(); for (Message msg : msgs) sb.append(String.format("%s: %s\n", msg.getLevel(), msg.getText())); oechem.OESetSDData(outMol, "errors_oe2", sb.toString()); } oechem.OESetSDData(outMol, "ISM", strchk.getTransformedIsoSmiles(null)); oechem.OESetSDData(outMol, "SMI", strchk.getTransformedSmiles(null)); oechem.OEWriteMolecule(ofs, outMol); msgs.clear(); } ofs.close(); ofs.delete(); ifs.close(); ifs.delete(); } catch (Exception e) { throw new Error(e); } finally { System.err.printf("Checked %d structures %d errors, %d messages in %dsec\n", nStruct, nErrors, nMessages, (System.currentTimeMillis() - start) / 1000); } }
From source file:com.thesmartweb.swebrank.DataManipulation.java
/** * Method that clears a List from duplicates and null elements * @param wordList It contains the List to be cleared * @return a List cleared from duplicates and null elements *//*from w ww. j av a 2 s.c o m*/ public List<String> clearListString(List<String> wordList) { //remove all null elements of the wordlist wordList.removeAll(Collections.singleton(null)); //remove the duplicate elements since HashSet does not allow duplicates HashSet<String> hashSet_wordList = new HashSet<String>(wordList); //create an iterator to the hashset to add the elements back to the wordlist Iterator wordList_iterator = hashSet_wordList.iterator(); //clear the wordlist wordList.clear(); while (wordList_iterator.hasNext()) { wordList.add(wordList_iterator.next().toString()); } return wordList; }
From source file:eu.europa.esig.dss.tsl.TrustedListsCertificateSource.java
private XMLDocumentValidator prepareSignatureValidation(final List<CertificateToken> signingCertList, final byte[] bytes) { final CommonTrustedCertificateSource commonTrustedCertificateSource = new CommonTrustedCertificateSource(); for (final CertificateToken x509Certificate : signingCertList) { commonTrustedCertificateSource.addCertificate(x509Certificate); }/*from ww w . ja va2s. c o m*/ final CertificateVerifier certificateVerifier = new CommonCertificateVerifier(true); certificateVerifier.setTrustedCertSource(commonTrustedCertificateSource); final DSSDocument dssDocument = new InMemoryDocument(bytes); final XMLDocumentValidator xmlDocumentValidator = new XMLDocumentValidator(dssDocument); xmlDocumentValidator.setCertificateVerifier(certificateVerifier); // To increase the security: the default {@code XPathQueryHolder} is used. final List<XPathQueryHolder> xPathQueryHolders = xmlDocumentValidator.getXPathQueryHolder(); xPathQueryHolders.clear(); final XPathQueryHolder xPathQueryHolder = new XPathQueryHolder(); xPathQueryHolders.add(xPathQueryHolder); return xmlDocumentValidator; }