List of usage examples for java.util List add
boolean add(E e);
From source file:com.netflix.genie.client.sample.ClusterServiceSampleClient.java
/** * Main for running client code./*from w w w. j a v a 2 s . com*/ * * @param args program arguments * @throws Exception On issue. */ public static void main(final String[] args) throws Exception { // Initialize Eureka, if it is being used // LOG.info("Initializing Eureka"); // ClusterServiceClient.initEureka("test"); LOG.info("Initializing list of Genie servers"); ConfigurationManager.getConfigInstance().setProperty("genie2Client.ribbon.listOfServers", "localhost:7001"); LOG.info("Initializing ApplicationServiceClient"); final ApplicationServiceClient appClient = ApplicationServiceClient.getInstance(); final Application app1 = appClient.createApplication( ApplicationServiceSampleClient.getSampleApplication(ApplicationServiceSampleClient.ID)); LOG.info("Created application:"); LOG.info(app1.toString()); final Application app2 = appClient.createApplication( ApplicationServiceSampleClient.getSampleApplication(ApplicationServiceSampleClient.ID + "2")); LOG.info("Created application:"); LOG.info(app2.toString()); LOG.info("Initializing CommandServiceClient"); final CommandServiceClient commandClient = CommandServiceClient.getInstance(); LOG.info("Creating command pig13_mr2"); final Command command1 = commandClient .createCommand(CommandServiceSampleClient.createSampleCommand(CommandServiceSampleClient.ID)); commandClient.setApplicationForCommand(command1.getId(), app1); LOG.info("Created command:"); LOG.info(command1.toString()); final List<Command> commands = new ArrayList<>(); commands.add(command1); LOG.info("Initializing ClusterConfigServiceClient"); final ClusterServiceClient clusterClient = ClusterServiceClient.getInstance(); LOG.info("Creating new cluster configuration"); final Cluster cluster1 = clusterClient.createCluster(createSampleCluster(ID)); clusterClient.addCommandsToCluster(cluster1.getId(), commands); LOG.info("Cluster config created with id: " + cluster1.getId()); LOG.info(cluster1.toString()); LOG.info("Getting cluster config by id"); final Cluster cluster2 = clusterClient.getCluster(cluster1.getId()); LOG.info(cluster2.toString()); LOG.info("Getting clusterConfigs using specified filter criteria"); final Multimap<String, String> params = ArrayListMultimap.create(); params.put("name", NAME); params.put("adHoc", "false"); params.put("test", "true"); params.put("limit", "3"); final List<Cluster> clusters = clusterClient.getClusters(params); if (clusters != null && !clusters.isEmpty()) { for (final Cluster cluster : clusters) { LOG.info(cluster.toString()); } } else { LOG.info("No clusters found for parameters"); } LOG.info("Configurations for cluster with id " + cluster1.getId()); final Set<String> configs = clusterClient.getConfigsForCluster(cluster1.getId()); for (final String config : configs) { LOG.info("Config = " + config); } LOG.info("Adding configurations to cluster with id " + cluster1.getId()); final Set<String> newConfigs = new HashSet<>(); newConfigs.add("someNewConfigFile"); newConfigs.add("someOtherNewConfigFile"); final Set<String> configs2 = clusterClient.addConfigsToCluster(cluster1.getId(), newConfigs); for (final String config : configs2) { LOG.info("Config = " + config); } LOG.info("Updating set of configuration files associated with id " + cluster1.getId()); //This should remove the original config leaving only the two in this set final Set<String> configs3 = clusterClient.updateConfigsForCluster(cluster1.getId(), newConfigs); for (final String config : configs3) { LOG.info("Config = " + config); } /**************** Begin tests for tag Api's *********************/ LOG.info("Get tags for cluster with id " + cluster1.getId()); final Set<String> tags = cluster1.getTags(); for (final String tag : tags) { LOG.info("Tag = " + tag); } LOG.info("Adding tags to cluster with id " + cluster1.getId()); final Set<String> newTags = new HashSet<>(); newTags.add("tag1"); newTags.add("tag2"); final Set<String> tags2 = clusterClient.addTagsToCluster(cluster1.getId(), newTags); for (final String tag : tags2) { LOG.info("Tag = " + tag); } LOG.info("Updating set of tags associated with id " + cluster1.getId()); //This should remove the original config leaving only the two in this set final Set<String> tags3 = clusterClient.updateTagsForCluster(cluster1.getId(), newTags); for (final String tag : tags3) { LOG.info("Tag = " + tag); } LOG.info("Deleting one tag from the cluster with id " + cluster1.getId()); //This should remove the "tag3" from the tags final Set<String> tags5 = clusterClient.removeTagForCluster(cluster1.getId(), "tag1"); for (final String tag : tags5) { //Shouldn't print anything LOG.info("Tag = " + tag); } LOG.info("Deleting all the tags from the cluster with id " + cluster1.getId()); //This should remove the original config leaving only the two in this set final Set<String> tags4 = clusterClient.removeAllTagsForCluster(cluster1.getId()); for (final String tag : tags4) { //Shouldn't print anything LOG.info("Config = " + tag); } /********************** End tests for tag Api's **********************/ LOG.info("Commands for cluster with id " + cluster1.getId()); final List<Command> commands1 = clusterClient.getCommandsForCluster(cluster1.getId()); for (final Command command : commands1) { LOG.info("Command = " + command); } LOG.info("Adding commands to cluster with id " + cluster1.getId()); final List<Command> newCmds = new ArrayList<>(); newCmds.add(commandClient.createCommand(CommandServiceSampleClient.createSampleCommand(ID + "something"))); newCmds.add(commandClient.createCommand(CommandServiceSampleClient.createSampleCommand(null))); final List<Command> commands2 = clusterClient.addCommandsToCluster(cluster1.getId(), newCmds); for (final Command command : commands2) { LOG.info("Command = " + command); } LOG.info("Updating set of commands files associated with id " + cluster1.getId()); //This should remove the original config leaving only the two in this set final List<Command> commands3 = clusterClient.updateCommandsForCluster(cluster1.getId(), newCmds); for (final Command command : commands3) { LOG.info("Command = " + command); } LOG.info("Deleting the command from the cluster with id " + ID + "something"); final Set<Command> commands4 = clusterClient.removeCommandForCluster(cluster1.getId(), ID + "something"); for (final Command command : commands4) { LOG.info("Command = " + command); } LOG.info("Deleting all the commands from the command with id " + command1.getId()); final List<Command> commands5 = clusterClient.removeAllCommandsForCluster(cluster1.getId()); for (final Command command : commands5) { //Shouldn't print anything LOG.info("Command = " + command); } LOG.info("Updating existing cluster config"); cluster2.setStatus(ClusterStatus.TERMINATED); final Cluster cluster3 = clusterClient.updateCluster(cluster2.getId(), cluster2); LOG.info("Cluster updated:"); LOG.info(cluster3.toString()); LOG.info("Deleting cluster config using id"); final Cluster cluster4 = clusterClient.deleteCluster(cluster1.getId()); LOG.info("Deleted cluster config with id: " + cluster1.getId()); LOG.info(cluster4.toString()); LOG.info("Deleting command config using id"); final Command command5 = commandClient.deleteCommand(command1.getId()); LOG.info("Deleted command config with id: " + command1.getId()); LOG.info(command5.toString()); LOG.info("Deleting commands in newCmd"); for (final Command cmd : newCmds) { commandClient.deleteCommand(cmd.getId()); } LOG.info("Deleting application config using id"); final Application app3 = appClient.deleteApplication(app1.getId()); LOG.info("Deleted application config with id: " + app1.getId()); LOG.info(app3.toString()); LOG.info("Deleting application config using id"); final Application app4 = appClient.deleteApplication(app2.getId()); LOG.info("Deleted application config with id: " + app2.getId()); LOG.info(app4.toString()); LOG.info("Done"); }
From source file:edu.umd.cloud9.example.bigram.AnalyzeBigramRelativeFrequencyTuple.java
@SuppressWarnings({ "static-access" }) public static void main(String[] args) throws Exception { Options options = new Options(); options.addOption(OptionBuilder.withArgName("path").hasArg().withDescription("input path").create(INPUT)); CommandLine cmdline = null;//from w w w. j a va 2 s.c o m CommandLineParser parser = new GnuParser(); try { cmdline = parser.parse(options, args); } catch (ParseException exp) { System.err.println("Error parsing command line: " + exp.getMessage()); System.exit(-1); } if (!cmdline.hasOption(INPUT)) { System.out.println("args: " + Arrays.toString(args)); HelpFormatter formatter = new HelpFormatter(); formatter.setWidth(120); formatter.printHelp(AnalyzeBigramRelativeFrequencyJson.class.getName(), options); ToolRunner.printGenericCommandUsage(System.out); System.exit(-1); } String inputPath = cmdline.getOptionValue(INPUT); System.out.println("input path: " + inputPath); List<PairOfWritables<Tuple, FloatWritable>> pairs = SequenceFileUtils.readDirectory(new Path(inputPath)); List<PairOfWritables<Tuple, FloatWritable>> list1 = Lists.newArrayList(); List<PairOfWritables<Tuple, FloatWritable>> list2 = Lists.newArrayList(); for (PairOfWritables<Tuple, FloatWritable> p : pairs) { Tuple bigram = p.getLeftElement(); if (bigram.get(0).equals("light")) { list1.add(p); } if (bigram.get(0).equals("contain")) { list2.add(p); } } Collections.sort(list1, new Comparator<PairOfWritables<Tuple, FloatWritable>>() { @SuppressWarnings("unchecked") public int compare(PairOfWritables<Tuple, FloatWritable> e1, PairOfWritables<Tuple, FloatWritable> e2) { if (e1.getRightElement().compareTo(e2.getRightElement()) == 0) { return e1.getLeftElement().compareTo(e2.getLeftElement()); } return e2.getRightElement().compareTo(e1.getRightElement()); } }); Iterator<PairOfWritables<Tuple, FloatWritable>> iter1 = Iterators.limit(list1.iterator(), 10); while (iter1.hasNext()) { PairOfWritables<Tuple, FloatWritable> p = iter1.next(); Tuple bigram = p.getLeftElement(); System.out.println(bigram + "\t" + p.getRightElement()); } Collections.sort(list2, new Comparator<PairOfWritables<Tuple, FloatWritable>>() { @SuppressWarnings("unchecked") public int compare(PairOfWritables<Tuple, FloatWritable> e1, PairOfWritables<Tuple, FloatWritable> e2) { if (e1.getRightElement().compareTo(e2.getRightElement()) == 0) { return e1.getLeftElement().compareTo(e2.getLeftElement()); } return e2.getRightElement().compareTo(e1.getRightElement()); } }); Iterator<PairOfWritables<Tuple, FloatWritable>> iter2 = Iterators.limit(list2.iterator(), 10); while (iter2.hasNext()) { PairOfWritables<Tuple, FloatWritable> p = iter2.next(); Tuple bigram = p.getLeftElement(); System.out.println(bigram + "\t" + p.getRightElement()); } }
From source file:com.siva.javamultithreading.MultiThreadExecutor.java
public static void main(String[] args) throws ExecutionException, IOException { //Populate the data List<DomainObject> list = new ArrayList<>(); DomainObject object = null;/*from ww w. jav a2s . c om*/ for (int i = 0; i < 230000; i++) { object = new DomainObject(); object.setId("ID" + i); object.setName("NAME" + i); object.setComment("COMMENT" + i); list.add(object); } int maxNoOfRows = 40000; int noOfThreads = 1; int remaining = 0; if (list.size() > 40000) { noOfThreads = list.size() / maxNoOfRows; remaining = list.size() % maxNoOfRows; if (remaining > 0) { noOfThreads++; } } List<List<DomainObject>> dos = ListUtils.partition(list, maxNoOfRows); ExecutorService threadPool = Executors.newFixedThreadPool(noOfThreads); CompletionService<HSSFWorkbook> pool = new ExecutorCompletionService<>(threadPool); // Excel creation through multiple threads long startTime = System.currentTimeMillis(); for (List<DomainObject> listObj : dos) { pool.submit(new ExcelChunkSheetWriter(listObj)); } HSSFWorkbook hSSFWorkbook = null; HSSFWorkbook book = new HSSFWorkbook(); HSSFSheet sheet = book.createSheet("Report"); try { for (int i = 0; i < 5; i++) { hSSFWorkbook = pool.take().get(); System.out.println( "sheet row count : sheet.PhysicalNumberOfRows() = " + sheet.getPhysicalNumberOfRows()); int currentCount = sheet.getPhysicalNumberOfRows(); int incomingCount = hSSFWorkbook.getSheetAt(0).getPhysicalNumberOfRows(); if ((currentCount + incomingCount) > 60000) { sheet = book.createSheet("Report" + i); } ExcelUtil.copySheets(book, sheet, hSSFWorkbook.getSheetAt(0)); } } catch (InterruptedException ex) { Logger.getLogger(MultiThreadExecutor.class.getName()).log(Level.SEVERE, null, ex); } catch (ExecutionException ex) { Logger.getLogger(MultiThreadExecutor.class.getName()).log(Level.SEVERE, null, ex); } try { writeFile(book, new FileOutputStream("Report.xls")); } catch (Exception e) { e.printStackTrace(); } //System.out.println("No of Threads : " + noOfThreads + " Size : " + list.size() + " remaining : " + remaining); long endTime = System.currentTimeMillis(); System.out.println("Time taken: " + (endTime - startTime) + " ms"); threadPool.shutdown(); //startProcess(); }
From source file:Test.java
public static void main(String[] args) { final AtomicLong orderIdGenerator = new AtomicLong(0); final List<Item> orders = Collections.synchronizedList(new ArrayList<Item>()); for (int i = 0; i < 10; i++) { Thread orderCreationThread = new Thread(new Runnable() { public void run() { for (int i = 0; i < 10; i++) { long orderId = orderIdGenerator.incrementAndGet(); Item order = new Item(Thread.currentThread().getName(), orderId); orders.add(order); }//from ww w.ja v a2 s. com } }); orderCreationThread.setName("Order Creation Thread " + i); orderCreationThread.start(); } try { Thread.sleep(1000); } catch (InterruptedException e) { e.printStackTrace(); } Set<Long> orderIds = new HashSet<Long>(); for (Item order : orders) { orderIds.add(order.getID()); System.out.println("Order id:" + order.getID()); } }
From source file:formats.db.fileformats.csv.RunnerCsv.java
public static void main(String[] args) throws IOException { CSVFormat format = CSVFormat.RFC4180.withHeader().withDelimiter(','); //initialize the CSVParser object CSVParser parser = new CSVParser(new FileReader("D:\\customers.csv"), format); List<Customers> customersList = new ArrayList<Customers>(); for (CSVRecord record : parser) { Customers customers = new Customers(); customers.setId_cs(Integer.parseInt(record.get("id_cs"))); customers.setF_name(record.get("f_name")); customers.setL_name(record.get("l_name")); customers.setDiscount(Integer.parseInt(record.get("discount"))); customers.setLicense(record.get("license")); customersList.add(customers); }/*from www.j a v a 2 s . co m*/ //close the parser parser.close(); System.out.println(customersList); }
From source file:com.clustercontrol.hub.util.CollectStringDataUtil.java
public static void main(String[] args) { System.out.println("START"); List<StringSample> list = new ArrayList<>(); StringSample sample = new StringSample(new Date(HinemosTime.currentTimeMillis()), "MON_SYS_0001"); sample.set("ver510logdev", "hoge", "<34>Oct 11 22:14:15 mymachine su: 'su root' failed for lonvick on /dev/pts/8"); list.add(sample); store(list);//from www .j av a2s.c om System.out.println("END"); }
From source file:com.senseidb.search.node.inmemory.InMemoryIndexPerfEval.java
public static void main(String[] args) throws Exception { final InMemorySenseiService memorySenseiService = InMemorySenseiService.valueOf( new File(InMemoryIndexPerfEval.class.getClassLoader().getResource("test-conf/node1/").toURI())); final List<JSONObject> docs = new ArrayList<JSONObject>(15000); LineIterator lineIterator = FileUtils.lineIterator( new File(InMemoryIndexPerfEval.class.getClassLoader().getResource("data/test_data.json").toURI())); int i = 0;/* w w w . j ava2 s . c o m*/ while (lineIterator.hasNext() && i < 100) { String car = lineIterator.next(); if (car != null && car.contains("{")) docs.add(new JSONObject(car)); i++; } Thread[] threads = new Thread[10]; for (int k = 0; k < threads.length; k++) { threads[k] = new Thread(new Runnable() { public void run() { long time = System.currentTimeMillis(); //System.out.println("Start thread"); for (int j = 0; j < 1000; j++) { //System.out.println("Send request"); memorySenseiService.doQuery(getRequest(), docs); } System.out.println("time = " + (System.currentTimeMillis() - time)); } }); threads[k].start(); } Thread.sleep(500000); }
From source file:ca.on.oicr.pde.deciders.GenomicAlignmentNovoalignDecider.java
public static void main(String args[]) { List<String> params = new ArrayList<String>(); params.add("--plugin"); params.add(GenomicAlignmentNovoalignDecider.class.getCanonicalName()); params.add("--"); params.addAll(Arrays.asList(args)); System.out.println("Parameters: " + Arrays.deepToString(params.toArray())); net.sourceforge.seqware.pipeline.runner.PluginRunner.main(params.toArray(new String[params.size()])); }
From source file:de.citec.sc.matoll.utils.visualizeSPARQL.java
public static void main(String[] args) { List<SparqlPattern> Patterns_EN = new ArrayList<SparqlPattern>(); List<SparqlPattern> Patterns_ES = new ArrayList<SparqlPattern>(); List<SparqlPattern> Patterns_DE = new ArrayList<SparqlPattern>(); Patterns_EN.add(new SparqlPattern_EN_Intransitive_PP()); Patterns_EN.add(new SparqlPattern_EN_Noun_PP_appos()); Patterns_EN.add(new SparqlPattern_EN_Noun_PP_copulative()); Patterns_EN.add(new SparqlPattern_EN_Predicative_Participle_passive()); Patterns_EN.add(new SparqlPattern_EN_Transitive_Verb()); Patterns_EN.add(new SparqlPattern_EN_Predicative_Participle_copulative()); Patterns_EN.add(new SparqlPattern_EN_Noun_PP_possessive()); Patterns_EN.add(new SparqlPattern_EN_Transitive_Passive()); Patterns_ES.add(new SparqlPattern_ES_Transitive()); Patterns_ES.add(new SparqlPattern_ES_Noun_PP_copulative_b()); Patterns_ES.add(new SparqlPattern_ES_Noun_PP_copulative_withHop()); Patterns_ES.add(new SparqlPattern_ES_Noun_PP_copulative()); Patterns_ES.add(new SparqlPattern_ES_Noun_PP_appos_b()); Patterns_ES.add(new SparqlPattern_ES_Noun_PP_appos()); Patterns_ES.add(new SparqlPattern_ES_Predicative_Participle_Copulative()); Patterns_ES.add(new SparqlPattern_ES_Predicative_Participle_Passive()); Patterns_ES.add(new SparqlPattern_ES_Intransitive_PP()); Patterns_ES.add(new SparqlPattern_ES_Transitive_Reciprocal()); Patterns_ES.add(new SparqlPattern_ES_Reflexive_Transitive_PP()); Patterns_ES.add(new SparqlPattern_ES_Transitive_passive()); Patterns_DE.add(new SparqlPattern_DE_Predicative_Adjective()); Patterns_DE.add(new SparqlPattern_DE_Noun_PP()); Patterns_DE.add(new SparqlPattern_DE_Noun_Possessive()); Patterns_DE.add(new SparqlPattern_DE_Noun_Possessive_b()); Patterns_DE.add(new SparqlPattern_DE_Transitive()); Patterns_DE.add(new SparqlPattern_DE_Transitive_Passive()); //Patterns.add(new SparqlPattern_DE_Transitive_Passive_optional()); Patterns_DE.add(new SparqlPattern_DE_Intransitive_PP()); Patterns_DE.add(new SparqlPattern_DE_Refelexive_Transitive_PP()); Patterns_DE.add(new SparqlPattern_DE_Noun_PP_appos()); Patterns_DE.add(new SparqlPattern_DE_Noun_Possessive_appos()); writePatterns(Patterns_EN, Language.EN); writePatterns(Patterns_ES, Language.ES); writePatterns(Patterns_DE, Language.DE); }
From source file:com.fun.rrs.common.excel.ExportExcel.java
/** * /* w ww . ja v a 2 s . co m*/ */ public static void main(String[] args) throws Throwable { List<String> headerList = new ArrayList<String>(); for (int i = 1; i <= 10; i++) { headerList.add("" + i); } List<String> dataRowList = new ArrayList<String>(); for (int i = 1; i <= headerList.size(); i++) { dataRowList.add("?" + i); } List<List<String>> dataList = new ArrayList<List<String>>(); for (int i = 1; i <= 100; i++) { dataList.add(dataRowList); } ExportExcel ee = new ExportExcel("", headerList); for (int i = 0; i < dataList.size(); i++) { Row row = ee.addRow(); for (int j = 0; j < dataList.get(i).size(); j++) { ee.addCell(row, j, dataList.get(i).get(j)); } } ee.writeFile("target/export.xlsx"); ee.dispose(); log.debug("Export success."); }