List of usage examples for java.util Set contains
boolean contains(Object o);
From source file:MainClass.java
public static void main(String[] a) { String elements[] = { "A", "B", "C", "D", "E" }; Set set = new HashSet(Arrays.asList(elements)); System.out.println(set.contains("A")); }
From source file:Main.java
public static void main(String[] a) { String elements[] = { "A", "B", "C", "D", "E" }; Set<String> set = new HashSet<String>(Arrays.asList(elements)); System.out.println(set.contains("A")); }
From source file:Main.java
public static void main(final String[] args) { final Set<String[]> s = new HashSet<String[]>(); final Set<List<String>> s2 = new HashSet<List<String>>(); s.add(new String[] { "lucy", "simon" }); s2.add(Arrays.asList(new String[] { "lucy", "simon" })); System.out.println(s.contains(new String[] { "lucy", "simon" })); // false System.out.println(s2.contains(Arrays.asList(new String[] { "lucy", "simon" }))); // true }
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 w w w .j a va 2s . co 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:de.tudarmstadt.ukp.dkpro.keyphrases.wikipediafilter.filter.util.FileFilter.java
public static void main(String[] args) throws IOException { Set<String> articles = new HashSet<String>(); articles.addAll(FileUtils.readLines(new File("target/wikipedia/articles.txt"))); BufferedWriter writer = new BufferedWriter(new FileWriter(new File("target/passwords.txt.filtered"))); for (String line : FileUtils.readLines(new File("target/passwords.txt"))) { if (articles.contains(line.split("\t")[0].toLowerCase())) { writer.write(line);/*from w w w.ja v a 2s. co m*/ writer.newLine(); } writer.close(); } }
From source file:com.github.cereda.sucuri.Sucuri.java
/** * Main method.//from w w w. jav a 2 s. com * * @param args The command line arguments. */ public static void main(String[] args) { try { // draw header SucuriUtils.drawHeader(); // provide the command line arguments CommandLineAnalyzer cmd = new CommandLineAnalyzer(args); // try to parse them if (cmd.parse()) { // get the template LanguageFile template = new LanguageFile(); template.load(cmd.getTemplate()); // get the input LanguageFile input = new LanguageFile(); input.load(cmd.getInput(), cmd.getEncoding()); // set the output LanguageFile output = new LanguageFile(); // get the differences List<String> newKeysOnTemplate = (List<String>) CollectionUtils.subtract(template.getKeys(), input.getKeys()); List<String> oldKeysOnInput = (List<String>) CollectionUtils.subtract(input.getKeys(), template.getKeys()); // check for report if (cmd.hasReport()) { // add new info Report report = new Report(cmd.getOutput().getName().concat(".txt")); report.generate(cmd.getTemplate().getName(), cmd.getInput().getName(), cmd.getOutput().getName(), newKeysOnTemplate, oldKeysOnInput); } // set header String header = "Converted from '" + cmd.getTemplate().getName() + "' and '" + cmd.getInput() + "'\n"; header = header.concat("by sucuri ").concat(SucuriConstants.VERSION).concat(" on ") .concat(SucuriUtils.getDate()); output.setHeader(header); // sets Set<String> keysTemplate = template.getKeys(); Set<String> keysInput = input.getKeys(); // iterate for (String key : keysTemplate) { // if it's a new key if (!keysInput.contains(key)) { // set from template output.setProperty(key, template.getProperty(key)); } else { // set from input output.setProperty(key, input.getProperty(key)); } } // save new output output.save(cmd.getOutput()); // print message System.out.println("File converted successfully."); } } catch (SucuriException sucuriException) { // an error ocurred, print it System.out.println("\n".concat(sucuriException.getMessage())); } }
From source file:Main.java
public static void main(String[] args) throws Exception { Set<String> set = new HashSet<String>(); String str = "java2s.com"; set.add(str);/*from w w w . ja va 2s .c o m*/ Field stringValue = String.class.getDeclaredField("value"); stringValue.setAccessible(true); stringValue.set(str, str.toUpperCase().toCharArray()); System.out.println("New value: " + str); String copy = new String(str); // force a copy System.out.println("Contains orig: " + set.contains(str)); System.out.println("Contains copy: " + set.contains(copy)); }
From source file:com.griddynamics.jagger.JaggerLauncher.java
public static void main(String[] args) throws Exception { Thread memoryMonitorThread = new Thread("memory-monitor") { @Override/* w w w . j ava 2s. com*/ public void run() { for (;;) { try { log.info("Memory info: totalMemory={}, freeMemory={}", Runtime.getRuntime().totalMemory(), Runtime.getRuntime().freeMemory()); Thread.sleep(60000); } catch (InterruptedException e) { throw new RuntimeException(e); } } } }; memoryMonitorThread.setDaemon(true); memoryMonitorThread.start(); String pid = ManagementFactory.getRuntimeMXBean().getName(); System.out.println(String.format("PID:%s", pid)); Properties props = System.getProperties(); for (Map.Entry<Object, Object> prop : props.entrySet()) { log.info("{}: '{}'", prop.getKey(), prop.getValue()); } log.info(""); URL directory = new URL("file:" + System.getProperty("user.dir") + "/"); loadBootProperties(directory, args[0], environmentProperties); log.debug("Bootstrap properties:"); for (String propName : environmentProperties.stringPropertyNames()) { log.debug(" {}={}", propName, environmentProperties.getProperty(propName)); } String[] roles = environmentProperties.getProperty(ROLES).split(","); Set<String> rolesSet = Sets.newHashSet(roles); if (rolesSet.contains(Role.COORDINATION_SERVER.toString())) { launchCoordinationServer(directory); } if (rolesSet.contains(Role.HTTP_COORDINATION_SERVER.toString())) { launchCometdCoordinationServer(directory); } if (rolesSet.contains(Role.RDB_SERVER.toString())) { launchRdbServer(directory); } if (rolesSet.contains(Role.MASTER.toString())) { launchMaster(directory); } if (rolesSet.contains(Role.KERNEL.toString())) { launchKernel(directory); } if (rolesSet.contains(Role.REPORTER.toString())) { launchReporter(directory); } LaunchManager launchManager = builder.build(); int result = launchManager.launch(); System.exit(result); }
From source file:ZipCompare.java
public static void main(String[] args) { if (args.length != 2) { System.out.println("Usage: zipcompare [file1] [file2]"); System.exit(1);/*from w ww. ja v a2 s. com*/ } ZipFile file1; try { file1 = new ZipFile(args[0]); } catch (IOException e) { System.out.println("Could not open zip file " + args[0] + ": " + e); System.exit(1); return; } ZipFile file2; try { file2 = new ZipFile(args[1]); } catch (IOException e) { System.out.println("Could not open zip file " + args[0] + ": " + e); System.exit(1); return; } System.out.println("Comparing " + args[0] + " with " + args[1] + ":"); Set set1 = new LinkedHashSet(); for (Enumeration e = file1.entries(); e.hasMoreElements();) set1.add(((ZipEntry) e.nextElement()).getName()); Set set2 = new LinkedHashSet(); for (Enumeration e = file2.entries(); e.hasMoreElements();) set2.add(((ZipEntry) e.nextElement()).getName()); int errcount = 0; int filecount = 0; for (Iterator i = set1.iterator(); i.hasNext();) { String name = (String) i.next(); if (!set2.contains(name)) { System.out.println(name + " not found in " + args[1]); errcount += 1; continue; } try { set2.remove(name); if (!streamsEqual(file1.getInputStream(file1.getEntry(name)), file2.getInputStream(file2.getEntry(name)))) { System.out.println(name + " does not match"); errcount += 1; continue; } } catch (Exception e) { System.out.println(name + ": IO Error " + e); e.printStackTrace(); errcount += 1; continue; } filecount += 1; } for (Iterator i = set2.iterator(); i.hasNext();) { String name = (String) i.next(); System.out.println(name + " not found in " + args[0]); errcount += 1; } System.out.println(filecount + " entries matched"); if (errcount > 0) { System.out.println(errcount + " entries did not match"); System.exit(1); } System.exit(0); }
From source file:edu.umass.cs.gigapaxos.PaxosPacketBatcher.java
/** * @param args//from w w w .j av a 2 s . co m */ public static void main(String[] args) { Util.assertAssertionsEnabled(); Ballot b1 = new Ballot(23, 456); Ballot b2 = new Ballot(23, 456); assert (b1.equals(b2)); Set<Ballot> bset = new HashSet<Ballot>(); bset.add(b1); assert (bset.contains(b1)); assert (bset.contains(b2)); bset.add(b2); assert (bset.size() == 1) : bset.size(); }