Example usage for java.util HashSet HashSet

List of usage examples for java.util HashSet HashSet

Introduction

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

Prototype

public HashSet() 

Source Link

Document

Constructs a new, empty set; the backing HashMap instance has default initial capacity (16) and load factor (0.75).

Usage

From source file:de.citec.csra.elancsv.parser.SimpleParser.java

public static void main(String[] args) throws IOException, ParseException {

    Options opts = new Options();
    opts.addOption("file", true, "Tab-separated ELAN export file to load.");
    opts.addOption("tier", true,
            "Tier to analyze. Optional: Append ::num to interpret annotations numerically.");
    opts.addOption("format", true,
            "How to read information from the file name. %V -> participant, %A -> annoatator, %C -> condition, e.g. \"%V - %A\"");
    opts.addOption("help", false, "Print this help and exit");

    CommandLineParser parser = new BasicParser();
    CommandLine cmd = parser.parse(opts, args);
    if (cmd.hasOption("help")) {
        helpExit(opts, "where OPTION includes:");
    }/*from w  w  w.ja va 2  s.c  o  m*/

    String infile = cmd.getOptionValue("file");
    if (infile == null) {
        helpExit(opts, "Error: no file given.");
    }

    String format = cmd.getOptionValue("format");
    if (format == null) {
        helpExit(opts, "Error: no format given.");
    }

    String tier = cmd.getOptionValue("tier");
    if (tier == null) {
        helpExit(opts, "Error: no tier given.");
    }

    //      TODO count values in annotations (e.g. search all robot occurrences)
    String[] tn = tier.split("::");
    boolean numeric = false;
    if (tn.length == 2 && tn[1].equals("num")) {
        numeric = true;
        tier = tn[0];
    }

    format = "^" + format + "$";
    format = format.replaceFirst("%V", "(?<V>.*?)");
    format = format.replaceFirst("%A", "(?<A>.*?)");
    format = format.replaceFirst("%C", "(?<C>.*?)");
    Pattern pa = Pattern.compile(format);

    Map<String, Participant> participants = new HashMap<>();
    BufferedReader br = new BufferedReader(new FileReader(infile));
    String line;
    int lineno = 0;
    while ((line = br.readLine()) != null) {
        String[] parts = line.split("\t");
        lineno++;
        if (parts.length < 5) {
            System.err.println("WARNING: line '" + lineno + "' too short '" + line + "'");
            continue;
        }
        Annotation a = new Annotation(Long.valueOf(parts[ElanFormat.START.field]),
                Long.valueOf(parts[ElanFormat.STOP.field]), Long.valueOf(parts[ElanFormat.DURATION.field]),
                parts[ElanFormat.VALUE.field]);
        String tname = parts[ElanFormat.TIER.field];
        String file = parts[ElanFormat.FILE.field].replaceAll(".eaf", "");

        Matcher m = pa.matcher(file);
        String vp = file;
        String condition = "?";
        String annotator = "?";
        String participantID = vp;

        if (m.find()) {
            vp = m.group("V");
            if (format.indexOf("<A>") > 0) {
                annotator = m.group("A");
            }

            if (format.indexOf("<C>") > 0) {
                condition = m.group("C");
            }
        }
        participantID = vp + ";" + annotator;

        if (!participants.containsKey(participantID)) {
            participants.put(participantID, new Participant(vp, condition, annotator));
        }
        Participant p = participants.get(participantID);

        if (!p.tiers.containsKey(tname)) {
            p.tiers.put(tname, new Tier(tname));
        }

        p.tiers.get(tname).annotations.add(a);

    }

    Map<String, Map<String, Number>> values = new HashMap<>();
    Set<String> rownames = new HashSet<>();

    String allCountKey = "c: all values";
    String allDurationKey = "d: all values";
    String allMeanKey = "m: all values";

    for (Map.Entry<String, Participant> e : participants.entrySet()) {
        //         System.out.println(e);
        Tier t = e.getValue().tiers.get(tier);
        String participantID = e.getKey();

        if (!values.containsKey(participantID)) {
            values.put(participantID, new HashMap<String, Number>());
        }
        Map<String, Number> row = values.get(participantID); //participant id

        if (t != null) {

            row.put(allCountKey, 0l);
            row.put(allDurationKey, 0l);
            row.put(allMeanKey, 0l);

            for (Annotation a : t.annotations) {

                long countAll = (long) row.get(allCountKey) + 1;
                long durationAll = (long) row.get(allDurationKey) + a.duration;
                long meanAll = durationAll / countAll;

                row.put(allCountKey, countAll);
                row.put(allDurationKey, durationAll);
                row.put(allMeanKey, meanAll);

                if (!numeric) {
                    String countKey = "c: " + a.value;
                    String durationKey = "d: " + a.value;
                    String meanKey = "m: " + a.value;

                    if (!row.containsKey(countKey)) {
                        row.put(countKey, 0l);
                    }
                    if (!row.containsKey(durationKey)) {
                        row.put(durationKey, 0l);
                    }
                    if (!row.containsKey(meanKey)) {
                        row.put(meanKey, 0d);
                    }

                    long count = (long) row.get(countKey) + 1;
                    long duration = (long) row.get(durationKey) + a.duration;
                    double mean = duration * 1.0 / count;

                    row.put(countKey, count);
                    row.put(durationKey, duration);
                    row.put(meanKey, mean);

                    rownames.add(countKey);
                    rownames.add(durationKey);
                    rownames.add(meanKey);
                } else {
                    String countKey = "c: " + t.name;
                    String sumKey = "s: " + t.name;
                    String meanKey = "m: " + t.name;

                    if (!row.containsKey(countKey)) {
                        row.put(countKey, 0l);
                    }
                    if (!row.containsKey(sumKey)) {
                        row.put(sumKey, 0d);
                    }
                    if (!row.containsKey(meanKey)) {
                        row.put(meanKey, 0d);
                    }

                    double d = 0;
                    try {
                        d = Double.valueOf(a.value);
                    } catch (NumberFormatException ex) {

                    }

                    long count = (long) row.get(countKey) + 1;
                    double sum = (double) row.get(sumKey) + d;
                    double mean = sum / count;

                    row.put(countKey, count);
                    row.put(sumKey, sum);
                    row.put(meanKey, mean);

                    rownames.add(countKey);
                    rownames.add(sumKey);
                    rownames.add(meanKey);
                }

            }
        }

    }

    ArrayList<String> list = new ArrayList(rownames);
    Collections.sort(list);
    StringBuilder header = new StringBuilder("ID;Annotator;");
    header.append(allCountKey);
    header.append(";");
    header.append(allDurationKey);
    header.append(";");
    header.append(allMeanKey);
    header.append(";");
    for (String l : list) {
        header.append(l);
        header.append(";");
    }
    System.out.println(header);

    for (Map.Entry<String, Map<String, Number>> e : values.entrySet()) {
        StringBuilder row = new StringBuilder(e.getKey());
        row.append(";");
        if (e.getValue().containsKey(allCountKey)) {
            row.append(e.getValue().get(allCountKey));
        } else {
            row.append("0");
        }
        row.append(";");
        if (e.getValue().containsKey(allDurationKey)) {
            row.append(e.getValue().get(allDurationKey));
        } else {
            row.append("0");
        }
        row.append(";");
        if (e.getValue().containsKey(allMeanKey)) {
            row.append(e.getValue().get(allMeanKey));
        } else {
            row.append("0");
        }
        row.append(";");
        for (String l : list) {
            if (e.getValue().containsKey(l)) {
                row.append(e.getValue().get(l));
            } else {
                row.append("0");
            }
            row.append(";");
        }
        System.out.println(row);
    }
}

From source file:com.lightboxtechnologies.spectrum.SequenceFileExport.java

public static void main(String[] args) throws Exception {
    final Configuration conf = new Configuration();

    final String[] otherArgs = new GenericOptionsParser(conf, args).getRemainingArgs();

    String imageID;/*from w  ww .ja v  a  2 s.com*/
    String outpath;
    String friendlyname;
    final Set<String> exts = new HashSet<String>();

    if ("-f".equals(otherArgs[0])) {
        if (otherArgs.length != 4) {
            die();
        }

        // load extensions from file
        final Path extpath = new Path(otherArgs[1]);

        InputStream in = null;
        try {
            in = extpath.getFileSystem(conf).open(extpath);

            Reader r = null;
            try {
                r = new InputStreamReader(in);

                BufferedReader br = null;
                try {
                    br = new BufferedReader(r);

                    String line;
                    while ((line = br.readLine()) != null) {
                        exts.add(line.trim().toLowerCase());
                    }

                    br.close();
                } finally {
                    IOUtils.closeQuietly(br);
                }

                r.close();
            } finally {
                IOUtils.closeQuietly(r);
            }

            in.close();
        } finally {
            IOUtils.closeQuietly(in);
        }

        imageID = otherArgs[2];
        friendlyname = otherArgs[3];
        outpath = otherArgs[4];
    } else {
        if (otherArgs.length < 3) {
            die();
        }

        // read extensions from trailing args
        imageID = otherArgs[0];
        friendlyname = otherArgs[1];
        outpath = otherArgs[2];

        // lowercase all file extensions
        for (int i = 2; i < otherArgs.length; ++i) {
            exts.add(otherArgs[i].toLowerCase());
        }
    }

    conf.setStrings("extensions", exts.toArray(new String[exts.size()]));

    final Job job = SKJobFactory.createJobFromConf(imageID, friendlyname, "SequenceFileExport", conf);
    job.setJarByClass(SequenceFileExport.class);
    job.setMapperClass(SequenceFileExportMapper.class);
    job.setNumReduceTasks(0);

    job.setOutputKeyClass(BytesWritable.class);
    job.setOutputValueClass(MapWritable.class);

    job.setInputFormatClass(FsEntryHBaseInputFormat.class);
    FsEntryHBaseInputFormat.setupJob(job, imageID);

    job.setOutputFormatClass(SequenceFileOutputFormat.class);
    SequenceFileOutputFormat.setOutputCompressionType(job, SequenceFile.CompressionType.BLOCK);

    FileOutputFormat.setOutputPath(job, new Path(outpath));
    System.exit(job.waitForCompletion(true) ? 0 : 1);
}

From source file:com.ibm.zurich.Main.java

public static void main(String[] args) throws NoSuchAlgorithmException, IOException {
    Option help = new Option(HELP, "print this message");
    Option version = new Option(VERSION, "print the version information");

    Options options = new Options();

    Option useCurve = Option.builder(USECURVE).hasArg().argName("curve")
            .desc("Specify the BN Curve. Options: " + curveOptions()).build();
    Option isskeygen = Option.builder(IKEYGEN).numberOfArgs(3).argName("ipk><isk><RL")
            .desc("Generate Issuer key pair and empty revocation list and store it in files").build();
    Option join1 = Option.builder(JOIN1).numberOfArgs(3).argName("ipk><authsk><msg1")
            .desc("Create an authenticator secret key and perform the first step of the join protocol").build();
    Option join2 = Option.builder(JOIN2).numberOfArgs(4).argName("ipk><isk><msg1><msg2")
            .desc("Complete the join protocol").build();
    Option verify = Option.builder(VERIFY).numberOfArgs(5).argName("ipk><sig><krd><appId><RL")
            .desc("Verify a signature").build();
    Option sign = Option.builder(SIGN).numberOfArgs(6).argName("ipk><authsk><msg2><appId><krd><sig")
            .desc("create a signature").build();

    options.addOption(help);/*from  w ww  . j  ava  2  s. co m*/
    options.addOption(version);
    options.addOption(useCurve);
    options.addOption(isskeygen);
    options.addOption(sign);
    options.addOption(verify);
    options.addOption(join1);
    options.addOption(join2);

    HelpFormatter formatter = new HelpFormatter();
    CommandLineParser parser = new DefaultParser();

    //FIXME Choose a proper instantiation of SecureRandom depending on the platform
    SecureRandom random = new SecureRandom();
    Base64.Encoder encoder = Base64.getUrlEncoder();
    Base64.Decoder decoder = Base64.getUrlDecoder();
    try {
        CommandLine line = parser.parse(options, args);
        BNCurveInstantiation instantiation = null;
        BNCurve curve = null;
        if (line.hasOption(HELP) || line.getOptions().length == 0) {
            formatter.printHelp(USAGE, options);
        } else if (line.hasOption(VERSION)) {
            System.out.println("Version " + Main.class.getPackage().getImplementationVersion());
        } else if (line.hasOption(USECURVE)) {
            instantiation = BNCurveInstantiation.valueOf(line.getOptionValue(USECURVE));
            curve = new BNCurve(instantiation);
        } else {
            System.out.println("Specify the curve to use.");
            return;
        }

        if (line.hasOption(IKEYGEN)) {
            String[] optionValues = line.getOptionValues(IKEYGEN);

            // Create secret key
            IssuerSecretKey sk = Issuer.createIssuerKey(curve, random);

            // Store pk
            writeToFile((new IssuerPublicKey(curve, sk, random)).toJSON(curve), optionValues[0]);

            // Store sk
            writeToFile(sk.toJson(curve), optionValues[1]);

            // Create empty revocation list and store
            HashSet<BigInteger> rl = new HashSet<BigInteger>();
            writeToFile(Verifier.revocationListToJson(rl, curve), optionValues[2]);
        } else if (line.hasOption(SIGN)) {
            //("ipk><authsk><msg2><appId><krd><sig")

            String[] optionValues = line.getOptionValues(SIGN);
            IssuerPublicKey ipk = new IssuerPublicKey(curve, readStringFromFile(optionValues[0]));

            BigInteger authsk = curve.bigIntegerFromB(decoder.decode(readFromFile(optionValues[1])));
            JoinMessage2 msg2 = new JoinMessage2(curve, readStringFromFile(optionValues[2]));

            // setup a new authenticator
            Authenticator auth = new Authenticator(curve, ipk, authsk);
            auth.EcDaaJoin1(curve.getRandomModOrder(random));
            if (auth.EcDaaJoin2(msg2)) {
                EcDaaSignature sig = auth.EcDaaSign(optionValues[3]);

                // Write krd to file
                writeToFile(sig.krd, optionValues[4]);

                // Write signature to file
                writeToFile(sig.encode(curve), optionValues[5]);

                System.out.println("Signature written to " + optionValues[5]);
            } else {
                System.out.println("JoinMsg2 invalid");
            }
        } else if (line.hasOption(VERIFY)) {
            Verifier ver = new Verifier(curve);
            String[] optionValues = line.getOptionValues(VERIFY);
            String pkFile = optionValues[0];
            String sigFile = optionValues[1];
            String krdFile = optionValues[2];
            String appId = optionValues[3];
            String rlPath = optionValues[4];
            byte[] krd = Files.readAllBytes(Paths.get(krdFile));
            IssuerPublicKey pk = new IssuerPublicKey(curve, readStringFromFile(pkFile));
            EcDaaSignature sig = new EcDaaSignature(Files.readAllBytes(Paths.get(sigFile)), krd, curve);
            boolean valid = ver.verify(sig, appId, pk,
                    Verifier.revocationListFromJson(readStringFromFile(rlPath), curve));
            System.out.println("Signature is " + (valid ? "valid." : "invalid."));
        } else if (line.hasOption(JOIN1)) {
            String[] optionValues = line.getOptionValues(JOIN1);
            IssuerPublicKey ipk = new IssuerPublicKey(curve, readStringFromFile(optionValues[0]));

            // Create authenticator key
            BigInteger sk = curve.getRandomModOrder(random);
            writeToFile(encoder.encodeToString(curve.bigIntegerToB(sk)), optionValues[1]);
            Authenticator auth = new Authenticator(curve, ipk, sk);
            JoinMessage1 msg1 = auth.EcDaaJoin1(curve.getRandomModOrder(random));
            writeToFile(msg1.toJson(curve), optionValues[2]);
        } else if (line.hasOption(JOIN2)) {
            String[] optionValues = line.getOptionValues(JOIN2);

            // create issuer with the specified key
            IssuerPublicKey pk = new IssuerPublicKey(curve, readStringFromFile(optionValues[0]));
            IssuerSecretKey sk = new IssuerSecretKey(curve, readStringFromFile(optionValues[1]));
            Issuer iss = new Issuer(curve, sk, pk);

            JoinMessage1 msg1 = new JoinMessage1(curve, readStringFromFile(optionValues[2]));

            // Note that we do not check for nonce freshness.
            JoinMessage2 msg2 = iss.EcDaaIssuerJoin(msg1, false);
            if (msg2 == null) {
                System.out.println("Join message invalid.");
            } else {
                System.out.println("Join message valid, msg2 written to file.");
                writeToFile(msg2.toJson(curve), optionValues[3]);
            }
        }
    } catch (ParseException e) {
        System.out.println("Error parsing input.");
        e.printStackTrace();
    } catch (NoSuchAlgorithmException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
}

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

/**
 * Main for running client code.//w  w  w  .jav  a 2 s  .  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");
    // 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:org.jaqpot.core.elastic.ElasticSearchWriter.java

License:asdf

public static void main(String... args) throws IOException {
    User u = UserBuilder.builder("jack.sparrow").setHashedPassword(UUID.randomUUID().toString())
            .setMail("jack.sparrow@gmail.com").setMaxBibTeX(17680).setMaxFeatures(12678).setMaxModels(9999)
            .setName("Jack Sparrow").setMaxSubstances(1000).setMaxWeeklyPublishedFeatures(345)
            .setMaxWeeklyPublishedModels(67).setMaxWeeklyPublishedSubstances(5).setMaxParallelTasks(10).build();

    //u.setId(null);

    BibTeX b = BibTeXBuilder.builder("WhaTevEr14").setAbstract("asdf").setAddress("sdfsdfsd")
            .setAnnotation("slkfsdlf").setAuthor("a").setBibType(BibTeX.BibTYPE.Article).setBookTitle("t6hdth")
            .setChapter("uthjsdfbkjs").setCopyright("sdfsdf").setCrossref("other").setEdition("234234")
            .setEditor("me").setISBN("23434234").setISSN("10010231230").setJournal("haha").setKey("lalala")
            .setKeywords("This is a set of keywords").setNumber("1").setPages("101-123")
            .setSeries("Some series").setTitle("Lololo").setURL("http://some.url.ch/").setVolume("100")
            .setYear("2010").build();

    ROG rog = new ROG(false);
    Model m = rog.nextModel();/*from w ww . j av a2s . c om*/
    m = new ModelMetaStripper(m).strip();

    Feature f = new Feature();
    f.setId("456");
    Set<String> ontClasses = new HashSet<>();
    ontClasses.add("ot:Feature");
    ontClasses.add("ot:NumericFeature");
    f.setOntologicalClasses(ontClasses);
    f.setMeta(MetaInfoBuilder.builder().addComments("this is a comment", "and a second one")
            .addTitles("My first feature", "a nice feature").addSubjects("feature of the day").build());
    f.setUnits("mJ");

    ElasticSearchWriter writer = new ElasticSearchWriter(b);
    InetSocketTransportAddress addrOpenTox = new InetSocketTransportAddress("147.102.82.32", 49101);
    InetSocketTransportAddress addrLocal = new InetSocketTransportAddress("localhost", 9300);
    writer.client = new TransportClient()
            //.addTransportAddress(addrLocal)
            .addTransportAddress(addrOpenTox);
    ObjectMapper om = new ObjectMapper();
    om.enable(SerializationFeature.INDENT_OUTPUT);
    writer.om = om;
    System.out.println("http://147.102.82.32:49234/jaqpot/"
            + XmlNameExtractor.extractName(writer.entity.getClass()) + "/" + writer.index());
}

From source file:com.act.lcms.db.io.PrintConstructInfo.java

public static void main(String[] args) throws Exception {
    Options opts = new Options();
    for (Option.Builder b : OPTION_BUILDERS) {
        opts.addOption(b.build());//from  w w w.j a va2s.  c o  m
    }

    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;
    }

    File lcmsDir = new File(cl.getOptionValue(OPTION_DIRECTORY));
    if (!lcmsDir.isDirectory()) {
        System.err.format("File at %s is not a directory\n", lcmsDir.getAbsolutePath());
        HELP_FORMATTER.printHelp(LoadPlateCompositionIntoDB.class.getCanonicalName(), HELP_MESSAGE, opts, null,
                true);
        System.exit(1);
    }

    try (DB db = DB.openDBFromCLI(cl)) {
        System.out.print("Loading/updating LCMS scan files into DB\n");
        ScanFile.insertOrUpdateScanFilesInDirectory(db, lcmsDir);

        String construct = cl.getOptionValue(OPTION_CONSTRUCT);
        List<LCMSWell> lcmsWells = LCMSWell.getInstance().getByConstructID(db, construct);
        Collections.sort(lcmsWells, new Comparator<LCMSWell>() {
            @Override
            public int compare(LCMSWell o1, LCMSWell o2) {
                return o1.getId().compareTo(o2.getId());
            }
        });

        Set<String> uniqueMSIDs = new HashSet<>();
        Map<Integer, Plate> platesById = new HashMap<>();

        System.out.format("\n\n-- Construct %s --\n\n", construct);

        List<ChemicalAssociatedWithPathway> pathwayChems = ChemicalAssociatedWithPathway.getInstance()
                .getChemicalsAssociatedWithPathwayByConstructId(db, construct);
        System.out.print("Chemicals associated with pathway:\n");
        System.out.format("  %-8s%-15s%-45s\n", "index", "kind", "chemical");
        for (ChemicalAssociatedWithPathway chem : pathwayChems) {
            System.out.format("  %-8d%-15s%-45s\n", chem.getIndex(), chem.getKind(), chem.getChemical());
        }

        System.out.print("\nLCMS wells:\n");
        System.out.format("  %-15s%-6s%-15s%-15s%-15s\n", "barcode", "well", "msid", "fed", "lcms_count");
        for (LCMSWell well : lcmsWells) {
            uniqueMSIDs.add(well.getMsid());

            Plate p = platesById.get(well.getPlateId());
            if (p == null) {
                // TODO: migrate Plate to be a subclass of BaseDBModel.
                p = Plate.getPlateById(db, well.getPlateId());
                platesById.put(p.getId(), p);
            }

            String chem = well.getChemical();
            List<ScanFile> scanFiles = ScanFile.getScanFileByPlateIDRowAndColumn(db, p.getId(),
                    well.getPlateRow(), well.getPlateColumn());

            System.out.format("  %-15s%-6s%-15s%-15s%-15d\n", p.getBarcode(), well.getCoordinatesString(),
                    well.getMsid(), chem == null || chem.isEmpty() ? "--" : chem, scanFiles.size());
            System.out.flush();
        }

        List<Integer> plateIds = Arrays.asList(platesById.keySet().toArray(new Integer[platesById.size()]));
        Collections.sort(plateIds);
        System.out.print("\nAppears in plates:\n");
        for (Integer id : plateIds) {
            Plate p = platesById.get(id);
            System.out.format("  %s: %s\n", p.getBarcode(), p.getName());
        }

        List<String> msids = Arrays.asList(uniqueMSIDs.toArray(new String[uniqueMSIDs.size()]));
        Collections.sort(msids);
        System.out.format("\nMSIDS: %s\n", StringUtils.join(msids, ", "));

        Set<String> availableNegativeControls = new HashSet<>();
        for (Map.Entry<Integer, Plate> entry : platesById.entrySet()) {
            List<LCMSWell> wells = LCMSWell.getInstance().getByPlateId(db, entry.getKey());
            for (LCMSWell well : wells) {
                if (!construct.equals(well.getComposition())) {
                    availableNegativeControls.add(well.getComposition());
                }
            }
        }

        // Print available standards for each step w/ plate barcodes and coordinates.
        System.out.format("\nAvailable Standards:\n");
        Map<Integer, Plate> plateCache = new HashMap<>();
        for (ChemicalAssociatedWithPathway chem : pathwayChems) {
            List<StandardWell> matchingWells = StandardWell.getInstance().getStandardWellsByChemical(db,
                    chem.getChemical());
            for (StandardWell well : matchingWells) {
                if (!plateCache.containsKey(well.getPlateId())) {
                    Plate p = Plate.getPlateById(db, well.getPlateId());
                    plateCache.put(p.getId(), p);
                }
            }
            Map<Integer, List<StandardWell>> standardWellsByPlateId = new HashMap<>();
            for (StandardWell well : matchingWells) {
                List<StandardWell> plateWells = standardWellsByPlateId.get(well.getPlateId());
                if (plateWells == null) {
                    plateWells = new ArrayList<>();
                    standardWellsByPlateId.put(well.getPlateId(), plateWells);
                }
                plateWells.add(well);
            }
            List<Pair<String, Integer>> plateBarcodes = new ArrayList<>(plateCache.size());
            for (Plate p : plateCache.values()) {
                if (p.getBarcode() == null) {
                    plateBarcodes.add(Pair.of("(no barcode)", p.getId()));
                } else {
                    plateBarcodes.add(Pair.of(p.getBarcode(), p.getId()));
                }
            }
            Collections.sort(plateBarcodes);
            System.out.format("  %s:\n", chem.getChemical());
            for (Pair<String, Integer> barcodePair : plateBarcodes) {
                // TODO: hoist this whole sorting/translation step into a utility class.
                List<StandardWell> wells = standardWellsByPlateId.get(barcodePair.getRight());
                if (wells == null) {
                    // Don't print plates that don't apply to this chemical, which can happen because we're caching the plates.
                    continue;
                }
                Collections.sort(wells, new Comparator<StandardWell>() {
                    @Override
                    public int compare(StandardWell o1, StandardWell o2) {
                        int c = o1.getPlateRow().compareTo(o2.getPlateRow());
                        if (c != 0)
                            return c;
                        return o1.getPlateColumn().compareTo(o2.getPlateColumn());
                    }
                });
                List<String> descriptions = new ArrayList<>(wells.size());
                for (StandardWell well : wells) {
                    descriptions.add(String.format("%s in %s%s", well.getCoordinatesString(), well.getMedia(),
                            well.getConcentration() == null ? ""
                                    : String.format(" c. %f", well.getConcentration())));
                }
                System.out.format("    %s: %s\n", barcodePair.getLeft(), StringUtils.join(descriptions, ", "));
            }
        }

        List<String> negativeControlStrains = Arrays
                .asList(availableNegativeControls.toArray(new String[availableNegativeControls.size()]));
        Collections.sort(negativeControlStrains);
        System.out.format("\nAvailable negative controls: %s\n", StringUtils.join(negativeControlStrains, ","));
        System.out.print("\n----------\n");
        System.out.print("\n\n");
    }
}

From source file:hyperloglog.tools.HyperLogLogCLI.java

public static void main(String[] args) {
    Options options = new Options();
    addOptions(options);/*from  ww  w  .jav  a2s  .co m*/

    CommandLineParser parser = new BasicParser();
    CommandLine cli = null;
    long n = 0;
    long seed = 123;
    EncodingType enc = EncodingType.SPARSE;
    int p = 14;
    int hb = 64;
    boolean bitPack = true;
    boolean noBias = true;
    int unique = -1;
    String filePath = null;
    BufferedReader br = null;
    String outFile = null;
    String inFile = null;
    FileOutputStream fos = null;
    DataOutputStream out = null;
    FileInputStream fis = null;
    DataInputStream in = null;
    try {
        cli = parser.parse(options, args);

        if (!(cli.hasOption('n') || cli.hasOption('f') || cli.hasOption('d'))) {
            System.out.println("Example usage: hll -n 1000 " + "<OR> hll -f /tmp/input.txt "
                    + "<OR> hll -d -i /tmp/out.hll");
            usage(options);
            return;
        }

        if (cli.hasOption('n')) {
            n = Long.parseLong(cli.getOptionValue('n'));
        }

        if (cli.hasOption('e')) {
            String value = cli.getOptionValue('e');
            if (value.equals(EncodingType.DENSE.name())) {
                enc = EncodingType.DENSE;
            }
        }

        if (cli.hasOption('p')) {
            p = Integer.parseInt(cli.getOptionValue('p'));
            if (p < 4 && p > 16) {
                System.out.println("Warning! Out-of-range value specified for p. Using to p=14.");
                p = 14;
            }
        }

        if (cli.hasOption('h')) {
            hb = Integer.parseInt(cli.getOptionValue('h'));
        }

        if (cli.hasOption('c')) {
            noBias = Boolean.parseBoolean(cli.getOptionValue('c'));
        }

        if (cli.hasOption('b')) {
            bitPack = Boolean.parseBoolean(cli.getOptionValue('b'));
        }

        if (cli.hasOption('f')) {
            filePath = cli.getOptionValue('f');
            br = new BufferedReader(new FileReader(new File(filePath)));
        }

        if (filePath != null && cli.hasOption('n')) {
            System.out.println("'-f' (input file) specified. Ignoring -n.");
        }

        if (cli.hasOption('s')) {
            if (cli.hasOption('o')) {
                outFile = cli.getOptionValue('o');
                fos = new FileOutputStream(new File(outFile));
                out = new DataOutputStream(fos);
            } else {
                System.err.println("Specify output file. Example usage: hll -s -o /tmp/out.hll");
                usage(options);
                return;
            }
        }

        if (cli.hasOption('d')) {
            if (cli.hasOption('i')) {
                inFile = cli.getOptionValue('i');
                fis = new FileInputStream(new File(inFile));
                in = new DataInputStream(fis);
            } else {
                System.err.println("Specify input file. Example usage: hll -d -i /tmp/in.hll");
                usage(options);
                return;
            }
        }

        // return after deserialization
        if (fis != null && in != null) {
            long start = System.currentTimeMillis();
            HyperLogLog deserializedHLL = HyperLogLogUtils.deserializeHLL(in);
            long end = System.currentTimeMillis();
            System.out.println(deserializedHLL.toString());
            System.out.println("Count after deserialization: " + deserializedHLL.count());
            System.out.println("Deserialization time: " + (end - start) + " ms");
            return;
        }

        // construct hll and serialize it if required
        HyperLogLog hll = HyperLogLog.builder().enableBitPacking(bitPack).enableNoBias(noBias).setEncoding(enc)
                .setNumHashBits(hb).setNumRegisterIndexBits(p).build();

        if (br != null) {
            Set<String> hashset = new HashSet<String>();
            String line;
            while ((line = br.readLine()) != null) {
                hll.addString(line);
                hashset.add(line);
            }
            n = hashset.size();
        } else {
            Random rand = new Random(seed);
            for (int i = 0; i < n; i++) {
                if (unique < 0) {
                    hll.addLong(rand.nextLong());
                } else {
                    int val = rand.nextInt(unique);
                    hll.addLong(val);
                }
            }
        }

        long estCount = hll.count();
        System.out.println("Actual count: " + n);
        System.out.println(hll.toString());
        System.out.println("Relative error: " + HyperLogLogUtils.getRelativeError(n, estCount) + "%");
        if (fos != null && out != null) {
            long start = System.currentTimeMillis();
            HyperLogLogUtils.serializeHLL(out, hll);
            long end = System.currentTimeMillis();
            System.out.println("Serialized hyperloglog to " + outFile);
            System.out.println("Serialized size: " + out.size() + " bytes");
            System.out.println("Serialization time: " + (end - start) + " ms");
            out.close();
        }
    } catch (ParseException e) {
        System.err.println("Invalid parameter.");
        usage(options);
    } catch (NumberFormatException e) {
        System.err.println("Invalid type for parameter.");
        usage(options);
    } catch (FileNotFoundException e) {
        System.err.println("Specified file not found.");
        usage(options);
    } catch (IOException e) {
        System.err.println("Exception occured while reading file.");
        usage(options);
    }
}

From source file:com.mfalaize.zipdiff.Main.java

/**
 * The command line interface to zipdiff utility
 *
 * @param args The command line parameters
 *//*from   ww  w  . j a  v  a 2s .  co m*/
public static void main(String[] args) {
    CommandLineParser parser = new DefaultParser();

    try {
        CommandLine line = parser.parse(options, args);

        String filename1;
        String filename2;

        filename1 = line.getOptionValue(OPTION_FILE1);
        filename2 = line.getOptionValue(OPTION_FILE2);

        File f1 = new File(filename1);
        File f2 = new File(filename2);

        checkFile(f1);
        checkFile(f2);

        System.out.println("File 1 = " + f1);
        System.out.println("File 2 = " + f2);

        DifferenceCalculator calc = new DifferenceCalculator(f1, f2);

        String regularExpression;

        // todo - calc.setFilenamesToIgnore();

        if (line.hasOption(OPTION_COMPARE_CRC_VALUES)) {
            calc.setCompareCRCValues(true);
        } else {
            calc.setCompareCRCValues(false);
        }

        if (line.hasOption(OPTION_IGNORE_CVS_FILES)) {
            calc.setIgnoreCVSFiles(true);
        } else {
            calc.setIgnoreCVSFiles(false);
        }

        if (line.hasOption(OPTION_COMPARE_TIMESTAMPS)) {
            calc.setIgnoreTimestamps(false);
        } else {
            calc.setIgnoreTimestamps(true);
        }

        if (line.hasOption(OPTION_REGEX)) {
            regularExpression = line.getOptionValue(OPTION_REGEX);
            Set<String> regexSet = new HashSet<String>();
            regexSet.add(regularExpression);

            calc.setFilenameRegexToIgnore(regexSet);
        }

        boolean exitWithErrorOnDiff = false;
        if (line.hasOption(OPTION_EXIT_WITH_ERROR_ON_DIFF)) {
            exitWithErrorOnDiff = true;
        }

        Differences d = calc.getDifferences();

        if (line.hasOption(OPTION_OUTPUT_FILE)) {
            String outputFilename = line.getOptionValue(OPTION_OUTPUT_FILE);
            writeOutputFile(outputFilename, d);
        }

        if (d.hasDifferences()) {
            if (line.hasOption(OPTION_VERBOSE)) {
                System.out.println(d);
                System.out.println(d.getFilename1() + " and " + d.getFilename2() + " are different.");
            }
            if (exitWithErrorOnDiff) {
                System.exit(EXITCODE_DIFF);
            }
        } else {
            System.out.println("No differences found.");
        }
    } catch (ParseException pex) {
        System.err.println(pex.getMessage());
        HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp("Main [options] ", options);
        System.exit(EXITCODE_ERROR);
    } catch (Exception ex) {
        ex.printStackTrace();
        System.exit(EXITCODE_ERROR);
    }

}

From source file:autocorrelator.apps.SDFGroovy.java

public static void main(String[] args) throws Exception {
    long start = System.currentTimeMillis();

    // create command line Options object
    Options options = new Options();
    Option opt = new Option("in", true, "input sd file");
    options.addOption(opt);//from   w ww.j  av  a 2  s. c om

    opt = new Option("out", true, "output file for return value true or null");
    options.addOption(opt);

    opt = new Option("falseOut", true, "output file for return value false");
    options.addOption(opt);

    opt = new Option("c", true, "groovy script line");
    options.addOption(opt);

    opt = new Option("f", true, "groovy script file");
    options.addOption(opt);

    opt = new Option("exception", true, "exception handling (Default: stop)");
    options.addOption(opt);

    opt = new Option("h", false, "print help message");
    options.addOption(opt);

    CommandLineParser parser = new BasicParser();
    CommandLine cmd = null;
    try {
        cmd = parser.parse(options, args);
    } catch (Exception e) {
        exitWithHelp(e.getMessage(), options);
    }
    if (!cmd.hasOption("c") && !cmd.hasOption("f"))
        exitWithHelp("-c or -f must be given!", options);

    if (cmd.hasOption("c") && cmd.hasOption("f"))
        exitWithHelp("Only one of -c or -f may be given!", options);

    String groovyStrg;
    if (cmd.hasOption("c"))
        groovyStrg = cmd.getOptionValue("c");
    else
        groovyStrg = fileToString(cmd.getOptionValue("f"));

    Set<String> inFileds = new HashSet<String>();
    Set<String> outFields = new HashSet<String>();
    Script script = getGroovyScript(groovyStrg, inFileds, outFields);

    if (cmd.hasOption("h")) {
        callScriptHelp(script);
        exitWithHelp("", options);
    }

    if (!cmd.hasOption("in") || !cmd.hasOption("out")) {
        callScriptHelp(script);
        exitWithHelp("-in and -out must be given", options);
    }

    String[] scriptArgs = cmd.getArgs();
    String inFile = cmd.getOptionValue("in");
    String outFile = cmd.getOptionValue("out");
    String falseOutFile = cmd.getOptionValue("falseOut");
    EXCEPTIONHandling eHandling = EXCEPTIONHandling.stop;
    if (cmd.hasOption("exception"))
        eHandling = EXCEPTIONHandling.getByName(cmd.getOptionValue("exception"));

    callScriptInit(script, scriptArgs);

    oemolistream ifs = new oemolistream(inFile);
    oemolostream ofs = new oemolostream(outFile);
    oemolostream falseOFS = null;
    if (falseOutFile != null)
        falseOFS = new oemolostream(falseOutFile);

    OEMolBase mol = new OEGraphMol();

    int iCounter = 0;
    int oCounter = 0;
    int foCounter = 0;
    while (oechem.OEReadMolecule(ifs, mol)) {
        iCounter++;

        Binding binding = getFieldBindings(mol, inFileds, outFields);

        script.setBinding(binding);
        boolean printToTrue = true;
        boolean printToFalse = true;
        try {
            Object ret = script.run();
            if (ret == null || !(ret instanceof Boolean)) {
                printToFalse = false;
            } else if (((Boolean) ret).booleanValue()) {
                printToFalse = false;
            } else // ret = false
            {
                printToTrue = false;
            }

            setOutputFields(mol, binding, outFields);
        } catch (Exception e) {
            switch (eHandling) {
            case stop:
                throw e;
            case printToTrue:
                printToFalse = false;
                System.err.println(e.getMessage());
                break;
            case printToFalse:
                printToTrue = false;
                System.err.println(e.getMessage());
                break;
            case dropRecord:
                printToTrue = false;
                printToFalse = false;
                System.err.println(e.getMessage());
                break;
            default:
                assert false;
                break;
            }
        }

        if (printToTrue) {
            oechem.OEWriteMolecule(ofs, mol);
            oCounter++;
        }
        if (falseOFS != null && printToFalse) {
            oechem.OEWriteMolecule(falseOFS, mol);
            foCounter++;
        }
    }

    System.err.printf("SDFGroovy: Input %d, output %d,%d structures in %dsec\n", iCounter, oCounter, foCounter,
            (System.currentTimeMillis() - start) / 1000);

    if (falseOFS != null)
        falseOFS.close();
    ofs.close();
    ifs.close();
    mol.delete();
}

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;//  w  w w  .java  2  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("_________________________________________________");
    }
}