List of usage examples for java.util HashSet HashSet
public HashSet()
From source file:be.dnsbelgium.rdap.client.RDAPCLI.java
public static void main(String[] args) { LOGGER.debug("Create the command line parser"); CommandLineParser parser = new GnuParser(); LOGGER.debug("Create the options"); Options options = new RDAPOptions(Locale.ENGLISH); try {/*from w ww . ja v a 2 s . c o m*/ LOGGER.debug("Parse the command line arguments"); CommandLine line = parser.parse(options, args); if (line.hasOption("help")) { printHelp(options); return; } if (line.getArgs().length == 0) { throw new IllegalArgumentException("You must provide a query"); } String query = line.getArgs()[0]; Type type = (line.getArgs().length == 2) ? Type.valueOf(line.getArgs()[1].toUpperCase()) : guessQueryType(query); LOGGER.debug("Query: {}, Type: {}", query, type); try { SSLContextBuilder sslContextBuilder = SSLContexts.custom(); if (line.hasOption(RDAPOptions.TRUSTSTORE)) { sslContextBuilder.loadTrustMaterial( RDAPClient.getKeyStoreFromFile(new File(line.getOptionValue(RDAPOptions.TRUSTSTORE)), line.getOptionValue(RDAPOptions.TRUSTSTORE_TYPE, RDAPOptions.DEFAULT_STORETYPE), line.getOptionValue(RDAPOptions.TRUSTSTORE_PASS, RDAPOptions.DEFAULT_PASS))); } if (line.hasOption(RDAPOptions.KEYSTORE)) { sslContextBuilder.loadKeyMaterial( RDAPClient.getKeyStoreFromFile(new File(line.getOptionValue(RDAPOptions.KEYSTORE)), line.getOptionValue(RDAPOptions.KEYSTORE_TYPE, RDAPOptions.DEFAULT_STORETYPE), line.getOptionValue(RDAPOptions.KEYSTORE_PASS, RDAPOptions.DEFAULT_PASS)), line.getOptionValue(RDAPOptions.KEYSTORE_PASS, RDAPOptions.DEFAULT_PASS).toCharArray()); } SSLContext sslContext = sslContextBuilder.build(); final String url = line.getOptionValue(RDAPOptions.URL); final HttpHost host = Utils.httpHost(url); HashSet<Header> headers = new HashSet<Header>(); headers.add(new BasicHeader("Accept-Language", line.getOptionValue(RDAPOptions.LANG, Locale.getDefault().toString()))); HttpClientBuilder httpClientBuilder = HttpClients.custom().setDefaultHeaders(headers) .setSSLSocketFactory(new SSLConnectionSocketFactory(sslContext, (line.hasOption(RDAPOptions.INSECURE) ? new AllowAllHostnameVerifier() : new BrowserCompatHostnameVerifier()))); if (line.hasOption(RDAPOptions.USERNAME) && line.hasOption(RDAPOptions.PASSWORD)) { BasicCredentialsProvider credentialsProvider = new BasicCredentialsProvider(); credentialsProvider.setCredentials(new AuthScope(host.getHostName(), host.getPort()), new UsernamePasswordCredentials(line.getOptionValue(RDAPOptions.USERNAME), line.getOptionValue(RDAPOptions.PASSWORD))); httpClientBuilder.setDefaultCredentialsProvider(credentialsProvider); } RDAPClient rdapClient = new RDAPClient(httpClientBuilder.build(), url); ObjectMapper mapper = new ObjectMapper(); JsonNode json = null; switch (type) { case DOMAIN: json = rdapClient.getDomainAsJson(query); break; case ENTITY: json = rdapClient.getEntityAsJson(query); break; case AUTNUM: json = rdapClient.getAutNum(query); break; case IP: json = rdapClient.getIp(query); break; case NAMESERVER: json = rdapClient.getNameserver(query); break; } PrintWriter out = new PrintWriter(System.out, true); if (line.hasOption(RDAPOptions.RAW)) { mapper.writer().writeValue(out, json); } else if (line.hasOption(RDAPOptions.PRETTY)) { mapper.writer(new DefaultPrettyPrinter()).writeValue(out, json); } else if (line.hasOption(RDAPOptions.YAML)) { DumperOptions dumperOptions = new DumperOptions(); dumperOptions.setPrettyFlow(true); dumperOptions.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK); dumperOptions.setSplitLines(true); Yaml yaml = new Yaml(dumperOptions); Map data = mapper.convertValue(json, Map.class); yaml.dump(data, out); } else { mapper.writer(new MinimalPrettyPrinter()).writeValue(out, json); } out.flush(); } catch (Exception e) { LOGGER.error(e.getMessage(), e); System.exit(-1); } } catch (org.apache.commons.cli.ParseException e) { printHelp(options); System.exit(-1); } }
From source file:com.netflix.genie.client.sample.ApplicationServiceSampleClient.java
/** * Main for running client code./* ww w.j a va 2 s.c om*/ * * @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"); // ApplicationServiceClient.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(); LOG.info("Creating new application config"); final Application app1 = appClient.createApplication(getSampleApplication(null)); LOG.info("Application configuration created with id: " + app1.getId()); LOG.info(app1.toString()); LOG.info("Getting Applications using specified filter criteria name = " + APP_NAME); final Multimap<String, String> params = ArrayListMultimap.create(); params.put("name", APP_NAME); final List<Application> appResponses = appClient.getApplications(params); if (appResponses.isEmpty()) { LOG.info("No applications found for specified criteria."); } else { LOG.info("Applications found:"); for (final Application appResponse : appResponses) { LOG.info(appResponse.toString()); } } LOG.info("Getting application config by id"); final Application app2 = appClient.getApplication(app1.getId()); LOG.info(app2.toString()); LOG.info("Updating existing application config"); app2.setStatus(ApplicationStatus.INACTIVE); final Application app3 = appClient.updateApplication(app1.getId(), app2); LOG.info(app3.toString()); LOG.info("Configurations for application with id " + app1.getId()); final Set<String> configs = appClient.getConfigsForApplication(app1.getId()); for (final String config : configs) { LOG.info("Config = " + config); } LOG.info("Adding configurations to application with id " + app1.getId()); final Set<String> newConfigs = new HashSet<>(); newConfigs.add("someNewConfigFile"); newConfigs.add("someOtherNewConfigFile"); final Set<String> configs2 = appClient.addConfigsToApplication(app1.getId(), newConfigs); for (final String config : configs2) { LOG.info("Config = " + config); } LOG.info("Updating set of configuration files associated with id " + app1.getId()); //This should remove the original config leaving only the two in this set final Set<String> configs3 = appClient.updateConfigsForApplication(app1.getId(), newConfigs); for (final String config : configs3) { LOG.info("Config = " + config); } LOG.info("Deleting all the configuration files from the application with id " + app1.getId()); //This should remove the original config leaving only the two in this set final Set<String> configs4 = appClient.removeAllConfigsForApplication(app1.getId()); for (final String config : configs4) { //Shouldn't print anything LOG.info("Config = " + config); } /**************** Begin tests for tag Api's *********************/ LOG.info("Get tags for application with id " + app1.getId()); final Set<String> tags = app1.getTags(); for (final String tag : tags) { LOG.info("Tag = " + tag); } LOG.info("Adding tags to application with id " + app1.getId()); final Set<String> newTags = new HashSet<>(); newTags.add("tag1"); newTags.add("tag2"); final Set<String> tags2 = appClient.addTagsToApplication(app1.getId(), newTags); for (final String tag : tags2) { LOG.info("Tag = " + tag); } LOG.info("Updating set of tags associated with id " + app1.getId()); //This should remove the original config leaving only the two in this set final Set<String> tags3 = appClient.updateTagsForApplication(app1.getId(), newTags); for (final String tag : tags3) { LOG.info("Tag = " + tag); } LOG.info("Deleting one tag from the application with id " + app1.getId()); //This should remove the "tag3" from the tags final Set<String> tags5 = appClient.removeTagForApplication(app1.getId(), "tag1"); for (final String tag : tags5) { //Shouldn't print anything LOG.info("Tag = " + tag); } LOG.info("Deleting all the tags from the application with id " + app1.getId()); //This should remove the original config leaving only the two in this set final Set<String> tags4 = appClient.removeAllConfigsForApplication(app1.getId()); for (final String tag : tags4) { //Shouldn't print anything LOG.info("Config = " + tag); } /********************** End tests for tag Api's **********************/ LOG.info("Jars for application with id " + app1.getId()); final Set<String> jars = appClient.getJarsForApplication(app1.getId()); for (final String jar : jars) { LOG.info("jar = " + jar); } LOG.info("Adding jars to application with id " + app1.getId()); final Set<String> newJars = new HashSet<>(); newJars.add("someNewJarFile.jar"); newJars.add("someOtherNewJarFile.jar"); final Set<String> jars2 = appClient.addJarsToApplication(app1.getId(), newJars); for (final String jar : jars2) { LOG.info("jar = " + jar); } LOG.info("Updating set of jars associated with id " + app1.getId()); //This should remove the original jar leaving only the two in this set final Set<String> jars3 = appClient.updateJarsForApplication(app1.getId(), newJars); for (final String jar : jars3) { LOG.info("jar = " + jar); } LOG.info("Deleting all the jars from the application with id " + app1.getId()); //This should remove the original jar leaving only the two in this set final Set<String> jars4 = appClient.removeAllJarsForApplication(app1.getId()); for (final String jar : jars4) { //Shouldn't print anything LOG.info("jar = " + jar); } LOG.info("Getting the commands associated with id " + app1.getId()); final Set<Command> commands = appClient.getCommandsForApplication(app1.getId()); for (final Command command : commands) { LOG.info("Command: " + command.toString()); } LOG.info("Deleting application using id"); final Application app4 = appClient.deleteApplication(app1.getId()); LOG.info("Deleted application with id: " + app4.getId()); LOG.info(app4.toString()); LOG.info("Done"); }
From source file:ClassFileUtilities.java
/** * Program that computes the dependencies between the Batik jars. * <p>// ww w . j a v a 2s . com * Run this from the main Batik distribution directory, after building * the jars. For every jar file in the batik-xxx/ build directory, * it will determine which other jar files it directly depends on. * The output is lines of the form: * </p> * <pre> <i>number</i>,<i>from</i>,<i>to</i></pre> * <p> * where mean that the <i>from</i> jar has <i>number</i> class files * that depend on class files in the <i>to</i> jar. * </p> */ public static void main(String[] args) { boolean showFiles = false; if (args.length == 1 && args[0].equals("-f")) { showFiles = true; } else if (args.length != 0) { System.err.println("usage: ClassFileUtilities [-f]"); System.err.println(); System.err.println(" -f list files that cause each jar file dependency"); System.exit(1); } File cwd = new File("."); File buildDir = null; String[] cwdFiles = cwd.list(); for (int i = 0; i < cwdFiles.length; i++) { if (cwdFiles[i].startsWith("batik-")) { buildDir = new File(cwdFiles[i]); if (!buildDir.isDirectory()) { buildDir = null; } else { break; } } } if (buildDir == null || !buildDir.isDirectory()) { System.out.println("Directory 'batik-xxx' not found in current directory!"); return; } try { Map cs = new HashMap(); Map js = new HashMap(); collectJars(buildDir, js, cs); Set classpath = new HashSet(); Iterator i = js.values().iterator(); while (i.hasNext()) { classpath.add(((Jar) i.next()).jarFile); } i = cs.values().iterator(); while (i.hasNext()) { ClassFile fromFile = (ClassFile) i.next(); // System.out.println(fromFile.name); Set result = getClassDependencies(fromFile.getInputStream(), classpath, false); Iterator j = result.iterator(); while (j.hasNext()) { ClassFile toFile = (ClassFile) cs.get(j.next()); if (fromFile != toFile && toFile != null) { fromFile.deps.add(toFile); } } } i = cs.values().iterator(); while (i.hasNext()) { ClassFile fromFile = (ClassFile) i.next(); Iterator j = fromFile.deps.iterator(); while (j.hasNext()) { ClassFile toFile = (ClassFile) j.next(); Jar fromJar = fromFile.jar; Jar toJar = toFile.jar; if (fromFile.name.equals(toFile.name) || toJar == fromJar || fromJar.files.contains(toFile.name)) { continue; } Integer n = (Integer) fromJar.deps.get(toJar); if (n == null) { fromJar.deps.put(toJar, new Integer(1)); } else { fromJar.deps.put(toJar, new Integer(n.intValue() + 1)); } } } List triples = new ArrayList(10); i = js.values().iterator(); while (i.hasNext()) { Jar fromJar = (Jar) i.next(); Iterator j = fromJar.deps.keySet().iterator(); while (j.hasNext()) { Jar toJar = (Jar) j.next(); Triple t = new Triple(); t.from = fromJar; t.to = toJar; t.count = ((Integer) fromJar.deps.get(toJar)).intValue(); triples.add(t); } } Collections.sort(triples); i = triples.iterator(); while (i.hasNext()) { Triple t = (Triple) i.next(); System.out.println(t.count + "," + t.from.name + "," + t.to.name); if (showFiles) { Iterator j = t.from.files.iterator(); while (j.hasNext()) { ClassFile fromFile = (ClassFile) j.next(); Iterator k = fromFile.deps.iterator(); while (k.hasNext()) { ClassFile toFile = (ClassFile) k.next(); if (toFile.jar == t.to && !t.from.files.contains(toFile.name)) { System.out.println("\t" + fromFile.name + " --> " + toFile.name); } } } } } } catch (IOException e) { e.printStackTrace(); } }
From source file:org.acme.insurance.policyquote.test.WorkServiceMain.java
public static void main(String... args) throws Exception { serverHostname = System.getProperty("serverHostname", serverHostname); Set<String> policies = new HashSet<String>(); for (String arg : args) { arg = Strings.trimToNull(arg);/*from w ww . j a v a2 s . c o m*/ if (arg != null) { if (arg.equals(CONFIDENTIALITY) || arg.equals(CLIENT_AUTHENTICATION) || arg.equals(HELP)) { policies.add(arg); } else { LOGGER.error(MAVEN_USAGE); throw new Exception(MAVEN_USAGE); } } } if (policies.contains(HELP)) { LOGGER.info(MAVEN_USAGE); } else { final String scheme; final int port; if (policies.contains(CONFIDENTIALITY)) { LOGGER.info("Invoking service via SSL..."); scheme = "https"; port = 443; SSLContext sslcontext = SSLContext.getInstance("TLS"); sslcontext.init(null, null, null); SSLSocketFactory sf = new SSLSocketFactory(sslcontext, SSLSocketFactory.STRICT_HOSTNAME_VERIFIER); Scheme https = new Scheme(scheme, port, sf); SchemeRegistry sr = new SchemeRegistry(); sr.register(https); } else { scheme = "http"; port = 8080; } Element assertion = policies.contains(CLIENT_AUTHENTICATION) ? getAssertion() : null; invokeWorkService(scheme, port, assertion); } }
From source file:org.apache.flink.benchmark.Runner.java
public static void main(String[] args) throws Exception { final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment(); env.getConfig().enableObjectReuse(); env.getConfig().disableSysoutLogging(); ParameterTool parameters = ParameterTool.fromArgs(args); if (!(parameters.has("p") && parameters.has("types") && parameters.has("algorithms"))) { printUsage();//from ww w . j av a2 s . c o m System.exit(-1); } int parallelism = parameters.getInt("p"); env.setParallelism(parallelism); Set<IdType> types = new HashSet<>(); if (parameters.get("types").equals("all")) { types.add(IdType.INT); types.add(IdType.LONG); types.add(IdType.STRING); } else { for (String type : parameters.get("types").split(",")) { if (type.toLowerCase().equals("int")) { types.add(IdType.INT); } else if (type.toLowerCase().equals("long")) { types.add(IdType.LONG); } else if (type.toLowerCase().equals("string")) { types.add(IdType.STRING); } else { printUsage(); throw new RuntimeException("Unknown type: " + type); } } } Queue<RunnerWithScore> queue = new PriorityQueue<>(); if (parameters.get("algorithms").equals("all")) { for (Map.Entry<String, Class> entry : AVAILABLE_ALGORITHMS.entrySet()) { for (IdType type : types) { AlgorithmRunner runner = (AlgorithmRunner) entry.getValue().newInstance(); runner.initialize(type, SAMPLES, parallelism); runner.warmup(env); queue.add(new RunnerWithScore(runner, 1.0)); } } } else { for (String algorithm : parameters.get("algorithms").split(",")) { double ratio = 1.0; if (algorithm.contains("=")) { String[] split = algorithm.split("="); algorithm = split[0]; ratio = Double.parseDouble(split[1]); } if (AVAILABLE_ALGORITHMS.containsKey(algorithm.toLowerCase())) { Class clazz = AVAILABLE_ALGORITHMS.get(algorithm.toLowerCase()); for (IdType type : types) { AlgorithmRunner runner = (AlgorithmRunner) clazz.newInstance(); runner.initialize(type, SAMPLES, parallelism); runner.warmup(env); queue.add(new RunnerWithScore(runner, ratio)); } } else { printUsage(); throw new RuntimeException("Unknown algorithm: " + algorithm); } } } JsonFactory factory = new JsonFactory(); while (queue.size() > 0) { RunnerWithScore current = queue.poll(); AlgorithmRunner runner = current.getRunner(); StringWriter writer = new StringWriter(); JsonGenerator gen = factory.createGenerator(writer); gen.writeStartObject(); gen.writeStringField("algorithm", runner.getClass().getSimpleName()); boolean running = true; while (running) { try { runner.run(env, gen); running = false; } catch (ProgramInvocationException e) { // only suppress job cancellations if (!(e.getCause() instanceof JobCancellationException)) { throw e; } } } JobExecutionResult result = env.getLastJobExecutionResult(); long runtime_ms = result.getNetRuntime(); gen.writeNumberField("runtime_ms", runtime_ms); current.credit(runtime_ms); if (!runner.finished()) { queue.add(current); } gen.writeObjectFieldStart("accumulators"); for (Map.Entry<String, Object> accumulatorResult : result.getAllAccumulatorResults().entrySet()) { gen.writeStringField(accumulatorResult.getKey(), accumulatorResult.getValue().toString()); } gen.writeEndObject(); gen.writeEndObject(); gen.close(); System.out.println(writer.toString()); } }
From source file:com.netflix.genie.client.sample.CommandServiceSampleClient.java
/** * Main for running client code./*from w ww . j a va2s .c o m*/ * * @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"); // ApplicationServiceClient.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(createSampleCommand(ID)); commandClient.setApplicationForCommand(command1.getId(), app1); LOG.info("Created command:"); LOG.info(command1.toString()); LOG.info("Getting Commands using specified filter criteria name = " + CMD_NAME); final Multimap<String, String> params = ArrayListMultimap.create(); params.put("name", CMD_NAME); final List<Command> commands = commandClient.getCommands(params); if (commands.isEmpty()) { LOG.info("No commands found for specified criteria."); } else { LOG.info("Commands found:"); for (final Command command : commands) { LOG.info(command.toString()); } } LOG.info("Getting command config by id"); final Command command3 = commandClient.getCommand(ID); LOG.info(command3.toString()); LOG.info("Updating existing command config"); command3.setStatus(CommandStatus.INACTIVE); final Command command4 = commandClient.updateCommand(ID, command3); LOG.info(command4.toString()); LOG.info("Configurations for command with id " + command1.getId()); final Set<String> configs = commandClient.getConfigsForCommand(command1.getId()); for (final String config : configs) { LOG.info("Config = " + config); } LOG.info("Adding configurations to command with id " + command1.getId()); final Set<String> newConfigs = new HashSet<>(); newConfigs.add("someNewConfigFile"); newConfigs.add("someOtherNewConfigFile"); final Set<String> configs2 = commandClient.addConfigsToCommand(command1.getId(), newConfigs); for (final String config : configs2) { LOG.info("Config = " + config); } LOG.info("Updating set of configuration files associated with id " + command1.getId()); //This should remove the original config leaving only the two in this set final Set<String> configs3 = commandClient.updateConfigsForCommand(command1.getId(), newConfigs); for (final String config : configs3) { LOG.info("Config = " + config); } LOG.info("Deleting all the configuration files from the command with id " + command1.getId()); //This should remove the original config leaving only the two in this set final Set<String> configs4 = commandClient.removeAllConfigsForCommand(command1.getId()); for (final String config : configs4) { //Shouldn't print anything LOG.info("Config = " + config); } /**************** Begin tests for tag Api's *********************/ LOG.info("Get tags for command with id " + command1.getId()); final Set<String> tags = command1.getTags(); for (final String tag : tags) { LOG.info("Tag = " + tag); } LOG.info("Adding tags to command with id " + command1.getId()); final Set<String> newTags = new HashSet<>(); newTags.add("tag1"); newTags.add("tag2"); final Set<String> tags2 = commandClient.addTagsToCommand(command1.getId(), newTags); for (final String tag : tags2) { LOG.info("Tag = " + tag); } LOG.info("Updating set of tags associated with id " + command1.getId()); //This should remove the original config leaving only the two in this set final Set<String> tags3 = commandClient.updateTagsForCommand(command1.getId(), newTags); for (final String tag : tags3) { LOG.info("Tag = " + tag); } LOG.info("Deleting one tag from the command with id " + command1.getId()); //This should remove the "tag3" from the tags final Set<String> tags5 = commandClient.removeTagForCommand(command1.getId(), "tag1"); for (final String tag : tags5) { //Shouldn't print anything LOG.info("Tag = " + tag); } LOG.info("Deleting all the tags from the command with id " + command1.getId()); //This should remove the original config leaving only the two in this set final Set<String> tags4 = commandClient.removeAllConfigsForCommand(command1.getId()); for (final String tag : tags4) { //Shouldn't print anything LOG.info("Config = " + tag); } /********************** End tests for tag Api's **********************/ LOG.info("Application for command with id " + command1.getId()); final Application application = commandClient.getApplicationForCommand(command1.getId()); LOG.info("Application = " + application); LOG.info("Removing Application for command with id " + command1.getId()); final Application application2 = commandClient.removeApplicationForCommand(command1.getId()); LOG.info("Application = " + application2); LOG.info("Getting all the clusters for command with id " + command1.getId()); final Set<Cluster> clusters = commandClient.getClustersForCommand(command1.getId()); for (final Cluster cluster : clusters) { LOG.info("Cluster = " + cluster); } LOG.info("Deleting command config using id"); final Command command5 = commandClient.deleteCommand(ID); LOG.info("Deleted command config with id: " + ID); LOG.info(command5.toString()); LOG.info("Deleting all applications"); final List<Application> deletedApps = appClient.deleteAllApplications(); LOG.info("Deleted all applications"); LOG.info(deletedApps.toString()); LOG.info("Done"); }
From source file:com.joliciel.jochre.search.JochreSearch.java
/** * @param args//from w w w.j ava 2 s . c o m */ public static void main(String[] args) { try { Map<String, String> argMap = new HashMap<String, String>(); for (String arg : args) { int equalsPos = arg.indexOf('='); String argName = arg.substring(0, equalsPos); String argValue = arg.substring(equalsPos + 1); argMap.put(argName, argValue); } String command = argMap.get("command"); argMap.remove("command"); String logConfigPath = argMap.get("logConfigFile"); if (logConfigPath != null) { argMap.remove("logConfigFile"); Properties props = new Properties(); props.load(new FileInputStream(logConfigPath)); PropertyConfigurator.configure(props); } LOG.debug("##### Arguments:"); for (Entry<String, String> arg : argMap.entrySet()) { LOG.debug(arg.getKey() + ": " + arg.getValue()); } SearchServiceLocator locator = SearchServiceLocator.getInstance(); SearchService searchService = locator.getSearchService(); if (command.equals("buildIndex")) { String indexDirPath = argMap.get("indexDir"); String documentDirPath = argMap.get("documentDir"); File indexDir = new File(indexDirPath); indexDir.mkdirs(); File documentDir = new File(documentDirPath); JochreIndexBuilder builder = searchService.getJochreIndexBuilder(indexDir); builder.updateDocument(documentDir); } else if (command.equals("updateIndex")) { String indexDirPath = argMap.get("indexDir"); String documentDirPath = argMap.get("documentDir"); boolean forceUpdate = false; if (argMap.containsKey("forceUpdate")) { forceUpdate = argMap.get("forceUpdate").equals("true"); } File indexDir = new File(indexDirPath); indexDir.mkdirs(); File documentDir = new File(documentDirPath); JochreIndexBuilder builder = searchService.getJochreIndexBuilder(indexDir); builder.updateIndex(documentDir, forceUpdate); } else if (command.equals("search")) { HighlightServiceLocator highlightServiceLocator = HighlightServiceLocator.getInstance(locator); HighlightService highlightService = highlightServiceLocator.getHighlightService(); String indexDirPath = argMap.get("indexDir"); File indexDir = new File(indexDirPath); JochreQuery query = searchService.getJochreQuery(argMap); JochreIndexSearcher searcher = searchService.getJochreIndexSearcher(indexDir); TopDocs topDocs = searcher.search(query); Set<Integer> docIds = new LinkedHashSet<Integer>(); for (ScoreDoc scoreDoc : topDocs.scoreDocs) { docIds.add(scoreDoc.doc); } Set<String> fields = new HashSet<String>(); fields.add("text"); Highlighter highlighter = highlightService.getHighlighter(query, searcher.getIndexSearcher()); HighlightManager highlightManager = highlightService .getHighlightManager(searcher.getIndexSearcher()); highlightManager.setDecimalPlaces(query.getDecimalPlaces()); highlightManager.setMinWeight(0.0); highlightManager.setIncludeText(true); highlightManager.setIncludeGraphics(true); Writer out = new PrintWriter(new OutputStreamWriter(System.out, StandardCharsets.UTF_8)); if (command.equals("highlight")) { highlightManager.highlight(highlighter, docIds, fields, out); } else { highlightManager.findSnippets(highlighter, docIds, fields, out); } } else { throw new RuntimeException("Unknown command: " + command); } } catch (RuntimeException e) { LogUtils.logError(LOG, e); throw e; } catch (IOException e) { LogUtils.logError(LOG, e); throw new RuntimeException(e); } }
From source file:org.ptm.translater.App.java
public static void main(String... args) { GenericXmlApplicationContext ctx = new GenericXmlApplicationContext(); ctx.load("file:src/main/resources/spring/datasource.xml"); ctx.refresh();// w w w .ja va 2 s. c o m GenericXmlApplicationContext ctx2 = new GenericXmlApplicationContext(); ctx2.load("file:src/main/resources/spring/datasource2.xml"); ctx2.refresh(); ArchiveDao archiveDao = ctx.getBean("archiveDao", ArchiveDao.class); List<Archive> archives = archiveDao.findAll(); UserDao userDao = ctx2.getBean("userDao", UserDao.class); TagDao tagDao = ctx2.getBean("tagDao", TagDao.class); PhotoDao photoDao = ctx2.getBean("photoDao", PhotoDao.class); List<Tag> tagz = tagDao.findAll(); Map<String, Long> hashTags = new HashMap<String, Long>(); for (Tag tag : tagz) hashTags.put(tag.getName(), tag.getId()); MongoCache cache = new MongoCache(); Calendar calendar = Calendar.getInstance(); Map<String, String> associates = new HashMap<String, String>(); for (Archive archive : archives) { AppUser appUser = new AppUser(); appUser.setName(archive.getName()); appUser.setEmail(archive.getUid() + "@mail.th"); appUser.setPassword("123456"); Role role = new Role(); role.setRoleId("ROLE_USER"); appUser.setRole(role); userDao.save(appUser); System.out.println("\tCreate user " + appUser); for (Photo photo : archive.getPhotos()) { // ? ??? if (cache.contains(photo.getUid())) continue; System.out.println("\tNew photo"); org.ptm.translater.ch2.domain.Photo photo2 = new org.ptm.translater.ch2.domain.Photo(); photo2.setAppUser(appUser); photo2.setName(photo.getTitle()); photo2.setLicense((byte) 7); photo2.setDescription(photo.getDescription()); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); try { calendar.setTime(sdf.parse(photo.getTaken())); if (calendar.get(Calendar.YEAR) != 0 && calendar.get(Calendar.YEAR) > 1998) continue; photo2.setYear(calendar.get(Calendar.YEAR)); photo2.setMonth(calendar.get(Calendar.MONTH) + 1); photo2.setDay(calendar.get(Calendar.DAY_OF_MONTH)); } catch (Exception ex) { ex.printStackTrace(); } if (photo.getLongitude() != null && photo.getLongitude().length() > 0) { // String key = photo.getLongitude()+"#"+photo.getLatitude(); photo2.setLatitude(photo.getLatitude()); photo2.setLongitude(photo.getLongitude()); // if (associates.containsKey(key)) { // photo2.setAddress(associates.get(key)); // } else { // Geocoder geocoder = new Geocoder(); // GeocoderRequestBuilder geocoderRequest = new GeocoderRequestBuilder(); // GeocoderRequest request = // geocoderRequest.setLocation(new LatLng(photo.getLongitude(), photo.getLatitude())).getGeocoderRequest(); // // GeocodeResponse response = geocoder.geocode(request); // if (response.getResults().size() > 0) { // photo2.setAddress(response.getResults().get(0).getFormattedAddress()); // } // try { Thread.sleep(2000); } catch (InterruptedException ex) { ex.printStackTrace(); } // } } System.out.println("\tFind tags"); Set<Tag> tags = new HashSet<Tag>(); for (org.ptm.translater.ch1.domain.Tag tag : photo.getTags()) { Tag item = new Tag(); item.setName(tag.getName()); if (hashTags.containsKey(tag.getName())) { item.setId(hashTags.get(tag.getName())); } else { tagDao.save(item); hashTags.put(item.getName(), item.getId()); } System.out.println("\t\tinit tag " + tag.getName()); tags.add(item); } photo2.setTags(tags); System.out.println("\tFind " + tags.size() + " tags"); photoDao.save(photo2); System.out.println("\tSave photo"); Imaginator img = new Imaginator(); img.setFolder(photo2.getId().toString()); img.setPath(); for (PhotoSize ps : photo.getSizes()) { if (ps.getLabel().equals("Original")) { img.setImage(ps.getSource()); break; } } img.generate(); System.out.println("\tGenerate image of photo"); img = null; cache.create(photo.getUid()); cache.create(photo2); System.out.println("Generate: " + photo2); } } }
From source file:cc.twittertools.search.api.RunQueriesThrift.java
@SuppressWarnings("static-access") public static void main(String[] args) throws Exception { Options options = new Options(); options.addOption(OptionBuilder.withArgName("string").hasArg().withDescription("host").create(HOST_OPTION)); options.addOption(OptionBuilder.withArgName("port").hasArg().withDescription("port").create(PORT_OPTION)); options.addOption(OptionBuilder.withArgName("file").hasArg() .withDescription("file containing topics in TREC format").create(QUERIES_OPTION)); options.addOption(OptionBuilder.withArgName("num").hasArg().withDescription("number of results to return") .create(NUM_RESULTS_OPTION)); options.addOption(//from ww w .j av a 2 s . c o m OptionBuilder.withArgName("string").hasArg().withDescription("group id").create(GROUP_OPTION)); options.addOption( OptionBuilder.withArgName("string").hasArg().withDescription("access token").create(TOKEN_OPTION)); options.addOption( OptionBuilder.withArgName("string").hasArg().withDescription("runtag").create(RUNTAG_OPTION)); options.addOption(new Option(VERBOSE_OPTION, "print out complete document")); CommandLine cmdline = null; 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(HOST_OPTION) || !cmdline.hasOption(PORT_OPTION) || !cmdline.hasOption(QUERIES_OPTION)) { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp(RunQueriesThrift.class.getName(), options); System.exit(-1); } String queryFile = cmdline.getOptionValue(QUERIES_OPTION); if (!new File(queryFile).exists()) { System.err.println("Error: " + queryFile + " doesn't exist!"); System.exit(-1); } String runtag = cmdline.hasOption(RUNTAG_OPTION) ? cmdline.getOptionValue(RUNTAG_OPTION) : DEFAULT_RUNTAG; TrecTopicSet topicsFile = TrecTopicSet.fromFile(new File(queryFile)); int numResults = 1000; try { if (cmdline.hasOption(NUM_RESULTS_OPTION)) { numResults = Integer.parseInt(cmdline.getOptionValue(NUM_RESULTS_OPTION)); } } catch (NumberFormatException e) { System.err.println("Invalid " + NUM_RESULTS_OPTION + ": " + cmdline.getOptionValue(NUM_RESULTS_OPTION)); System.exit(-1); } String group = cmdline.hasOption(GROUP_OPTION) ? cmdline.getOptionValue(GROUP_OPTION) : null; String token = cmdline.hasOption(TOKEN_OPTION) ? cmdline.getOptionValue(TOKEN_OPTION) : null; boolean verbose = cmdline.hasOption(VERBOSE_OPTION); PrintStream out = new PrintStream(System.out, true, "UTF-8"); TrecSearchThriftClient client = new TrecSearchThriftClient(cmdline.getOptionValue(HOST_OPTION), Integer.parseInt(cmdline.getOptionValue(PORT_OPTION)), group, token); for (cc.twittertools.search.TrecTopic query : topicsFile) { List<TResult> results = client.search(query.getQuery(), query.getQueryTweetTime(), numResults); int i = 1; Set<Long> tweetIds = new HashSet<Long>(); for (TResult result : results) { if (!tweetIds.contains(result.id)) { tweetIds.add(result.id); out.println( String.format("%s Q0 %d %d %f %s", query.getId(), result.id, i, result.rsv, runtag)); if (verbose) { out.println("# " + result.toString().replaceAll("[\\n\\r]+", " ")); } i++; } } } out.close(); }
From source file:com.act.analysis.surfactant.AnalysisDriver.java
public static void main(String[] args) throws Exception { Options opts = new Options(); for (Option.Builder b : OPTION_BUILDERS) { opts.addOption(b.build());//w w w . ja v a 2s.com } CommandLine cl = null; try { CommandLineParser parser = new DefaultParser(); cl = parser.parse(opts, args); } catch (ParseException e) { System.err.format("Argument parsing failed: %s\n", e.getMessage()); HELP_FORMATTER.printHelp(LoadPlateCompositionIntoDB.class.getCanonicalName(), HELP_MESSAGE, opts, null, true); System.exit(1); } if (cl.hasOption("help")) { HELP_FORMATTER.printHelp(LoadPlateCompositionIntoDB.class.getCanonicalName(), HELP_MESSAGE, opts, null, true); return; } Set<String> seenOutputIds = new HashSet<>(); TSVWriter<String, String> tsvWriter = null; if (cl.hasOption(OPTION_OUTPUT_FILE)) { File outputFile = new File(cl.getOptionValue(OPTION_OUTPUT_FILE)); List<Map<String, String>> oldResults = null; if (outputFile.exists()) { System.err.format( "Output file already exists, reading old results and skipping processed molecules.\n"); TSVParser outputParser = new TSVParser(); outputParser.parse(outputFile); oldResults = outputParser.getResults(); for (Map<String, String> row : oldResults) { // TODO: verify that the last row was written cleanly/completely. seenOutputIds.add(row.get("id")); } } List<String> header = new ArrayList<>(); header.add("name"); header.add("id"); header.add("inchi"); header.add("label"); for (SurfactantAnalysis.FEATURES f : SurfactantAnalysis.FEATURES.values()) { header.add(f.toString()); } // TODO: make this API more auto-closable friendly. tsvWriter = new TSVWriter<>(header); tsvWriter.open(outputFile); if (oldResults != null) { System.out.format("Re-writing %d existing result rows\n", oldResults.size()); tsvWriter.append(oldResults); } } try { Map<SurfactantAnalysis.FEATURES, Double> analysisFeatures; LicenseManager.setLicenseFile(cl.getOptionValue(OPTION_LICENSE_FILE)); if (cl.hasOption(OPTION_INCHI)) { analysisFeatures = SurfactantAnalysis.performAnalysis(cl.getOptionValue(OPTION_INCHI), cl.hasOption(OPTION_DISPLAY)); Map<String, String> tsvFeatures = new HashMap<>(); // Convert features to strings to avoid some weird formatting issues. It's ugly, but it works. for (Map.Entry<SurfactantAnalysis.FEATURES, Double> entry : analysisFeatures.entrySet()) { tsvFeatures.put(entry.getKey().toString(), String.format("%.6f", entry.getValue())); } tsvFeatures.put("name", "direct-inchi-input"); if (tsvWriter != null) { tsvWriter.append(tsvFeatures); } } else if (cl.hasOption(OPTION_INPUT_FILE)) { TSVParser parser = new TSVParser(); parser.parse(new File(cl.getOptionValue(OPTION_INPUT_FILE))); int i = 0; List<Map<String, String>> inputRows = parser.getResults(); for (Map<String, String> row : inputRows) { i++; // Just for warning messages. if (!row.containsKey("name") || !row.containsKey("id") || !row.containsKey("inchi")) { System.err.format( "WARNING: TSV rows must contain at least name, id, and inchi, skipping row %d\n", i); continue; } if (seenOutputIds.contains(row.get("id"))) { System.out.format("Skipping input row with id already in output: %s\n", row.get("id")); continue; } System.out.format("Analysis for chemical %s\n", row.get("name")); try { analysisFeatures = SurfactantAnalysis.performAnalysis(row.get("inchi"), false); } catch (Exception e) { // Ignore exceptions for now. Sometimes the regression analysis or Chemaxon processing chokes unexpectedly. System.err.format("ERROR caught exception while processing '%s':\n", row.get("name")); System.err.format("%s\n", e.getMessage()); e.printStackTrace(System.err); System.err.println("Skipping..."); continue; } System.out.format("--- Done analysis for chemical %s\n", row.get("name")); // This is a duplicate of the OPTION_INCHI block code, but it's inside of a tight loop, so... Map<String, String> tsvFeatures = new HashMap<>(); for (Map.Entry<SurfactantAnalysis.FEATURES, Double> entry : analysisFeatures.entrySet()) { tsvFeatures.put(entry.getKey().toString(), String.format("%.6f", entry.getValue())); } tsvFeatures.put("name", row.get("name")); tsvFeatures.put("id", row.get("id")); tsvFeatures.put("inchi", row.get("inchi")); tsvFeatures.put("label", row.containsKey("label") ? row.get("label") : "?"); if (tsvWriter != null) { tsvWriter.append(tsvFeatures); // Flush every time in case we crash or get interrupted. The features must flow! tsvWriter.flush(); } } } else { throw new RuntimeException("Must specify inchi or input file"); } } finally { if (tsvWriter != null) { tsvWriter.close(); } } }