Example usage for org.apache.commons.cli Options Options

List of usage examples for org.apache.commons.cli Options Options

Introduction

In this page you can find the example usage for org.apache.commons.cli Options Options.

Prototype

Options

Source Link

Usage

From source file:com.adobe.aem.demomachine.Updates.java

public static void main(String[] args) {

    String rootFolder = null;//from   w w w  .j  av  a  2  s.com

    // Command line options for this tool
    Options options = new Options();
    options.addOption("f", true, "Demo Machine root folder");
    CommandLineParser parser = new BasicParser();
    try {
        CommandLine cmd = parser.parse(options, args);

        if (cmd.hasOption("f")) {
            rootFolder = cmd.getOptionValue("f");
        }

    } catch (Exception e) {
        System.exit(-1);
    }

    Properties md5properties = new Properties();

    try {
        URL url = new URL(
                "https://raw.githubusercontent.com/Adobe-Marketing-Cloud/aem-demo-machine/master/conf/checksums.properties");
        InputStream in = url.openStream();
        Reader reader = new InputStreamReader(in, "UTF-8");
        md5properties.load(reader);
        reader.close();
    } catch (Exception e) {
        System.out.println("Error: Cannot connect to GitHub.com to check for updates");
        System.exit(-1);
    }

    System.out.println(AemDemoConstants.HR);

    int nbUpdateAvailable = 0;

    List<String[]> listPaths = Arrays.asList(AemDemoConstants.demoPaths);
    for (String[] path : listPaths) {
        if (path.length == 5) {
            logger.debug(path[1]);
            File pathFolder = new File(rootFolder + (path[1].length() > 0 ? (File.separator + path[1]) : ""));
            if (pathFolder.exists()) {
                String newMd5 = AemDemoUtils.calcMD5HashForDir(pathFolder, Boolean.parseBoolean(path[3]),
                        false);
                logger.debug("MD5 is: " + newMd5);
                String oldMd5 = md5properties.getProperty("demo.md5." + path[0]);
                if (oldMd5 == null || oldMd5.length() == 0) {
                    logger.error("Cannot find MD5 for " + path[0]);
                    System.out.println(path[2] + " : Cannot find M5 checksum");
                    continue;
                }
                if (newMd5.equals(oldMd5)) {
                    continue;
                } else {
                    System.out.println(path[2] + " : New update available"
                            + (path[0].equals("0") ? " (use 'git pull' to get the latest changes)" : ""));
                    nbUpdateAvailable++;
                }
            } else {
                System.out.println(path[2] + " : Not installed");
            }
        }
    }

    if (nbUpdateAvailable == 0) {
        System.out.println("Your AEM Demo Machine is up to date!");
    }

    System.out.println(AemDemoConstants.HR);

}

From source file:examples.grid.evolutionDistributed.ServerAndWorker.java

/**
 * Convenience (demo) start of both the server and a worker.
 *
 * @param args might not work here in this simple example as distinct options
 * between server and worker could lead to parsing errors.
 *
 * @throws Exception//from w ww .j av  a2s.  c  o m
 *
 * @author Klaus Meffert
 * @since 3.2
 */
public static void main(String[] args) throws Exception {
    // Start server.
    // ------------
    new JGAPServer(args);
    // Setup worker configuration.
    // ---------------------------
    Options options = new Options();
    GridNodeWorkerConfig config = new GridNodeWorkerConfig();
    CommandLine cmd = MainCmd.parseCommonOptions(options, config, args);
    // Start worker.
    // -------------
    new JGAPWorkers(config);
}

From source file:com.aestel.chemistry.openEye.fp.apps.SDFFPSphereExclusion.java

public static void main(String... args) throws IOException { // create command line Options object
    Options options = new Options();
    Option opt = new Option("in", true, "input file [.sdf,...]");
    opt.setRequired(true);/*from www.  j  av a  2 s  . c o m*/
    options.addOption(opt);

    opt = new Option("out", true, "output file oe-supported");
    opt.setRequired(false);
    options.addOption(opt);

    opt = new Option("ref", true, "refrence file to be loaded before starting");
    opt.setRequired(false);
    options.addOption(opt);

    opt = new Option("fpTag", true, "field containing fingerpPrint");
    opt.setRequired(true);
    options.addOption(opt);

    opt = new Option("maxTanimoto", false,
            "If given the modified maxTanimoto will be used = common/(2*Max(na,nb)-common).");
    opt.setRequired(false);
    options.addOption(opt);

    opt = new Option("radius", true, "radius of exclusion sphere, exclude anything with similarity >= radius.");
    opt.setRequired(true);
    options.addOption(opt);

    opt = new Option("printSphereMatchCount", false,
            "check and print membership of candidates not "
                    + " only to the first centroid which has sim >= radius but to all centroids"
                    + " found up to that input. This will output a candidate multiple times."
                    + " Implies checkSpheresInOrder.");
    options.addOption(opt);

    opt = new Option("checkSpheresInOrder", false,
            "For each candiate: compare to centroids from first to last (default is last to first)");
    options.addOption(opt);

    opt = new Option("printAll", false, "print all molecule, check includeIdx tag");
    options.addOption(opt);

    CommandLineParser parser = new PosixParser();
    CommandLine cmd = null;
    try {
        cmd = parser.parse(options, args);
    } catch (Exception e) {
        System.err.println(e.getMessage());
        exitWithHelp(options);
    }
    args = cmd.getArgs();

    if (cmd.hasOption("d")) {
        System.err.println("Start debugger and press return:");
        new BufferedReader(new InputStreamReader(System.in)).readLine();
    }

    // the only reason not to match centroids in reverse order id if
    // a non-centroid is to be assigned to multiple centroids
    boolean printSphereMatchCount = cmd.hasOption("printSphereMatchCount");
    boolean reverseMatch = !cmd.hasOption("checkSpheresInOrder") && !printSphereMatchCount;
    boolean printAll = cmd.hasOption("printAll") || printSphereMatchCount;
    boolean doMaxTanimoto = cmd.hasOption("maxTanimoto");
    String fpTag = cmd.getOptionValue("fpTag");
    double radius = Double.parseDouble(cmd.getOptionValue("radius"));
    String inFile = cmd.getOptionValue("in");
    String outFile = cmd.getOptionValue("out");
    String refFile = cmd.getOptionValue("ref");

    SimComparatorFactory<OEMolBase, FPComparator, FPComparator> compFact = new FPComparatorFact(doMaxTanimoto,
            fpTag);
    SphereExclusion<FPComparator, FPComparator> alg = new SphereExclusion<FPComparator, FPComparator>(compFact,
            refFile, outFile, radius, reverseMatch, printSphereMatchCount, printAll);
    alg.run(inFile);
    alg.close();
}

From source file:com.quanticate.opensource.pdftkbox.PDFtkBox.java

public static void main(String[] args) throws Exception {
    // For printing help
    Options optsHelp = new Options();
    optsHelp.addOption(Option.builder("help").required().desc("print this message").build());

    // Normal-style import/export
    Options optsNormal = new Options();
    OptionGroup normal = new OptionGroup();
    Option optExport = Option.builder("export").required().hasArg().desc("export bookmarks from pdf")
            .argName("source-pdf").build();
    normal.addOption(optExport);/* w  w w .  j  a  v  a2 s.c  om*/
    Option optImport = Option.builder("import").required().hasArg().desc("import bookmarks into pdf")
            .argName("source-pdf").build();
    normal.addOption(optImport);
    optsNormal.addOptionGroup(normal);
    Option optBookmarks = Option.builder("bookmarks").hasArg().desc("bookmarks definition file")
            .argName("bookmarks").build();
    optsNormal.addOption(optBookmarks);
    Option optOutput = Option.builder("output").hasArg().desc("output to new pdf").argName("pdf").build();
    optsNormal.addOption(optOutput);

    // PDFtk style options
    Options optsPDFtk = new Options();
    OptionGroup pdftk = new OptionGroup();
    Option optDumpData = Option.builder("dump_data").required().desc("dump bookmarks from pdf").build();
    pdftk.addOption(optDumpData);
    Option optUpdateInfo = Option.builder("update_info").required().hasArg().desc("update bookmarks in pdf")
            .argName("bookmarks").build();
    pdftk.addOption(optUpdateInfo);
    optsPDFtk.addOptionGroup(pdftk);
    optsPDFtk.addOption(optOutput);

    // What are we doing?
    CommandLineParser parser = new DefaultParser();

    // Did they want help?
    try {
        parser.parse(optsHelp, args);

        // If we get here, they asked for help
        doPrintHelp(optsHelp, optsNormal, optsPDFtk);
        return;
    } catch (ParseException pe) {
    }

    // Normal-style import/export?
    try {
        CommandLine line = parser.parse(optsNormal, args);

        // Export
        if (line.hasOption(optExport.getOpt())) {
            doExport(line.getOptionValue(optExport.getOpt()), line.getOptionValue(optBookmarks.getOpt()),
                    line.getArgs());
            return;
        }
        // Import with explicit output filename
        if (line.hasOption(optImport.getOpt()) && line.hasOption(optOutput.getOpt())) {
            doImport(line.getOptionValue(optImport.getOpt()), line.getOptionValue(optBookmarks.getOpt()),
                    line.getOptionValue(optOutput.getOpt()), null);
            return;
        }
        // Import with implicit output filename
        if (line.hasOption(optImport.getOpt()) && line.getArgs().length > 0) {
            doImport(line.getOptionValue(optImport.getOpt()), line.getOptionValue(optBookmarks.getOpt()), null,
                    line.getArgs());
            return;
        }
    } catch (ParseException pe) {
    }

    // PDFtk-style
    if (args.length > 1) {
        // Nobble things for PDFtk-style options and Commons CLI
        for (int i = 1; i < args.length; i++) {
            for (Option opt : optsPDFtk.getOptions()) {
                if (args[i].equals(opt.getOpt())) {
                    args[i] = "-" + args[i];
                }
            }
        }
        try {
            // Input file comes first, then arguments
            String input = args[0];
            String[] pargs = new String[args.length - 1];
            System.arraycopy(args, 1, pargs, 0, pargs.length);

            // Parse what's left and check
            CommandLine line = parser.parse(optsPDFtk, pargs);

            if (line.hasOption(optDumpData.getOpt())) {
                doExport(input, line.getOptionValue(optOutput.getOpt()), line.getArgs());
                return;
            }
            if (line.hasOption(optUpdateInfo.getOpt())) {
                doImport(input, line.getOptionValue(optUpdateInfo.getOpt()),
                        line.getOptionValue(optOutput.getOpt()), line.getArgs());
                return;
            }
        } catch (ParseException pe) {
        }
    }

    // If in doubt, print help
    doPrintHelp(optsHelp, optsNormal, optsPDFtk);
}

From source file:gr.seab.r2rml.beans.Main.java

public static void main(String[] args) {
    Calendar c0 = Calendar.getInstance();
    long t0 = c0.getTimeInMillis();

    CommandLineParser cmdParser = new PosixParser();

    Options cmdOptions = new Options();
    cmdOptions.addOption("p", "properties", true,
            "define the properties file. Example: r2rml-parser -p r2rml.properties");
    cmdOptions.addOption("h", "print help", false, "help");

    String propertiesFile = "r2rml.properties";

    try {//from w  w w .  ja  va2  s  . co m
        CommandLine line = cmdParser.parse(cmdOptions, args);

        if (line.hasOption("h")) {
            HelpFormatter help = new HelpFormatter();
            help.printHelp("r2rml-parser\n", cmdOptions);
            System.exit(0);
        }

        if (line.hasOption("p")) {
            propertiesFile = line.getOptionValue("p");
        }
    } catch (ParseException e1) {
        //e1.printStackTrace();
        log.error("Error parsing command line arguments.");
        System.exit(1);
    }

    try {
        if (StringUtils.isNotEmpty(propertiesFile)) {
            properties.load(new FileInputStream(propertiesFile));
            log.info("Loaded properties from " + propertiesFile);
        }
    } catch (FileNotFoundException e) {
        //e.printStackTrace();
        log.error("Properties file not found (" + propertiesFile + ").");
        System.exit(1);
    } catch (IOException e) {
        //e.printStackTrace();
        log.error("Error reading properties file (" + propertiesFile + ").");
        System.exit(1);
    }

    ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("app-context.xml");

    Database db = (Database) context.getBean("db");
    db.setProperties(properties);

    Parser parser = (Parser) context.getBean("parser");
    parser.setProperties(properties);

    MappingDocument mappingDocument = parser.parse();

    mappingDocument.getTimestamps().add(t0); //0 Started
    mappingDocument.getTimestamps().add(Calendar.getInstance().getTimeInMillis()); //1 Finished parsing. Starting generating result model.

    Generator generator = (Generator) context.getBean("generator");
    generator.setProperties(properties);
    generator.setResultModel(parser.getResultModel());

    //Actually do the output
    generator.createTriples(mappingDocument);

    context.close();
    Calendar c1 = Calendar.getInstance();
    long t1 = c1.getTimeInMillis();
    log.info("Finished in " + (t1 - t0) + " milliseconds. Done.");
    mappingDocument.getTimestamps().add(Calendar.getInstance().getTimeInMillis()); //5 Finished.
    //log.info("5 Finished.");

    //output the result
    for (int i = 0; i < mappingDocument.getTimestamps().size(); i++) {
        if (i > 0) {
            long l = (mappingDocument.getTimestamps().get(i).longValue()
                    - mappingDocument.getTimestamps().get(i - 1).longValue());
            //System.out.println(l);
            log.info(String.valueOf(l));
        }
    }
    log.info("Parse. Generate in memory. Dump to disk/database. Log. - Alltogether in "
            + String.valueOf(mappingDocument.getTimestamps().get(5).longValue()
                    - mappingDocument.getTimestamps().get(0).longValue())
            + " msec.");
    log.info("Done.");
    System.out.println("Done.");
}

From source file:cc.twittertools.util.ExtractSubcollection.java

@SuppressWarnings("static-access")
public static void main(String[] args) throws Exception {
    Options options = new Options();

    options.addOption(OptionBuilder.withArgName("dir").hasArg().withDescription("source collection directory")
            .create(COLLECTION_OPTION));
    options.addOption(//from   w  ww .  j av  a2s  .c o  m
            OptionBuilder.withArgName("file").hasArg().withDescription("list of tweetids").create(ID_OPTION));

    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(COLLECTION_OPTION) || !cmdline.hasOption(ID_OPTION)) {
        HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp(ExtractSubcollection.class.getName(), options);
        System.exit(-1);
    }

    String collectionPath = cmdline.getOptionValue(COLLECTION_OPTION);

    LongOpenHashSet tweetids = new LongOpenHashSet();
    File tweetidsFile = new File(cmdline.getOptionValue(ID_OPTION));
    if (!tweetidsFile.exists()) {
        System.err.println("Error: " + tweetidsFile + " does not exist!");
        System.exit(-1);
    }
    LOG.info("Reading tweetids from " + tweetidsFile);

    FileInputStream fin = new FileInputStream(tweetidsFile);
    BufferedReader br = new BufferedReader(new InputStreamReader(fin));

    String s;
    while ((s = br.readLine()) != null) {
        tweetids.add(Long.parseLong(s));
    }
    br.close();
    fin.close();
    LOG.info("Read " + tweetids.size() + " tweetids.");

    File file = new File(collectionPath);
    if (!file.exists()) {
        System.err.println("Error: " + file + " does not exist!");
        System.exit(-1);
    }

    PrintStream out = new PrintStream(System.out, true, "UTF-8");
    StatusStream stream = new JsonStatusCorpusReader(file);
    Status status;
    while ((status = stream.next()) != null) {
        if (tweetids.contains(status.getId())) {
            out.println(status.getJsonObject().toString());
        }
    }
    stream.close();
    out.close();
}

From source file:com.ikanow.infinit.e.utility.MongoIndexerMain.java

/**
 * This is just a placeholder to invoke MongoDocumentTxfer, MongoEventFeatureTxfer, or MongoEntityFeatureTxfer
 * @param args//  www .  ja va2  s.  com
 * @throws ParseException 
 * @throws MongoException 
 * @throws NumberFormatException 
 * @throws IOException 
 */

public static void main(String[] args) {

    try {
        CommandLineParser cliParser = new BasicParser();
        Options allOps = new Options();
        // Fork
        allOps.addOption("d", "doc", false, "Document transfer");
        allOps.addOption("n", "entity", false, "Entity feature transfer");
        allOps.addOption("a", "assoc", false, "Association feature transfer");
        allOps.addOption("A", "associations", false, "Association feature transfer");
        // Common
        allOps.addOption("q", "query", true, "MongoDB query to select records to transfer");
        allOps.addOption("D", "delete", false,
                "Delete the records in both MongoDB and Elasticsearch (instead of transferring them)");
        allOps.addOption("c", "config", true, "Override the default config path");
        allOps.addOption("l", "limit", true, "Caps the number of records to act upon");
        allOps.addOption("s", "skip", true, "The record at which to start (not in delete mode)");
        allOps.addOption("r", "rebuild", false, "Rebuild the index before transferring");
        allOps.addOption("v", "verify", false,
                "Verifies the document indexes all exist | resync the entity frequencies (INTERNAL ONLY)");
        allOps.addOption("f", "features", false,
                "Updates features present in the queried documents (--doc only; INTERNAL ONLY)");
        allOps.addOption("C", "chunks", true,
                "Loop over chunks, '--chunks all' for all chunks, '--chunks A,B,..' for specific chunks, '--chunks +A' for all chunks after A (currently -doc only)");

        CommandLine cliOpts = cliParser.parse(allOps, args);

        //Set up common parameters

        String configOverride = null;
        String query = null;
        String chunksDescription = null;
        boolean bDelete = false;
        boolean bRebuildIndex = false;
        boolean bVerifyIndex = false;
        boolean bUpdateFeatures = false;
        int nLimit = 0;
        int nSkip = 0;
        if (cliOpts.hasOption("config")) {
            configOverride = (String) cliOpts.getOptionValue("config");
        }
        if (cliOpts.hasOption("query")) {
            query = (String) cliOpts.getOptionValue("query");
        }
        if (cliOpts.hasOption("delete")) {
            bDelete = true;
        }
        if (cliOpts.hasOption("limit")) {
            try {
                nLimit = Integer.parseInt((String) cliOpts.getOptionValue("limit"));
            } catch (Exception e) {
                System.out.println("Error parsing --limit: " + (String) cliOpts.getOptionValue("limit"));
                query = null; // exit in if clause below
            }
        }
        if (cliOpts.hasOption("skip")) {
            try {
                nSkip = Integer.parseInt((String) cliOpts.getOptionValue("skip"));
            } catch (Exception e) {
                System.out.println("Error parsing --skip: " + (String) cliOpts.getOptionValue("skip"));
                query = null; // exit in if clause below
            }
        }
        if (cliOpts.hasOption("rebuild")) {
            bRebuildIndex = true;
        }
        if (cliOpts.hasOption("features")) {
            bUpdateFeatures = true;
        }
        if (cliOpts.hasOption("verify")) {
            if (cliOpts.hasOption("doc") && !bRebuildIndex) {
                bVerifyIndex = true; // (doc only)
            } else if (cliOpts.hasOption("entity")) {
                bVerifyIndex = true; // (ents only)               
            }
        }
        if (cliOpts.hasOption("chunks")) {
            if (bDelete) {
                System.out.println("Can't specify --chunks in conjunction with --delete");
                query = null; // exit in if clause below
            } else if ((nSkip != 0) || (nLimit != 0)) {
                System.out.println("Can't specify --chunks in conjunction with --skip or --limit");
                query = null; // exit in if clause below
            }
            chunksDescription = (String) cliOpts.getOptionValue("chunks");
        }
        if ((0 == args.length)
                || ((null == query) && (0 == nLimit) && !bVerifyIndex && (null == chunksDescription))) {
            System.out.println(
                    "Usage: MongoIndexerMain --doc|--assoc|--entity [--rebuild] [--verify] [--query <query>] [--chunks all|<chunklist>|+<chunk>] [--config <path>] [--delete] [--skip <start record>] [--limit <max records>]");
            if (args.length > 0) {
                System.out.println(
                        "(Note you must either specify a limit or a query or chunks - the query can be {} to get all records)");
            }
            System.exit(-1);
        }

        // Invoke appropriate manager to perform processing

        if (cliOpts.hasOption("doc")) {
            MongoDocumentTxfer.main(configOverride, query, bDelete, bRebuildIndex, bVerifyIndex,
                    bUpdateFeatures, nSkip, nLimit, chunksDescription);
        } else if (cliOpts.hasOption("assoc") || cliOpts.hasOption("association")) {
            MongoAssociationFeatureTxfer.main(configOverride, query, bDelete, bRebuildIndex, nSkip, nLimit,
                    chunksDescription);
        } else if (cliOpts.hasOption("entity")) {
            if (bVerifyIndex) {
                String[] dbDotColl = query.split("\\.");
                MongoEntitySyncFreq.syncFreq(dbDotColl[0], dbDotColl[1], configOverride);
            } else {
                MongoEntityFeatureTxfer.main(configOverride, query, bDelete, bRebuildIndex, nSkip, nLimit,
                        chunksDescription);
            }
        } else {
            System.out.println(
                    "Usage: MongoIndexerMain --doc|--assoc|--entity [--rebuild] [--query <query>] [--config <path>] [--delete] [--skip <start record>] [--limit <max records>]");
            System.exit(-1);
        }
    } catch (Exception e) {
        e.printStackTrace();
        System.exit(-1);
    }
}

From source file:edu.umd.cloud9.example.bigram.AnalyzeBigramRelativeFrequency.java

@SuppressWarnings({ "static-access" })
public static void main(String[] args) {
    Options options = new Options();

    options.addOption(OptionBuilder.withArgName("path").hasArg().withDescription("input path").create(INPUT));

    CommandLine cmdline = null;/*from ww w  .ja  v  a  2 s  .  c om*/
    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(INPUT)) {
        System.out.println("args: " + Arrays.toString(args));
        HelpFormatter formatter = new HelpFormatter();
        formatter.setWidth(120);
        formatter.printHelp(AnalyzeBigramRelativeFrequency.class.getName(), options);
        ToolRunner.printGenericCommandUsage(System.out);
        System.exit(-1);
    }

    String inputPath = cmdline.getOptionValue(INPUT);
    System.out.println("input path: " + inputPath);

    List<PairOfWritables<PairOfStrings, FloatWritable>> pairs = SequenceFileUtils
            .readDirectory(new Path(inputPath));

    List<PairOfWritables<PairOfStrings, FloatWritable>> list1 = Lists.newArrayList();
    List<PairOfWritables<PairOfStrings, FloatWritable>> list2 = Lists.newArrayList();

    for (PairOfWritables<PairOfStrings, FloatWritable> p : pairs) {
        PairOfStrings bigram = p.getLeftElement();

        if (bigram.getLeftElement().equals("light")) {
            list1.add(p);
        }
        if (bigram.getLeftElement().equals("contain")) {
            list2.add(p);
        }
    }

    Collections.sort(list1, new Comparator<PairOfWritables<PairOfStrings, FloatWritable>>() {
        public int compare(PairOfWritables<PairOfStrings, FloatWritable> e1,
                PairOfWritables<PairOfStrings, FloatWritable> e2) {
            if (e1.getRightElement().compareTo(e2.getRightElement()) == 0) {
                return e1.getLeftElement().compareTo(e2.getLeftElement());
            }

            return e2.getRightElement().compareTo(e1.getRightElement());
        }
    });

    Iterator<PairOfWritables<PairOfStrings, FloatWritable>> iter1 = Iterators.limit(list1.iterator(), 10);
    while (iter1.hasNext()) {
        PairOfWritables<PairOfStrings, FloatWritable> p = iter1.next();
        PairOfStrings bigram = p.getLeftElement();
        System.out.println(bigram + "\t" + p.getRightElement());
    }

    Collections.sort(list2, new Comparator<PairOfWritables<PairOfStrings, FloatWritable>>() {
        public int compare(PairOfWritables<PairOfStrings, FloatWritable> e1,
                PairOfWritables<PairOfStrings, FloatWritable> e2) {
            if (e1.getRightElement().compareTo(e2.getRightElement()) == 0) {
                return e1.getLeftElement().compareTo(e2.getLeftElement());
            }

            return e2.getRightElement().compareTo(e1.getRightElement());
        }
    });

    Iterator<PairOfWritables<PairOfStrings, FloatWritable>> iter2 = Iterators.limit(list2.iterator(), 10);
    while (iter2.hasNext()) {
        PairOfWritables<PairOfStrings, FloatWritable> p = iter2.next();
        PairOfStrings bigram = p.getLeftElement();
        System.out.println(bigram + "\t" + p.getRightElement());
    }
}

From source file:net.ovres.tuxcourser.TuxCourser.java

public static void main(String[] argss) throws Exception {
    Options options = new Options();
    options.addOption(OptionBuilder.withArgName("WARN|INFO|FINE").hasArg()
            .withDescription("Set the log level. Valid values include WARN, INFO, and FINE.")
            .withLongOpt("loglevel").create("l"));
    options.addOption("h", "help", false, "Displays this help and exits");
    options.addOption("v", "version", false, "Displays version information and exits");

    options.addOption(OptionBuilder.withArgName("TYPE").hasArg()
            .withDescription("Sets the output type. Valid values are tux11 and ppracer05").withLongOpt("output")
            .create());//from  w  w  w.  j av  a  2  s .  c  om

    CommandLineParser parser = new GnuParser();
    CommandLine line = null;
    try {
        line = parser.parse(options, argss);
    } catch (ParseException exp) {
        System.err.println(exp.getMessage());
        HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp("java -jar TuxCourser.jar [Options]", "Options", options, "");
        System.exit(-1);
    }

    if (line.hasOption("loglevel")) {
        String lvl = line.getOptionValue("loglevel");
        Level logLevel = Level.parse(lvl);
        Logger.getLogger("net.ovres.tuxcourser").setLevel(logLevel);
    }

    if (line.hasOption("help")) {
        HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp("java -jar TuxCourser.jar [Options]", "Options", options, "");
        return;
    }
    if (line.hasOption("version")) {
        System.out.println("TuxCourser Version " + Settings.getVersion());
        return;
    }

    String[] remaining = line.getArgs();

    // Initialize all the different item and terrain types
    ModuleClassLoader.load();

    if (remaining.length == 0) { // Just show the gui.
        //UIManager.setLookAndFeel("com.sun.java.swing.plaf.gtk.GTKLookAndFeel");
        new net.ovres.tuxcourser.gui.TuxCourserGui().setVisible(true);
    } else if (remaining.length == 3) {
        new TuxCourser().convertCourse(new File(remaining[0]), new File(remaining[1]), remaining[2],
                TYPE_TUXRACER11);
    } else {
        usage();
        System.exit(-1);
    }
}

From source file:edu.usc.pgroup.floe.client.commands.Signal.java

/**
 * Entry point for Scale command./*www . j a v  a  2s.  c om*/
 * @param args command line arguments sent by the floe.py script.
 */
public static void main(final String[] args) {

    Options options = new Options();

    Option appOption = OptionBuilder.withArgName("name").hasArg().isRequired()
            .withDescription("Application Name").create("app");

    Option pelletNameOption = OptionBuilder.withArgName("name").hasArg().isRequired()
            .withDescription("Pellet Name").create("pellet");

    Option signalOption = OptionBuilder.withArgName("data").hasArg().withType(new String())
            .withDescription("signal data to send to the pellet").create("data");

    options.addOption(appOption);
    options.addOption(pelletNameOption);
    options.addOption(signalOption);

    CommandLineParser parser = new BasicParser();
    CommandLine line;

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

    } catch (ParseException e) {
        LOGGER.error("Invalid command: " + e.getMessage());
        HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp("scale options", options);
        return;
    }

    String app = line.getOptionValue("app");
    String pellet = line.getOptionValue("pellet");
    String data = line.getOptionValue("data");

    LOGGER.info("Application: {}", app);
    LOGGER.info("Pellet: {}", pellet);
    LOGGER.info("data: {}", data);

    byte[] datab = Utils.serialize(data);
    try {
        TSignal signal = new TSignal();
        signal.set_destApp(app);
        signal.set_destPellet(pellet);
        signal.set_data(datab);
        FloeClient.getInstance().getClient().signal(signal);
    } catch (TException e) {
        LOGGER.error("Error while connecting to the coordinator: {}", e);
    }
}