List of usage examples for java.util HashSet HashSet
public HashSet(int initialCapacity)
From source file:ProducerAndConsumerTool.java
public static void main(String[] args) { ConsumerTool consumerTool = new ConsumerTool(); String[] unknown = CommandLineSupport.setOptions(consumerTool, args); HashSet<String> set1 = new HashSet<String>(Arrays.asList(unknown)); ProducerTool producerTool = new ProducerTool(); unknown = CommandLineSupport.setOptions(producerTool, args); HashSet<String> set2 = new HashSet<String>(Arrays.asList(unknown)); set1.retainAll(set2);//www . j a v a2s . c om if (set1.size() > 0) { System.out.println("Unknown options: " + set1); System.exit(-1); } consumerTool.run(); producerTool.run(); }
From source file:Main.java
public static void main(String[] args) throws Exception { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder = factory.newDocumentBuilder(); Document doc = builder.parse(new File("Table.xml")); XPathFactory xFactory = XPathFactory.newInstance(); XPath path = xFactory.newXPath(); XPathExpression exp = path.compile("/tables/table"); NodeList nlTables = (NodeList) exp.evaluate(doc, XPathConstants.NODESET); for (int tblIndex = 0; tblIndex < nlTables.getLength(); tblIndex++) { Node table = nlTables.item(tblIndex); Node nAtt = table.getAttributes().getNamedItem("title"); System.out.println(nAtt.getTextContent()); exp = path.compile("headings/heading"); NodeList nlHeaders = (NodeList) exp.evaluate(table, XPathConstants.NODESET); Set<String> headers = new HashSet<String>(25); for (int index = 0; index < nlHeaders.getLength(); index++) { headers.add(nlHeaders.item(index).getTextContent().trim()); }//from ww w . j a va2s. c o m for (String header : headers) { System.out.println(header); } exp = path.compile("tablebody/tablerow"); NodeList nlRows = (NodeList) exp.evaluate(table, XPathConstants.NODESET); for (int index = 0; index < nlRows.getLength(); index++) { Node rowNode = nlRows.item(index); exp = path.compile("tablecell/item"); NodeList nlValues = (NodeList) exp.evaluate(rowNode, XPathConstants.NODESET); List<String> values = new ArrayList<String>(25); for (int valueIndex = 0; valueIndex < nlValues.getLength(); valueIndex++) { values.add(nlValues.item(valueIndex).getTextContent().trim()); } for (String value : values) { System.out.println(value); } } } }
From source file:ProducerAndConsumerTool.java
public static void main(String[] args) { ConsumerTool consumerTool = new ConsumerTool(); String[] unknown = CommandLineSupport.setOptions(consumerTool, args); HashSet<String> set1 = new HashSet<String>(Arrays.asList(unknown)); HashSet<String> set4 = new HashSet<String>(5); ProducerTool producerTool = new ProducerTool(); unknown = CommandLineSupport.setOptions(producerTool, args); HashSet<String> set2 = new HashSet<String>(Arrays.asList(unknown)); set1.retainAll(set2);//w w w. ja v a 2 s .c o m if (set1.size() > 0) { System.out.println("Unknown options: " + set1); System.exit(-1); } /* consumerTool.run(); */ producerTool.run(); }
From source file:com.tragicphantom.stdf.tools.extract.CommandLine.java
public static void main(String[] args) { try {/*from w ww . j ava 2 s. c o m*/ Options options = setupOptions(); org.apache.commons.cli.CommandLine cl = new GnuParser().parse(options, args); if (cl.hasOption("t")) { HashSet<String> types = new HashSet<String>(Arrays.asList(cl.getOptionValue("t").split(","))); OutputFormatter outputFormatter; if (cl.hasOption("x")) outputFormatter = new RawOutputFormatter(); else if (cl.hasOption("c")) outputFormatter = new CsvOutputFormatter(); else outputFormatter = new DefaultOutputFormatter(); for (String file : cl.getArgs()) { System.out.println(file); Visitor visitor = new Visitor(file, types); System.out.println(visitor.size() + " records found"); for (Record record : visitor) outputFormatter.write(record); } } else new HelpFormatter().printHelp("extract", options); } catch (Exception e) { e.printStackTrace(); } }
From source file:Employee.java
public static void main(String[] args) { Set<Employee> empSet = new HashSet<Employee>(populateList()); for (Employee employee : empSet) { System.out.println(employee); }//from ww w. jav a2 s . c o m }
From source file:com.me.jvmi.Main.java
public static void main(String[] args) throws IOException { final Path localProductImagesPath = Paths.get("/Volumes/jvmpubfs/WEB/images/products/"); final Path uploadCSVFile = Paths.get("/Users/jbabic/Documents/products/upload.csv"); final Config config = new Config(Paths.get("../config.properties")); LuminateOnlineClient luminateClient2 = new LuminateOnlineClient("https://secure2.convio.net/jvmi/admin/", 3);/* ww w. jav a 2s. c o m*/ luminateClient2.login(config.luminateUser(), config.luminatePassword()); Set<String> completed = new HashSet<>( IOUtils.readLines(Files.newBufferedReader(Paths.get("completed.txt")))); try (InputStream is = Files.newInputStream(Paths.get("donforms.csv")); PrintWriter pw = new PrintWriter(new FileOutputStream(new File("completed.txt"), true))) { for (String line : IOUtils.readLines(is)) { if (completed.contains(line)) { System.out.println("completed: " + line); continue; } try { luminateClient2.editDonationForm(line, "-1"); pw.println(line); System.out.println("done: " + line); pw.flush(); } catch (Exception e) { System.out.println("skipping: " + line); e.printStackTrace(); } } } // luminateClient2.editDonationForm("8840", "-1"); // Collection<String> ids = luminateClient2.donFormSearch("", true); // // CSVFormat csvFileFormat = CSVFormat.DEFAULT.withRecordSeparator("\n"); // try (FileWriter fileWriter = new FileWriter(new File("donforms.csv")); // CSVPrinter csvFilePrinter = new CSVPrinter(fileWriter, csvFileFormat);) { // // for (String id : ids) { // csvFilePrinter.printRecord(id); // } // } // if (true) { return; } Collection<InputRecord> records = parseInput(uploadCSVFile); LuminateFTPClient ftp = new LuminateFTPClient("customerftp.convio.net"); ftp.login(config.ftpUser(), config.ftpPassword()); ProductImages images = new ProductImages(localProductImagesPath, ftp); validateImages(records, images); Map<String, DPCSClient> dpcsClients = new HashMap<>(); dpcsClients.put("us", new DPCSClient("https://donor.dpconsulting.com/NewDDI/Logon.asp?client=jvm")); dpcsClients.put("ca", new DPCSClient("https://donor.dpconsulting.com/NewDDI/Logon.asp?client=jvcn")); dpcsClients.put("uk", new DPCSClient("https://donor.dpconsulting.com/NewDDI/Logon.asp?client=jvuk")); for (DPCSClient client : dpcsClients.values()) { client.login(config.dpcsUser(), config.dpcsPassword()); } Map<String, LuminateOnlineClient> luminateClients = new HashMap<>(); luminateClients.put("us", new LuminateOnlineClient("https://secure2.convio.net/jvmi/admin/", 10)); luminateClients.put("ca", new LuminateOnlineClient("https://secure3.convio.net/jvmica/admin/", 10)); luminateClients.put("uk", new LuminateOnlineClient("https://secure3.convio.net/jvmiuk/admin/", 10)); Map<String, EcommerceProductFactory> ecommFactories = new HashMap<>(); ecommFactories.put("us", new EcommerceProductFactory(dpcsClients.get("us"), images, Categories.us)); ecommFactories.put("ca", new EcommerceProductFactory(dpcsClients.get("ca"), images, Categories.ca)); ecommFactories.put("uk", new EcommerceProductFactory(dpcsClients.get("uk"), images, Categories.uk)); List<String> countries = Arrays.asList("us", "ca", "uk"); boolean error = false; for (InputRecord record : records) { for (String country : countries) { if (record.ignore(country)) { System.out.println("IGNORE: " + country + " " + record); continue; } try { EcommerceProductFactory ecommFactory = ecommFactories.get(country); LuminateOnlineClient luminateClient = luminateClients.get(country); luminateClient.login(config.luminateUser(), config.luminatePassword()); ECommerceProduct product = ecommFactory.createECommerceProduct(record); luminateClient.createOrUpdateProduct(product); } catch (Exception e) { System.out.println("ERROR: " + country + " " + record); //System.out.println(e.getMessage()); error = true; e.printStackTrace(); } } } if (!error) { for (String country : countries) { LuminateOnlineClient luminateClient = luminateClients.get(country); DPCSClient dpcsClient = dpcsClients.get(country); luminateClient.close(); dpcsClient.close(); } } }
From source file:com.dattack.dbping.cli.PingCli.java
/** * The <code>main</code> method. * * @param args//from w ww .ja v a 2 s . c om * the program arguments */ public static void main(final String[] args) { final Options options = createOptions(); try { final CommandLineParser parser = new DefaultParser(); final CommandLine cmd = parser.parse(options, args); final String[] filenames = cmd.getOptionValues(FILE_OPTION); final String[] taskNames = cmd.getOptionValues(TASK_NAME_OPTION); HashSet<String> hs = null; if (taskNames != null) { hs = new HashSet<>(Arrays.asList(taskNames)); } final PingEngine ping = new PingEngine(); ping.execute(filenames, hs); } catch (@SuppressWarnings("unused") final ParseException e) { showUsage(options); } catch (final ConfigurationException | DattackParserException e) { System.err.println(e.getMessage()); } }
From source file:edu.scripps.fl.pubchem.app.AssayDownloader.java
public static void main(String[] args) throws Exception { CommandLineHandler clh = new CommandLineHandler() { public void configureOptions(Options options) { options.addOption(OptionBuilder.withLongOpt("data_url").withType("").withValueSeparator('=') .hasArg().create()); options.addOption(/*from w w w . j a va2s .c om*/ OptionBuilder.withLongOpt("days").withType(0).withValueSeparator('=').hasArg().create()); options.addOption(OptionBuilder.withLongOpt("mlpcn").withType(false).create()); options.addOption(OptionBuilder.withLongOpt("notInDb").withType(false).create()); } }; args = clh.handle(args); String data_url = clh.getCommandLine().getOptionValue("data_url"); if (null == data_url) data_url = "ftp://ftp.ncbi.nlm.nih.gov/pubchem/Bioassay/CSV/"; // data_url = "file:///C:/Home/temp/PubChemFTP/"; AssayDownloader main = new AssayDownloader(); main.dataUrl = new URL(data_url); if (clh.getCommandLine().hasOption("days")) main.days = Integer.parseInt(clh.getCommandLine().getOptionValue("days")); if (clh.getCommandLine().hasOption("mlpcn")) main.mlpcn = true; if (clh.getCommandLine().hasOption("notInDb")) main.notInDb = true; if (args.length == 0) main.process(); else { Long[] list = (Long[]) ConvertUtils.convert(args, Long[].class); List<Long> l = (List<Long>) Arrays.asList(list); log.info("AID to process: " + l); main.process(new HashSet<Long>(Arrays.asList(list))); } }
From source file:com.impetus.ankush.agent.daemon.AnkushAgent.java
/** * The main method./*from ww w .j a v a2s .c om*/ * * @param args * the arguments */ public static void main(String[] args) { // taskable file name. String file = System.getProperty(Constant.AGENT_INSTALL_DIR) + "/.ankush/agent/conf/taskable.conf"; // iterate always try { // reading the class name lines from the file List<String> classNames = FileUtils.readLines(new File(file)); // iterate over the class names to start the newly added task. for (String className : classNames) { // if an empty string from the file then continue the loop. if (className.isEmpty()) { continue; } // if not started. if (!objMap.containsKey(className)) { // create taskable object LOGGER.info("Creating " + className + " object."); try { Taskable taskable = ActionFactory.getTaskableObject(className); objMap.put(className, taskable); // call start on object ... taskable.start(); } catch (Exception e) { LOGGER.error("Could not start the " + className + " taskable."); } } } // iterating over the existing tasks to stop if it is removed // from the file. Set<String> existingClassNames = new HashSet<String>(objMap.keySet()); for (String className : existingClassNames) { // if not started. if (!classNames.contains(className)) { // create taskable object LOGGER.info("Removing " + className + " object."); Taskable taskable = objMap.get(className); objMap.remove(className); // call stop on object ... taskable.stop(); } } } catch (Exception e) { LOGGER.error(e.getMessage(), e); } while (true) { try { Thread.sleep(TASK_SEARCH_SLEEP_TIME); } catch (Exception e) { LOGGER.error(e.getMessage(), e); } } }
From source file:fall2015.b565.wisBreastCancer.Assignment2.java
public static void main(String[] args) throws Exception { try {//w ww.j a v a 2s. co m parseArguments(args); FileReader fileReader = new FileReader(); if (useReplaceDataSet) { cleanedFilePath = Constants.REPLACED_DATA_FILE_PATH; } else { cleanedFilePath = Constants.REMOVED_DATA_FILE_PATH; } KMeans kMeans = new KMeans(); System.out.println("=============== Pre-Processing of Data ==============="); fileReader.cleanDataSet(); System.out.println("=============== Data Cleaned ==============="); if (correlation) { System.out.println("=============== Finding Correlation between attributes ==============="); kMeans.findAttributeCorrelations(); } if (ppv) { System.out.println("=============== Finding PPV considering all the attributes ==============="); KMeansResult kMeansResult = kMeans.findKmeansToAllAttributes(cleanedFilePath); double ppv = kMeans.calculatePPV(kMeansResult.getFinalCentroids(), kMeans.getRecords(cleanedFilePath)); System.out.println("Calculated PPV : " + ppv); } if (powerSetPPV) { System.out.println( "=============== Finding PPV considering power set of the attributes ==============="); kMeans.findKmeansToAttributePowerSet(cleanedFilePath); } if (vfoldCrossValidation) { System.out.println( "=============== Finding V Fold cross validation considering all the attribute set ==============="); KMeansResult kMeansResult = kMeans.findKmeansToAllAttributes(cleanedFilePath); HashSet<Integer> attributes = new HashSet<Integer>(Ints.asList(allAttributeHeaders)); double vPPV = kMeans.vFoldCrossValidation(kMeansResult.getInitialRecords(), attributes); System.out.println("VFold cross validation PPV : " + vPPV); } } catch (Exception e) { throw new RuntimeException(e); } }