Example usage for java.lang Long parseLong

List of usage examples for java.lang Long parseLong

Introduction

In this page you can find the example usage for java.lang Long parseLong.

Prototype

public static long parseLong(String s) throws NumberFormatException 

Source Link

Document

Parses the string argument as a signed decimal long .

Usage

From source file:com.github.rnewson.couchdb.lucene.util.ServletUtils.java

public static long getLongParameter(final HttpServletRequest req, final String parameterName,
        final long defaultValue) {
    final String result = req.getParameter(parameterName);
    return result != null ? Long.parseLong(result) : defaultValue;
}

From source file:com.act.biointerpretation.mechanisminspection.ReactionRenderer.java

public static void main(String[] args) throws IOException {
    Options opts = new Options();
    for (Option.Builder b : OPTION_BUILDERS) {
        opts.addOption(b.build());/*w  ww. jav  a  2 s.  com*/
    }

    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(ReactionRenderer.class.getCanonicalName(), HELP_MESSAGE, opts, null, true);
        System.exit(1);
    }

    if (cl.hasOption("help")) {
        HELP_FORMATTER.printHelp(ReactionRenderer.class.getCanonicalName(), HELP_MESSAGE, opts, null, true);
        return;
    }

    Integer height = Integer.parseInt(cl.getOptionValue(OPTION_HEIGHT, "1000"));
    Integer width = Integer.parseInt(cl.getOptionValue(OPTION_WIDTH, "1000"));
    Boolean representCofactors = cl.hasOption(OPTION_COFACTOR)
            && Boolean.parseBoolean(cl.getOptionValue(OPTION_COFACTOR));

    NoSQLAPI api = new NoSQLAPI(cl.getOptionValue(OPTION_READ_DB), cl.getOptionValue(OPTION_READ_DB));

    for (String val : cl.getOptionValues(OPTION_RXN_IDS)) {
        Long reactionId = Long.parseLong(val);
        ReactionRenderer renderer = new ReactionRenderer(cl.getOptionValue(OPTION_FILE_FORMAT), width, height);
        renderer.drawReaction(api.getReadDB(), reactionId, cl.getOptionValue(OPTION_DIR_PATH),
                representCofactors);
        LOGGER.info(renderer.getSmartsForReaction(api.getReadDB(), reactionId, representCofactors));
    }
}

From source file:converters.StringRoleConverter.java

@Override
public Role convert(String source) {
    return rolesRepository.findOne(Long.parseLong(source));
}

From source file:api.util.JsonUtil.java

public static Number asNumber(Object val) {
    if (val instanceof Number)
        return (Number) val;
    if (val == JSONObject.NULL)
        return null;
    if (val instanceof String) {
        String str = (String) val;
        try {//from  w w  w.j av  a  2s .c  o m
            return Integer.parseInt(str);
        } catch (Exception ex) {
        }
        try {
            return Long.parseLong(str);
        } catch (Exception ex) {
        }
        try {
            return Double.parseDouble(str);
        } catch (Exception ex) {
        }
    }
    throw new IllegalArgumentException("Not a number: " + val);
}

From source file:com.atilika.kuromoji.benchmark.Benchmark.java

public static void main(String[] args) throws IOException {
    Options options = new Options();
    options.addOption("h", "help", false, "Display this help message and exit");
    options.addOption("t", "tokenizer", true, "Tokenizer class to use");
    options.addOption("u", "user-dictionary", true, "Optional user dictionary filename to use");
    options.addOption("c", "count", true, "Number of documents ot process (Default: 0, which means all");
    //        options.addOption("v", "validation-input", true, "Validation filename");
    options.addOption("o", "output", true,
            "Output filename.  If unset, segmentation is done, but the result is discarded");
    options.addOption("n", "n-best", true, "The number of tokenizations to get per input");
    options.addOption(null, "benchmark-output", true, "Benchmark metrics output filename filename");

    CommandLineParser parser = new DefaultParser();
    CommandLine commandLine = null;//w w w . j  a v  a  2s  .c o  m
    try {
        commandLine = parser.parse(options, args);

        args = commandLine.getArgs();

        if (args.length != 1) {
            throw new ParseException("A single input filename is required");
        }
    } catch (ParseException e) {
        System.err.println(e.getMessage());
        usage(options);
    }

    String inputFilename = args[0];

    String className = commandLine.getOptionValue("t", "com.atilika.kuromoji.ipadic.Tokenizer");

    className += "$Builder";

    String userDictionaryFilename = commandLine.getOptionValue("u");

    TokenizerBase tokenizer = null;
    try {
        Class clazz = Class.forName(className);

        // Make builder
        Object builder = clazz.getDeclaredConstructor(null).newInstance();

        // Set user dictionary
        if (userDictionaryFilename != null) {
            builder.getClass().getMethod("userDictionary", String.class).invoke(builder,
                    userDictionaryFilename);
        }

        // Build tokenizer
        tokenizer = (TokenizerBase) builder.getClass().getMethod("build").invoke(builder);

    } catch (Exception e) {
        System.err.println("Could not create tokenizer. Got " + e);
        e.printStackTrace();
        System.exit(1);
    }

    File outputFile = null;
    String outputFilename = commandLine.getOptionValue("o");

    if (outputFilename != null) {
        outputFile = new File(outputFilename);
    }

    File statisticsFile = null;
    String statisticsFilename = commandLine.getOptionValue("benchmark-output");

    if (statisticsFilename != null) {
        statisticsFile = new File(statisticsFilename);
    }

    long count = Long.parseLong(commandLine.getOptionValue("c", "0"));

    int nbest = Integer.parseInt(commandLine.getOptionValue("n", "1"));

    Benchmark benchmark = new Builder().tokenizer(tokenizer).inputFile(new File(inputFilename))
            .outputFile(outputFile).outputStatisticsFile(statisticsFile).setOutputStatistiscs(true).count(count)
            .nbest(nbest).build();

    benchmark.benchmark();
}

From source file:com.google.android.vending.licensing.NaaPolicy.java

public NaaPolicy() {

    mMaxRetries = Long.parseLong(DEFAULT_MAX_RETRIES);
    mRetryCount = Long.parseLong(DEFAULT_RETRY_COUNT);
}

From source file:ConsoleUtils.java

public static long readLong() {
    return Long.parseLong(readData());
}

From source file:Main.java

public static long getRunningProcess() {

    File file = new File("/proc/meminfo");
    BufferedReader bufferedReader = null;
    String total = null;/*from   w ww.  ja  v  a  2 s .  c om*/
    try {
        bufferedReader = new BufferedReader(new FileReader(file));
        String line = bufferedReader.readLine();
        char[] charArray = line.toCharArray();
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < charArray.length; i++) {
            char c = charArray[i];
            if (c >= '0' && c <= '9') {
                sb.append(c);
            }
        }
        total = sb.toString();
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    long number = Long.parseLong(total) * 1024;
    return number;
}

From source file:com.dub.skoolie.web.forms.conversion.IdToSchoolConverter.java

@Override
public SchoolBean convert(String s) {
    return schoolServiceImpl.getByID(Long.parseLong(s));
}

From source file:controllers.api.v1.SchemaHistory.java

public static Result getPagedDatasets() {
    ObjectNode result = Json.newObject();

    String name = request().getQueryString("name");
    int page = 1;
    String pageStr = request().getQueryString("page");
    if (StringUtils.isBlank(pageStr)) {
        page = 1;//from w  w  w.j  a  v  a2  s . c  o m
    } else {
        try {
            page = Integer.parseInt(pageStr);
        } catch (NumberFormatException e) {
            Logger.error("SchemaHistory Controller getPagedDatasets wrong page parameter. Error message: "
                    + e.getMessage());
            page = 1;
        }
    }

    Long datasetId = 0L;
    String datasetIdStr = request().getQueryString("datasetId");
    if (StringUtils.isNotBlank(datasetIdStr)) {
        try {
            datasetId = Long.parseLong(datasetIdStr);
        } catch (NumberFormatException e) {
            datasetId = 0L;
        }
    }

    int size = 10;
    String sizeStr = request().getQueryString("size");
    if (StringUtils.isBlank(sizeStr)) {
        size = 10;
    } else {
        try {
            size = Integer.parseInt(sizeStr);
        } catch (NumberFormatException e) {
            Logger.error("SchemaHistory Controller getPagedDatasets wrong size parameter. Error message: "
                    + e.getMessage());
            size = 10;
        }
    }

    result.put("status", "ok");
    result.set("data", SchemaHistoryDAO.getPagedSchemaDataset(name, datasetId, page, size));
    return ok(result);
}