Example usage for java.util Set add

List of usage examples for java.util Set add

Introduction

In this page you can find the example usage for java.util Set add.

Prototype

boolean add(E e);

Source Link

Document

Adds the specified element to this set if it is not already present (optional operation).

Usage

From source file:com.joliciel.jochre.search.JochreSearch.java

/**
 * @param args// 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:dhbw.clippinggorilla.external.twitter.TwitterUtils.java

public static void main(String[] args) {
    Set<String> includedTagsSet = new HashSet<>();
    Set<String> excludedTagsSet = new HashSet<>();
    LocalDateTime date;//from  ww  w. j  a va2 s .  c om

    includedTagsSet.add("bmw, mercedes");
    includedTagsSet.add("Audi, toyota");
    includedTagsSet.add("merkel");
    includedTagsSet.add("dat boi, pepe");
    includedTagsSet.add("dhbw");
    includedTagsSet.add("VW Golf");

    Query query = queryBuilder(includedTagsSet, LocalDateTime.of(2017, 5, 1, 0, 0));

    QueryResult result = searchTweets(query);

    for (Status status : result.getTweets()) {
        System.out.println("@" + status.getUser().getScreenName() + ":" + status.getText());
        for (MediaEntity mediaEntity : status.getMediaEntities()) {
            System.out.println(mediaEntity.getType());
        }
        System.out.println("_________________________________________________");
    }
}

From source file:edu.ucdenver.ccp.nlp.ae.dict_util.OboToDictionary.java

public static void main(String args[]) {

        BasicConfigurator.configure();//ww  w  . ja  va  2  s.co  m

        if (args.length < 2) {
            usage();
        } else {
            try {
                File oboFile = new File(args[0]);
                File outputFile = new File(args[1]);
                String namespaceName = "";
                if (args.length > 2) {
                    namespaceName = args[2];
                }
                if (!oboFile.canRead()) {
                    System.out.println("can't read input file;" + oboFile.getAbsolutePath());
                    usage();
                    System.exit(-2);
                }
                if (outputFile.exists() && !outputFile.canWrite()) {
                    System.out.println("can't write output file;" + outputFile.getAbsolutePath());
                    usage();
                    System.exit(-3);
                }

                logger.warn("running with: " + oboFile.getAbsolutePath());
                OboToDictionary converter = null;
                if (namespaceName != null && namespaceName.length() > 0) {
                    Set<String> namespaceSet = new TreeSet<String>();
                    namespaceSet.add(namespaceName);
                    converter = new OboToDictionary(true, SynonymType.EXACT_ONLY, namespaceSet);
                } else {
                    converter = new OboToDictionary();
                }
                converter.convert(oboFile, outputFile);
            } catch (Exception e) {
                System.out.println("error:" + e);
                e.printStackTrace();
                System.exit(-1);
            }
        }
    }

From source file:com.wrmsr.nativity.x86.App.java

public static void main(String[] args) throws Exception {
    logger.info("hi");

    Document doc;/*from www .ja v  a2 s  . c  om*/
    try (InputStream is = App.class.getClassLoader().getResourceAsStream("x86reference.xml")) {
        DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
        dbFactory.setFeature("http://apache.org/xml/features/nonvalidating/load-dtd-grammar", false);
        dbFactory.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false);
        DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
        doc = dBuilder.parse(is);
    }

    //optional, but recommended
    //read this - http://stackoverflow.com/questions/13786607/normalization-in-dom-parsing-with-java-how-does-it-work
    doc.getDocumentElement().normalize();

    List<Ref.Entry> entries = Lists.newArrayList();
    Ref.Parsing.parseRoot(doc, entries);
    ByteTrie<Ref.Entry> trie = DisImpl.buildTrie(entries);

    System.out.println(trie.toDetailedString());
    System.out.println();
    System.out.println();

    // Dis.run(trie);

    Ordering<Pair<Ref.Operand.Type, Ref.Operand.Address>> ord = Ordering.from((o1, o2) -> {
        int c = ObjectUtils.compare(o1.getLeft(), o2.getLeft());
        if (c == 0) {
            c = ObjectUtils.compare(o1.getRight(), o2.getRight());
        }
        return c;
    });

    Set<Pair<Ref.Operand.Type, Ref.Operand.Address>> set = Sets.newHashSet();
    for (Ref.Entry entry : entries) {
        for (Ref.Syntax syntax : entry.getSyntaxes()) {
            for (Ref.Operand operand : syntax.getOperands()) {
                set.add(new ImmutablePair<>(operand.type, operand.address));
            }
        }
    }
    for (Pair<Ref.Operand.Type, Ref.Operand.Address> pair : ord.sortedCopy(set)) {
        System.out.println(pair);
    }
    System.out.println("\n");

    DisImpl.run(trie);
}

From source file:com.github.brandtg.switchboard.FileLogAggregator.java

/** Main. */
public static void main(String[] args) throws Exception {
    Options opts = new Options();
    opts.addOption("h", "help", false, "Prints help message");
    opts.addOption("f", "file", true, "File to output aggregated logs to");
    opts.addOption("s", "separator", true, "Line separator in log");
    CommandLine cli = new GnuParser().parse(opts, args);

    if (cli.getArgs().length == 0 || cli.hasOption("help")) {
        new HelpFormatter().printHelp("usage: [opts] sourceHost:port ...", opts);
        System.exit(1);/*from   w w w .j a v a2 s. c o m*/
    }

    // Parse sources
    Set<InetSocketAddress> sources = new HashSet<>();
    for (int i = 0; i < cli.getArgs().length; i++) {
        String[] tokens = cli.getArgs()[i].split(":");
        sources.add(new InetSocketAddress(tokens[0], Integer.valueOf(tokens[1])));
    }

    // Parse output stream
    OutputStream outputStream;
    if (cli.hasOption("file")) {
        outputStream = new FileOutputStream(cli.getOptionValue("file"));
    } else {
        outputStream = System.out;
    }

    // Separator
    String separator = cli.getOptionValue("separator", "\n");
    if (separator.length() != 1) {
        throw new IllegalArgumentException("Separator must only be 1 character");
    }

    final FileLogAggregator fileLogAggregator = new FileLogAggregator(sources, separator.charAt(0),
            outputStream);

    Runtime.getRuntime().addShutdownHook(new Thread() {
        @Override
        public void run() {
            try {
                fileLogAggregator.stop();
            } catch (Exception e) {
                LOG.error("Error when stopping log aggregator", e);
            }
        }
    });

    fileLogAggregator.start();
}

From source file:org.switchyard.quickstarts.demo.policy.security.wss.signencrypt.WorkServiceMain.java

public static void main(String... args) throws Exception {
    Set<String> policies = new HashSet<String>();
    for (String arg : args) {
        arg = Strings.trimToNull(arg);/*from  w ww  .  j  a  va  2 s .com*/
        if (arg != null) {
            if (arg.equals(CONFIDENTIALITY) || arg.equals(SIGNENCRYPT) || 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)) {
            scheme = "https";
            port = getPort(8443);
            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 = getPort(8080);
        }
        boolean signencrypt = policies.contains(SIGNENCRYPT);
        invokeWorkService(scheme, port, getContext(), signencrypt);
    }
}

From source file:org.switchyard.quickstarts.demo.policy.security.basic.propagate.WorkServiceMain.java

public static void main(String... args) throws Exception {
    Set<String> policies = new HashSet<String>();
    for (String arg : args) {
        arg = Strings.trimToNull(arg);// www.jav  a2  s.com
        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)) {
            scheme = "https";
            port = 8443;
            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;
        }
        String[] userPass = policies.contains(CLIENT_AUTHENTICATION) ? new String[] { "kermit", "the-frog-1" }
                : null;
        invokeWorkService(scheme, port, userPass);
    }
}

From source file:org.switchyard.quickstarts.demo.security.propagation.jms.WorkServiceMain.java

public static void main(String... args) throws Exception {
    Set<String> policies = new HashSet<String>();
    for (String arg : args) {
        arg = Strings.trimToNull(arg);//from w  ww .  ja  va2 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)) {
            scheme = "https";
            port = getPort(8443);
            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 = getPort(8080);
        }
        String[] userPass = policies.contains(CLIENT_AUTHENTICATION) ? new String[] { "kermit", "the-frog-1" }
                : null;
        invokeWorkService(scheme, port, getContext(), userPass);
    }
}

From source file:com.netflix.genie.client.sample.CommandServiceSampleClient.java

/**
 * Main for running client code.//  ww  w.  j  a v a  2s . 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:Main.java

  public static void main(String[] argv) throws Exception {
  Set result = new HashSet();
  String serviceType = "KeyFactory";
  Provider[] providers = Security.getProviders();
  for (int i = 0; i < providers.length; i++) {
    Set keys = providers[i].keySet();
    for (Iterator it = keys.iterator(); it.hasNext();) {
      String key = (String) it.next();
      key = key.split(" ")[0];

      if (key.startsWith(serviceType + ".")) {
        result.add(key.substring(serviceType.length() + 1));
      } else if (key.startsWith("Alg.Alias." + serviceType + ".")) {
        result.add(key.substring(serviceType.length() + 11));
      }//from ww  w .j av  a2  s  .co  m
    }
  }
  System.out.println(result);
}