List of usage examples for java.util List size
int size();
From source file:jena.RuleMap.java
/** * General command line utility to process one RDF file into another * by application of a set of forward chaining rules. * <pre>// w w w . jav a 2s .c o m * Usage: RuleMap [-il inlang] [-ol outlang] -d infile rulefile * </pre> */ public static void main(String[] args) { try { // Parse the command line String usage = "Usage: RuleMap [-il inlang] [-ol outlang] [-d] rulefile infile (- for stdin)"; final CommandLineParser parser = new DefaultParser(); Options options = new Options().addOption("il", "inputLang", true, "input language") .addOption("ol", "outputLang", true, "output language").addOption("d", "Deductions only?"); CommandLine cl = parser.parse(options, args); final List<String> filenameArgs = cl.getArgList(); if (filenameArgs.size() != 2) { System.err.println(usage); System.exit(1); } String inLang = cl.getOptionValue("inputLang"); String fname = filenameArgs.get(1); Model inModel = null; if (fname.equals("-")) { inModel = ModelFactory.createDefaultModel(); inModel.read(System.in, null, inLang); } else { inModel = FileManager.get().loadModel(fname, inLang); } String outLang = cl.hasOption("outputLang") ? cl.getOptionValue("outputLang") : "N3"; boolean deductionsOnly = cl.hasOption('d'); // Fetch the rule set and create the reasoner BuiltinRegistry.theRegistry.register(new Deduce()); Map<String, String> prefixes = new HashMap<>(); List<Rule> rules = loadRules(filenameArgs.get(0), prefixes); Reasoner reasoner = new GenericRuleReasoner(rules); // Process InfModel infModel = ModelFactory.createInfModel(reasoner, inModel); infModel.prepare(); infModel.setNsPrefixes(prefixes); // Output try (PrintWriter writer = new PrintWriter(System.out)) { if (deductionsOnly) { Model deductions = infModel.getDeductionsModel(); deductions.setNsPrefixes(prefixes); deductions.setNsPrefixes(inModel); deductions.write(writer, outLang); } else { infModel.write(writer, outLang); } } } catch (Throwable t) { System.err.println("An error occured: \n" + t); t.printStackTrace(); } }
From source file:elaborate.editor.backend.AnnotationMarkerScrubber.java
@SuppressWarnings("boxing") public static void main(String[] args) { StopWatch sw = new StopWatch(); sw.start();//ww w . j a va2 s. c om EntityManager entityManager = HibernateUtil.beginTransaction(); TranscriptionService ts = TranscriptionService.instance(); ts.setEntityManager(entityManager); try { List<Transcription> resultList = entityManager// . .createQuery("select t from Transcription t", Transcription.class)// .getResultList(); int size = resultList.size(); int n = 1; for (Transcription t : resultList) { Log.info("indexing transcription {} ({}/{} = {}%)", new Object[] { t.getId(), n, size, percentage(n, size) }); String bodyBefore = t.getBody(); ts.cleanupAnnotations(t); String bodyAfter = t.getBody(); if (!bodyAfter.equals(bodyBefore)) { ProjectEntry projectEntry = t.getProjectEntry(); String projectname = projectEntry.getProject().getName(); long entryId = projectEntry.getId(); Log.info("url: http://test.elaborate.huygens.knaw.nl/projects/{}/entries/{}/transcriptions/{}", projectname, entryId, t.getTextLayer()); Log.info("body changed:\nbefore: {}\nafter:{}", bodyBefore, bodyAfter); } n++; } } finally { HibernateUtil.commitTransaction(entityManager); } sw.stop(); Log.info("done in {}", convert(sw.getTime())); }
From source file:core.App.java
public static void main(String[] args) { // For XML/* w ww .j av a 2s. c om*/ //ApplicationContext ctx = new GenericXmlApplicationContext("SpringConfig.xml"); // For Annotation ApplicationContext ctx = new AnnotationConfigApplicationContext(SpringMongoConfig.class); MongoOperations mongoOperation = (MongoOperations) ctx.getBean("mongoTemplate"); //Student user = new Student("3", "federico", "solterman", "26-10-1990"); // save //mongoOperation.save(user); // now user object got the created id. // System.out.println("1. user : " + user); // query to search user // Query searchUserQuery = new Query(Criteria.where("first_name").is("federico")) { //}; // find the saved user again. //Student savedUser = mongoOperation.findOne(searchUserQuery, Student.class); // System.out.println("2. find - savedUser : " + savedUser); //This method Fetch all students whose notes in a specific course were greater than 4 BasicQuery query = new BasicQuery( "{ $and: [{ note_1: {$gt:4 }, note_2: {$gt:4}, note_3: {$gt:4},note_final:{$gt:4 } } ] }"); List<StudentXCourseXNote> stu = mongoOperation.find(query, StudentXCourseXNote.class); StudentXCourseXNote aux; for (int i = 0; i < stu.size(); i++) { aux = stu.get(i); BasicQuery query1 = new BasicQuery("{id_registration:" + " \"" + aux.getId_student() + "\"}"); Student student = mongoOperation.findOne(query1, Student.class); System.out.println(student.toString()); } //Fetch all courses ordered by name for a given teacher BasicQuery query2 = new BasicQuery("{ last_name:\"Sulma\" }"); Teacher teacher = mongoOperation.findOne(query2, Teacher.class); BasicQuery query3 = new BasicQuery("{ id_teacher: \"" + teacher.getId_teacher() + "\"}"); List<TeacherXCourse> list = mongoOperation.find(query3, TeacherXCourse.class); TeacherXCourse aux2; for (int j = 0; j < list.size(); j++) { aux2 = list.get(j); BasicQuery query4 = new BasicQuery("{id_course: \"" + aux2.getId_course() + "\" }"); Course course = mongoOperation.findOne(query4, Course.class); System.out.println(course.toString()); } //This method add a new fields in the collection course BasicQuery queryPoint4 = new BasicQuery("{ },{ $set: { finish: boolean } },{ multi: true }"); Update update = new Update(); update.set("{}", ""); mongoOperation.updateFirst(queryPoint4, null, Course.class); // update password /*mongoOperation.updateFirst(searchUserQuery, Update.update("password", "new password"), Student.class);*/ // find the updated user object /*Student updatedUser = mongoOperation.findOne(searchUserQuery, Student.class);*/ //System.out.println("3. updatedUser : " + updatedUser); // delete // mongoOperation.remove(searchUserQuery, Student.class); // List, it should be empty now. /* List<Student> listUser = mongoOperation.findAll(Student.class); System.out.println("4. Number of user = " + listUser.size());*/ }
From source file:it.units.malelab.sse.Main.java
public static void main(String[] args) throws IOException { Random random = new Random(1); VirtualMachine vm = new VirtualMachine(4, 4, 400); List<Map<Boolean, List<String>>> datasets = new ArrayList<>(); datasets.add(Util.loadStrings("/home/eric/Documenti/esperimenti/datasets/Bills-Date.txt", random)); datasets.add(Util.loadStrings("/home/eric/Documenti/esperimenti/datasets/Log-IP.txt", random)); datasets.add(Util.loadStrings("/home/eric/Documenti/esperimenti/datasets/Twitter-URL.txt", random)); Evaluator evaluator = new Evaluator(vm, datasets, 1, 10); MyGeneticAlgorithm ga = new MyGeneticAlgorithm(new OnePointCrossover<Integer>(), 0.2, new BinaryMutation(), 0.6, new TournamentSelection(10), evaluator); MyGeneticAlgorithm.setRandomGenerator(new JDKRandomGenerator(1)); List<Chromosome> chromosomes = new ArrayList<>(); for (int i = 0; i < 2000; i++) { chromosomes.add(new OperationsChromosome(evaluator)); }/*from w ww.j ava 2 s .c o m*/ Population population = new ElitisticListPopulation(chromosomes, chromosomes.size(), 0.99); Population finalPopulation = ga.evolve(population, new FixedGenerationCount(10000)); List<Operation> operations = ((OperationsChromosome) finalPopulation.getFittestChromosome()) .getOperations(); for (int i = 0; i < operations.size(); i++) { System.out.printf("%4d: %s\n", i, operations.get(i)); } }
From source file:com.khartec.waltz.jobs.AssetCostHarness.java
public static void main(String[] args) { AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(DIConfiguration.class); DSLContext dsl = ctx.getBean(DSLContext.class); AssetCostService service = ctx.getBean(AssetCostService.class); AssetCostStatsDao statsDao = ctx.getBean(AssetCostStatsDao.class); AssetCostDao costDao = ctx.getBean(AssetCostDao.class); ApplicationIdSelectorFactory selectorFactory = ctx.getBean(ApplicationIdSelectorFactory.class); long st = System.currentTimeMillis(); System.out.println("-- start"); IdSelectionOptions appIdSelectionOptions = ImmutableIdSelectionOptions.builder() .scope(HierarchyQueryScope.CHILDREN) .entityReference(ImmutableEntityReference.builder().id(5600).kind(EntityKind.CAPABILITY).build()) .build();//from w w w . java 2 s . c o m List<Tuple2<Long, BigDecimal>> costs = service.calculateCombinedAmountsForSelector(appIdSelectionOptions); System.out.println("-- end, dur: " + (System.currentTimeMillis() - st)); System.out.println(costs); System.out.println(costs.size()); }
From source file:com.jdom.word.playdough.model.gamepack.GamePackFileGenerator.java
/** * Usage: java GamePackFileGenerator <input file> <output directory> * /*from w ww .ja v a2s.c o m*/ * @param args * @throws IOException */ public static void main(String[] args) throws IOException { File dictionaryFile = new File(args[0]); // Validate arguments first if (!dictionaryFile.isFile()) { throw new IllegalArgumentException("The specified file does not seem to be a valid file [" + dictionaryFile.getAbsolutePath() + "]!"); } File outputDir = new File(args[1]); if (!outputDir.isDirectory()) { throw new IllegalArgumentException("The specified directory does not seem to be a valid directory [" + outputDir.getAbsolutePath() + "]!"); } Set<String> words = GamePackFileGenerator.readWordsFromDictionaryFile(dictionaryFile); GamePackFileGenerator generator = new GamePackFileGenerator(words); List<Properties> properties = generator.generateGamePacks(20); for (int i = 0; i < properties.size(); i++) { Properties current = properties.get(i); File outputFile = new File(outputDir, i + ".properties"); PropertiesUtil.writePropertiesFile(current, outputFile); } }
From source file:com.aerospike.examples.travel.FlighAggregation.java
public static void main(String[] args) throws AerospikeException { try {/*w w w.ja va2 s . co m*/ Options options = new Options(); options.addOption("h", "host", true, "Server hostname (default: 127.0.0.1)"); options.addOption("p", "port", true, "Server port (default: 3000)"); options.addOption("n", "namespace", true, "Namespace (default: test)"); options.addOption("s", "set", true, "Set (default: demo)"); options.addOption("u", "usage", false, "Print usage."); CommandLineParser parser = new PosixParser(); CommandLine cl = parser.parse(options, args, false); String host = cl.getOptionValue("h", "127.0.0.1"); String portString = cl.getOptionValue("p", "3000"); int port = Integer.parseInt(portString); String namespace = cl.getOptionValue("n", "test"); String set = cl.getOptionValue("s", "demo"); log.debug("Host: " + host); log.debug("Port: " + port); log.debug("Namespace: " + namespace); log.debug("Set: " + set); @SuppressWarnings("unchecked") List<String> cmds = cl.getArgList(); if (cmds.size() == 0 && cl.hasOption("u")) { logUsage(options); return; } FlighAggregation as = new FlighAggregation(host, port, namespace, set); as.init(); as.work(); } catch (Exception e) { log.error("Critical error", e); } }
From source file:is.landsbokasafn.deduplicator.indexer.IndexingLauncher.java
public static void main(String[] args) throws Exception { loadConfiguration();//w w w . j a va2 s . c o m // Set default values for all settings boolean verbose = readBooleanConfig(VERBOSE_CONF_KEY, true); boolean etag = readBooleanConfig(ETAG_CONF_KEY, false); boolean canonical = readBooleanConfig(CANONICAL_CONF_KEY, true); boolean indexURL = readBooleanConfig(INDEX_URL_KEY, true); boolean addToIndex = readBooleanConfig(ADD_TO_INDEX_CONF_KEY, false); String mimefilter = readStringConfig(MIME_CONF_KEY, "^text/.*"); boolean whitelist = readBooleanConfig(WHITELIST_CONF_KEY, false); String iteratorClassName = readStringConfig(ITERATOR_CONF_KEY, WarcIterator.class.getName()); // Parse command line options CommandLineParser clp = new CommandLineParser(args, new PrintWriter(System.out)); Option[] opts = clp.getCommandLineOptions(); for (int i = 0; i < opts.length; i++) { Option opt = opts[i]; switch (opt.getId()) { case 'w': whitelist = true; break; case 'a': addToIndex = true; break; case 'e': etag = true; break; case 'h': clp.usage(0); break; case 'i': iteratorClassName = opt.getValue(); break; case 'm': mimefilter = opt.getValue(); break; case 'u': indexURL = false; break; case 's': canonical = false; break; case 'v': verbose = true; break; } } if (!indexURL && canonical) { canonical = false; } List<String> cargs = clp.getCommandLineArguments(); if (cargs.size() != 2) { // Should be exactly two arguments. Source and target! clp.usage(0); } String source = cargs.get(0); String target = cargs.get(1); // Load the CrawlDataIterator CrawlDataIterator iterator = (CrawlDataIterator) Class.forName(iteratorClassName).newInstance(); // Print initial stuff System.out.println("Indexing: " + source); System.out.println(" - Index URL: " + indexURL); System.out.println(" - Mime filter: " + mimefilter + " (" + (whitelist ? "whitelist" : "blacklist") + ")"); System.out.println(" - Includes" + (canonical ? " <canonical URL>" : "") + (etag ? " <etag>" : "")); System.out.println(" - Iterator: " + iteratorClassName); System.out.println(" - " + iterator.getSourceType()); System.out.println("Target: " + target); if (addToIndex) { System.out.println(" - Add to existing index (if any)"); } else { System.out.println(" - New index (erases any existing index at " + "that location)"); } iterator.initialize(source); // Create the index long start = System.currentTimeMillis(); IndexBuilder di = new IndexBuilder(target, indexURL, canonical, etag, addToIndex); di.writeToIndex(iterator, mimefilter, !whitelist, verbose); // Clean-up di.close(); System.out.println("Total run time: " + DateUtils.formatMillisecondsToConventional(System.currentTimeMillis() - start)); }
From source file:Main.java
License:asdf
public static void main(String[] args) { int howManyWords = 2; List<String> listOfWords = new ArrayList<>(); Random random = new Random(); listOfWords.addAll(Arrays.asList(randomMessages)); List<String> selectedRandomMessages = new ArrayList<>(); for (int i = 0; i < howManyWords; i++) { int randomNumber = random.nextInt(listOfWords.size()); String randomItem = listOfWords.get(randomNumber); selectedRandomMessages.add(randomItem); listOfWords.remove(randomItem);//from w ww . jav a 2 s .co m } System.out.println(selectedRandomMessages); }
From source file:bs.java
public static void main(String[] args) throws FileNotFoundException { Options options = new Options(); options.addOption(help);/*from ww w. j a v a 2s . c om*/ options.addOption(version); options.addOption(loadPath); options.addOption(loadable); options.addOption(eval); // args = new String[] { "Reflection.bs" }; try { Bs.init(); CommandLineParser argParser = new PosixParser(); CommandLine line = argParser.parse(options, args); if (line.hasOption(HELP)) { help(options); } if (line.hasOption(VERSION)) { version(); } if (line.hasOption(LOAD_PATH)) { loadPath(line.getOptionValue(LOAD_PATH)); } if (line.hasOption(EVAL)) { eval(line.getOptionValue(EVAL)); } if (line.hasOption(LOADABLE)) { loadable(line.getOptionValue(LOADABLE)); } List<?> rest = line.getArgList(); if (rest.size() > 0) { eval(rest); } else { repl(); } } catch (ParseException e) { help(options); } }