Example usage for java.lang Integer MAX_VALUE

List of usage examples for java.lang Integer MAX_VALUE

Introduction

In this page you can find the example usage for java.lang Integer MAX_VALUE.

Prototype

int MAX_VALUE

To view the source code for java.lang Integer MAX_VALUE.

Click Source Link

Document

A constant holding the maximum value an int can have, 231-1.

Usage

From source file:com.tamingtext.qa.WikipediaWexIndexer.java

public static void main(String[] args) throws Exception {
    DefaultOptionBuilder obuilder = new DefaultOptionBuilder();
    ArgumentBuilder abuilder = new ArgumentBuilder();
    GroupBuilder gbuilder = new GroupBuilder();

    Option wikipediaFileOpt = obuilder.withLongName("wikiFile").withRequired(true)
            .withArgument(abuilder.withName("wikiFile").withMinimum(1).withMaximum(1).create())
            .withDescription("The path to the wikipedia dump file. "
                    + "May be a directory containing wikipedia dump files. "
                    + "If a directory is specified, files starting with the prefix "
                    + "freebase-segment- are used.")
            .withShortName("w").create();

    Option numDocsOpt = obuilder.withLongName("numDocs").withRequired(false)
            .withArgument(abuilder.withName("numDocs").withMinimum(1).withMaximum(1).create())
            .withDescription("The number of docs to index").withShortName("n").create();

    Option solrURLOpt = obuilder.withLongName("solrURL").withRequired(false)
            .withArgument(abuilder.withName("solrURL").withMinimum(1).withMaximum(1).create())
            .withDescription("The URL where Solr lives").withShortName("s").create();

    Option solrBatchOpt = obuilder.withLongName("batch").withRequired(false)
            .withArgument(abuilder.withName("batch").withMinimum(1).withMaximum(1).create())
            .withDescription("The number of docs to include in each indexing batch").withShortName("b")
            .create();/*w  ww.java  2s .c  om*/

    Option helpOpt = obuilder.withLongName("help").withDescription("Print out help").withShortName("h")
            .create();

    Group group = gbuilder.withName("Options").withOption(wikipediaFileOpt).withOption(numDocsOpt)
            .withOption(solrURLOpt).withOption(solrBatchOpt).withOption(helpOpt).create();

    Parser parser = new Parser();
    parser.setGroup(group);

    try {
        CommandLine cmdLine = parser.parse(args);

        if (cmdLine.hasOption(helpOpt)) {
            CommandLineUtil.printHelp(group);
            return;
        }

        File file;
        file = new File(cmdLine.getValue(wikipediaFileOpt).toString());
        File[] dumpFiles;
        if (file.isDirectory()) {
            dumpFiles = file.listFiles(new FilenameFilter() {
                public boolean accept(File file, String s) {
                    return s.startsWith("freebase-segment-");
                }
            });
        } else {
            dumpFiles = new File[] { file };
        }

        int numDocs = Integer.MAX_VALUE;
        if (cmdLine.hasOption(numDocsOpt)) {
            numDocs = Integer.parseInt(cmdLine.getValue(numDocsOpt).toString());
        }
        String url = DEFAULT_SOLR_URL;
        if (cmdLine.hasOption(solrURLOpt)) {
            url = cmdLine.getValue(solrURLOpt).toString();
        }
        int batch = 100;
        if (cmdLine.hasOption(solrBatchOpt)) {
            batch = Integer.parseInt(cmdLine.getValue(solrBatchOpt).toString());
        }
        WikipediaWexIndexer indexer = new WikipediaWexIndexer(new CommonsHttpSolrServer(url));
        int total = 0;
        for (int i = 0; i < dumpFiles.length && total < numDocs; i++) {
            File dumpFile = dumpFiles[i];
            log.info("Indexing: " + file + " Num files to index: " + (numDocs - total));
            long start = System.currentTimeMillis();
            int totalFile = indexer.index(dumpFile, numDocs - total, batch);
            long finish = System.currentTimeMillis();
            if (log.isInfoEnabled()) {
                log.info("Indexing " + dumpFile + " took " + (finish - start) + " ms");
            }
            total += totalFile;
            log.info("Done Indexing: " + file + ". Indexed " + totalFile + " docs for that file and " + total
                    + " overall.");

        }
        log.info("Indexed " + total + " docs overall.");
    } catch (OptionException e) {
        log.error("Exception", e);
        CommandLineUtil.printHelp(group);
        return;
    }
}

From source file:de.tudarmstadt.ukp.teaching.uima.nounDecompounding.evaluation.CouchDbExport.java

@SuppressWarnings("static-access")
public static void main(String[] args) {
    Options options = new Options();
    options.addOption(OptionBuilder.withLongOpt("host")
            .withDescription("(optional) The couchdb host. default: 127.0.0.1").hasArg().create());
    options.addOption(OptionBuilder.withLongOpt("port")
            .withDescription("(optional) The couchdb port. default: 5984").hasArg().create());
    options.addOption(OptionBuilder.withLongOpt("username")
            .withDescription("(optional) The couchdb username. default: <empty>").hasArg().create());
    options.addOption(OptionBuilder.withLongOpt("password")
            .withDescription("(optional) The couchdb password. default: <empty>").hasArg().create());
    options.addOption(OptionBuilder.withLongOpt("dbname")
            .withDescription("(optional) The couchdb database name. default: noun_decompounding").hasArg()
            .create());/*from w  ww. j  a  va  2  s .  co  m*/
    options.addOption(OptionBuilder.withLongOpt("limit")
            .withDescription("(optional) The amount of documents you want to export. default: all").hasArg()
            .create());

    CommandLineParser parser = new PosixParser();
    CommandLine cmd;
    try {
        cmd = parser.parse(options, args);
    } catch (ParseException e) {
        System.err.println("Error: " + e.getMessage());

        HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp("countTotalFreq", options);
        return;
    }
    String host = (cmd.hasOption("host")) ? cmd.getOptionValue("host") : "127.0.0.1";
    int port = Integer.parseInt((cmd.hasOption("port")) ? cmd.getOptionValue("port") : "5984");
    String username = (cmd.hasOption("username")) ? cmd.getOptionValue("username") : "";
    String password = (cmd.hasOption("password")) ? cmd.getOptionValue("password") : "";
    String dbName = (cmd.hasOption("dbname")) ? cmd.getOptionValue("dbname") : "";
    int limit = (cmd.hasOption("limit")) ? Integer.parseInt(cmd.getOptionValue("limit")) : Integer.MAX_VALUE;

    IDictionary dict = new IGerman98Dictionary(new File("src/main/resources/de_DE.dic"),
            new File("src/main/resources/de_DE.aff"));
    LinkingMorphemes morphemes = new LinkingMorphemes(new File("src/main/resources/linkingMorphemes.txt"));
    LeftToRightSplitAlgorithm algo = new LeftToRightSplitAlgorithm(dict, morphemes);

    HttpClient httpClient = new StdHttpClient.Builder().host(host).port(port).username(username)
            .password(password).build();
    CouchDbInstance dbInstance = new StdCouchDbInstance(httpClient);
    CouchDbConnector db = new StdCouchDbConnector(dbName, dbInstance);

    try {
        CouchDbExport exporter = new CouchDbExport(
                new CcorpusReader(new File("src/main/resources/evaluation/ccorpus.txt")), db);
        exporter.export(algo, limit);
    } catch (FileNotFoundException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
    }
}

From source file:com.thimbleware.jmemcached.Main.java

public static void main(String[] args) throws Exception {
    // look for external log4j.properties

    // setup command line options
    Options options = new Options();
    options.addOption("h", "help", false, "print this help screen");
    options.addOption("bl", "block-store", false, "use external (from JVM) heap");
    options.addOption("f", "mapped-file", false, "use external (from JVM) heap through a memory mapped file");
    options.addOption("bs", "block-size", true,
            "block size (in bytes) for external memory mapped file allocator.  default is 8 bytes");
    options.addOption("i", "idle", true, "disconnect after idle <x> seconds");
    options.addOption("p", "port", true, "port to listen on");
    options.addOption("m", "memory", true,
            "max memory to use; in bytes, specify K, kb, M, GB for larger units");
    options.addOption("c", "ceiling", true,
            "ceiling memory to use; in bytes, specify K, kb, M, GB for larger units");
    options.addOption("l", "listen", true, "Address to listen on");
    options.addOption("s", "size", true, "max items");
    options.addOption("b", "binary", false, "binary protocol mode");
    options.addOption("V", false, "Show version number");
    options.addOption("v", false, "verbose (show commands)");

    // read command line options
    CommandLineParser parser = new PosixParser();
    CommandLine cmdline = parser.parse(options, args);

    if (cmdline.hasOption("help") || cmdline.hasOption("h")) {
        System.out.println("Memcached Version " + MemCacheDaemon.memcachedVersion);
        System.out.println("http://thimbleware.com/projects/memcached\n");

        HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp("java -jar memcached.jar", options);
        return;/*ww  w.  j  a v a2 s .co m*/
    }

    if (cmdline.hasOption("V")) {
        System.out.println("Memcached Version " + MemCacheDaemon.memcachedVersion);
        return;
    }

    int port = 11211;
    if (cmdline.hasOption("p")) {
        port = Integer.parseInt(cmdline.getOptionValue("p"));
    } else if (cmdline.hasOption("port")) {
        port = Integer.parseInt(cmdline.getOptionValue("port"));
    }

    InetSocketAddress addr = new InetSocketAddress(port);
    if (cmdline.hasOption("l")) {
        addr = new InetSocketAddress(cmdline.getOptionValue("l"), port);
    } else if (cmdline.hasOption("listen")) {
        addr = new InetSocketAddress(cmdline.getOptionValue("listen"), port);
    }

    int max_size = 1000000;
    if (cmdline.hasOption("s"))
        max_size = (int) Bytes.valueOf(cmdline.getOptionValue("s")).bytes();
    else if (cmdline.hasOption("size"))
        max_size = (int) Bytes.valueOf(cmdline.getOptionValue("size")).bytes();

    System.out.println("Setting max cache elements to " + String.valueOf(max_size));

    int idle = -1;
    if (cmdline.hasOption("i")) {
        idle = Integer.parseInt(cmdline.getOptionValue("i"));
    } else if (cmdline.hasOption("idle")) {
        idle = Integer.parseInt(cmdline.getOptionValue("idle"));
    }

    boolean memoryMapped = false;
    if (cmdline.hasOption("f")) {
        memoryMapped = true;
    } else if (cmdline.hasOption("mapped-file")) {
        memoryMapped = true;
    }

    boolean blockStore = false;
    if (cmdline.hasOption("bl")) {
        blockStore = true;
    } else if (cmdline.hasOption("block-store")) {
        blockStore = true;
    }

    boolean verbose = false;
    if (cmdline.hasOption("v")) {
        verbose = true;
    }

    long ceiling;
    if (cmdline.hasOption("c")) {
        ceiling = Bytes.valueOf(cmdline.getOptionValue("c")).bytes();
        System.out.println("Setting ceiling memory size to " + Bytes.bytes(ceiling).megabytes() + "M");
    } else if (cmdline.hasOption("ceiling")) {
        ceiling = Bytes.valueOf(cmdline.getOptionValue("ceiling")).bytes();
        System.out.println("Setting ceiling memory size to " + Bytes.bytes(ceiling).megabytes() + "M");
    } else if (!memoryMapped) {
        ceiling = 1024000;
        System.out.println(
                "Setting ceiling memory size to default limit of " + Bytes.bytes(ceiling).megabytes() + "M");
    } else {
        System.out
                .println("ERROR : ceiling memory size mandatory when external memory mapped file is specified");

        return;
    }

    boolean binary = false;
    if (cmdline.hasOption("b")) {
        binary = true;
    }

    int blockSize = 8;
    if (!memoryMapped && (cmdline.hasOption("bs") || cmdline.hasOption("block-size"))) {
        System.out.println(
                "WARN : block size option is only valid for memory mapped external heap storage; ignoring");
    } else if (cmdline.hasOption("bs")) {
        blockSize = Integer.parseInt(cmdline.getOptionValue("bs"));
    } else if (cmdline.hasOption("block-size")) {
        blockSize = Integer.parseInt(cmdline.getOptionValue("block-size"));
    }

    long maxBytes;
    if (cmdline.hasOption("m")) {
        maxBytes = Bytes.valueOf(cmdline.getOptionValue("m")).bytes();
        System.out.println("Setting max memory size to " + Bytes.bytes(maxBytes).gigabytes() + "GB");
    } else if (cmdline.hasOption("memory")) {
        maxBytes = Bytes.valueOf(cmdline.getOptionValue("memory")).bytes();
        System.out.println("Setting max memory size to " + Bytes.bytes(maxBytes).gigabytes() + "GB");
    } else if (!memoryMapped) {
        maxBytes = Runtime.getRuntime().maxMemory();
        System.out
                .println("Setting max memory size to JVM limit of " + Bytes.bytes(maxBytes).gigabytes() + "GB");
    } else {
        System.out.println(
                "ERROR : max memory size and ceiling size are mandatory when external memory mapped file is specified");
        return;
    }

    if (!memoryMapped && !blockStore && maxBytes > Runtime.getRuntime().maxMemory()) {
        System.out.println("ERROR : JVM heap size is not big enough. use '-Xmx"
                + String.valueOf(maxBytes / 1024000) + "m' java argument before the '-jar' option.");
        return;
    } else if ((memoryMapped || !blockStore) && maxBytes > Integer.MAX_VALUE) {
        System.out.println(
                "ERROR : when external memory mapped, memory size may not exceed the size of Integer.MAX_VALUE ("
                        + Bytes.bytes(Integer.MAX_VALUE).gigabytes() + "GB");
        return;
    }

    // create daemon and start it
    final MemCacheDaemon<LocalCacheElement> daemon = new MemCacheDaemon<LocalCacheElement>();

    CacheStorage<Key, LocalCacheElement> storage;
    if (blockStore) {
        BlockStoreFactory blockStoreFactory = ByteBufferBlockStore.getFactory();

        storage = new BlockStorageCacheStorage(8, (int) ceiling, blockSize, maxBytes, max_size,
                blockStoreFactory);
    } else if (memoryMapped) {
        BlockStoreFactory blockStoreFactory = MemoryMappedBlockStore.getFactory();

        storage = new BlockStorageCacheStorage(8, (int) ceiling, blockSize, maxBytes, max_size,
                blockStoreFactory);
    } else {
        storage = ConcurrentLinkedHashMap.create(ConcurrentLinkedHashMap.EvictionPolicy.FIFO, max_size,
                maxBytes);
    }

    daemon.setCache(new CacheImpl(storage));
    daemon.setBinary(binary);
    daemon.setAddr(addr);
    daemon.setIdleTime(idle);
    daemon.setVerbose(verbose);
    daemon.start();

    Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {
        public void run() {
            if (daemon.isRunning())
                daemon.stop();
        }
    }));
}

From source file:com.asakusafw.compiler.bootstrap.OperatorCompilerDriver.java

/**
 * //from   ww  w  .ja v  a  2s. c om
 * @param args 
 */
public static void main(String... args) {
    try {
        start(args);
    } catch (Exception e) {
        HelpFormatter formatter = new HelpFormatter();
        formatter.setWidth(Integer.MAX_VALUE);
        formatter.printHelp(MessageFormat.format("java -classpath ... {0}", //$NON-NLS-1$
                OperatorCompilerDriver.class.getName()), OPTIONS, true);
        e.printStackTrace(System.out);
        System.exit(1);
    }
}

From source file:net.minecraftforge.fml.repackage.com.nothome.delta.GDiffPatcher.java

/**
 * Simple command line tool to patch a file.
 *///  ww w.j ava2 s  .com
public static void main(String argv[]) {

    if (argv.length != 3) {
        System.err.println("usage GDiffPatch source patch output");
        System.err.println("aborting..");
        return;
    }
    try {
        File sourceFile = new File(argv[0]);
        File patchFile = new File(argv[1]);
        File outputFile = new File(argv[2]);

        if (sourceFile.length() > Integer.MAX_VALUE || patchFile.length() > Integer.MAX_VALUE) {
            System.err.println("source or patch is too large, max length is " + Integer.MAX_VALUE);
            System.err.println("aborting..");
            return;
        }
        GDiffPatcher patcher = new GDiffPatcher();
        patcher.patch(sourceFile, patchFile, outputFile);

        System.out.println("finished patching file");

    } catch (Exception ioe) { //gls031504a
        System.err.println("error while patching: " + ioe);
    }
}

From source file:cc.twittertools.search.api.TrecSearchThriftLoadGenerator.java

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

    options.addOption(new Option(HELP_OPTION, "show help"));
    options.addOption(OptionBuilder.withArgName("port").hasArg().withDescription("port").create(PORT_OPTION));
    options.addOption(OptionBuilder.withArgName("index").hasArg().withDescription("host").create(HOST_OPTION));
    options.addOption(/*  w  ww . j av  a2s. c  om*/
            OptionBuilder.withArgName("num").hasArg().withDescription("threads").create(THREADS_OPTION));
    options.addOption(OptionBuilder.withArgName("num").hasArg().withDescription("number of queries to process")
            .create(LIMIT_OPTION));
    options.addOption(
            OptionBuilder.withArgName("string").hasArg().withDescription("group id").create(GROUP_OPTION));
    options.addOption(
            OptionBuilder.withArgName("string").hasArg().withDescription("access token").create(TOKEN_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(HELP_OPTION) || !cmdline.hasOption(HOST_OPTION)) {
        HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp(TrecSearchThriftServer.class.getName(), options);
        System.exit(-1);
    }

    String host = cmdline.getOptionValue(HOST_OPTION);
    int port = cmdline.hasOption(PORT_OPTION) ? Integer.parseInt(cmdline.getOptionValue(PORT_OPTION))
            : DEFAULT_PORT;
    int numThreads = cmdline.hasOption(THREADS_OPTION)
            ? Integer.parseInt(cmdline.getOptionValue(THREADS_OPTION))
            : DEFAULT_THREADS;
    int limit = cmdline.hasOption(LIMIT_OPTION) ? Integer.parseInt(cmdline.getOptionValue(LIMIT_OPTION))
            : Integer.MAX_VALUE;

    String group = cmdline.hasOption(GROUP_OPTION) ? cmdline.getOptionValue(GROUP_OPTION) : null;
    String token = cmdline.hasOption(TOKEN_OPTION) ? cmdline.getOptionValue(TOKEN_OPTION) : null;

    String queryFile = "data/queries.trec2005efficiency.txt";
    new TrecSearchThriftLoadGenerator(new File(queryFile), limit).withThreads(numThreads)
            .withCredentials(group, token).run(host, port);
}

From source file:com.ning.hfind.Find.java

public static void main(String[] origArgs) throws ParseException, IOException {
    PrinterConfig printerConfig = new PrinterConfig();

    CommandLineParser parser = new PosixParser();
    CommandLine line = parser.parse(options, origArgs);
    String[] args = line.getArgs();

    if (args.length > 1) {
        // find(1) seems to complain about the first argument only, let's do the same
        System.out.println(String.format("hfind: %s: unknown option", args[1]));
        System.exit(COMMAND_LINE_ERROR);
    }/*ww  w  .  java 2s. co  m*/
    if (line.hasOption("help") || args.length == 0) {
        usage();
        return;
    }

    String path = args[0];
    // Optimization: check the depth on a top-level basis, not on a per-file basis
    // This avoids crawling files on Hadoop we don't care about
    int maxDepth = Integer.MAX_VALUE;
    if (line.hasOption("maxdepth")) {
        String maxDepthOptionValue = line.getOptionValue("maxdepth");
        maxDepth = Integer.valueOf(maxDepthOptionValue);
    }
    if (line.hasOption("delete")) {
        // -delete implies -d
        printerConfig.setDepthMode(true);
        printerConfig.setDeleteMode(true);
    }
    if (line.hasOption("d")) {
        printerConfig.setDepthMode(true);
    }
    if (line.hasOption("print0")) {
        printerConfig.setEndLineWithNull(true);
    }
    if (line.hasOption("verbose")) {
        printerConfig.setVerbose(true);
    }

    // Ignore certain primaries
    Iterator<Option> optionsIterator = ExpressionFactory.sanitizeCommandLine(line.getOptions());

    Expression expression = null;
    try {
        expression = ExpressionFactory
                .buildExpressionFromCommandLine(new PushbackIterator<Option>(optionsIterator));
        //System.out.println(String.format("find %s: %s", StringUtils.join(origArgs, " "), expression));
    } catch (IllegalArgumentException e) {
        System.err.println(e);
        System.exit(COMMAND_LINE_ERROR);
    }

    try {
        expression.run(path, maxDepth, printerConfig);
        System.exit(0);
    } catch (IOException e) {
        System.err.println(String.format("Error crawling HDFS: %s", e.getLocalizedMessage()));
        System.exit(HADOOP_ERROR);
    }
}

From source file:Main.java

public static int longToUInt(long lInt) {
    if (lInt > Integer.MAX_VALUE && lInt < 0xFFFFFFFFL) {
        lInt = lInt - 0xFFFFFFFFL;//from www  .  ja v a  2s .com
    }
    return (int) lInt;
}

From source file:Main.java

public static int getMin(int[] arr) {
    int min = Integer.MAX_VALUE;

    for (int i = 0; i < arr.length; i++) {
        if (arr[i] < min)
            min = arr[i];//from   w w  w . j  a v  a2  s  . co  m
    }

    return min;
}

From source file:Main.java

public static String secToMinSec(Long sec) {
    if (sec == Integer.MAX_VALUE) {
        return "no result";
    } else {/* ww w . j av a 2  s  .  com*/
        Long totalTime_sec = sec;
        Long toltalTime_min = sec / 60;
        totalTime_sec -= toltalTime_min * 60;

        return String.format("%02d:%02d", toltalTime_min, totalTime_sec);
    }
}