Example usage for java.lang NumberFormatException getMessage

List of usage examples for java.lang NumberFormatException getMessage

Introduction

In this page you can find the example usage for java.lang NumberFormatException getMessage.

Prototype

public String getMessage() 

Source Link

Document

Returns the detail message string of this throwable.

Usage

From source file:is.merkor.core.cli.Main.java

public static List<String> processCommandLine(final CommandLine cmdLine) {
    List<String> results = new ArrayList<String>();

    if (cmdLine.hasOption("help") || cmdLine.hasOption("h")) {
        HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp("java -jar MerkOrCore.jar", MerkorCoreCommandLineOptions.options);
        results.add("no message");
    }//from  www. j  a v a2 s  .  com
    // non default redis host / port?
    if (cmdLine.hasOption("host")) {
        redisHost = cmdLine.getOptionValue("host");
    }
    if (cmdLine.hasOption("port")) {
        try {
            redisPort = Integer.parseInt(cmdLine.getOptionValue("port"));
        } catch (NumberFormatException e) {
            results.add(e.getMessage());
            return results;
        }
    }
    // now Redis host and port are set or default is used
    try {
        queries = new MerkorCommandLineQueries(redisHost, redisPort);
    } catch (Exception e) {
        results.add("Couldn't connect to Redis. See logs/logging.log for info");
        return results;
    }

    // info on lexical items wanted? ///////////////////////   
    String value = cmdLine.getOptionValue("items");
    if (value != null) {
        if (value.contains("?") || value.contains("*"))
            return queries.getItemsForRegex(value);
        else
            return queries.getItemsForLemma(value);
    }

    // info on relations wanted? ///////////////////////////
    value = cmdLine.getOptionValue("relations");
    String number = cmdLine.getOptionValue("n");
    if (null != value && null != number)
        return queries.getMostRelated(value, number);
    else if (null != value) {
        return queries.getRelationsFor(value);
    }

    String fromLemma = cmdLine.getOptionValue("rel_from");
    String toLemma = cmdLine.getOptionValue("rel_to");
    String type = cmdLine.getOptionValue("rel_type");

    if (null != fromLemma && null != toLemma)
        return queries.getRelationsFor(fromLemma, toLemma);
    if (null != fromLemma && null != type)
        return queries.getRelationsHavingLeft(fromLemma, type);
    if (null != toLemma && null != type)
        return queries.getRelationsHavingRight(toLemma, type);

    if (null != fromLemma && null == toLemma && null == type) {
        results.add("param -rel_from needs to be followed by param -rel_to or -rel_type");
        return results;
    }
    if (null != toLemma && null == fromLemma && null == type) {
        results.add("param -rel_to needs to be accompanied by param -rel_from or -rel_type");
        return results;
    }

    if (null != type && null != number)
        return queries.getTopRelations(type, number);
    if (null != type && null == number)
        return queries.getTopRelations(type, DEFAULT_NUMBER);

    // info on clusters and domains wanted? ///////////////////////////

    if (cmdLine.hasOption("clusters"))
        return queries.getAllClusterNames();

    String clusterId = cmdLine.getOptionValue("cluster_id");
    if (null != clusterId)
        return queries.getClusterById(clusterId);

    String clustersMatching = cmdLine.getOptionValue("clusters_matching");
    if (null != clustersMatching)
        return queries.getClustersMatching(clustersMatching);

    String clustersHaving = cmdLine.getOptionValue("clusters_having");
    if (null != clustersHaving)
        return queries.getAllClustersFor(clustersHaving);
    clustersHaving = cmdLine.getOptionValue("domains_having");
    if (null != clustersHaving)
        return queries.getAllDomainsFor(clustersHaving);

    String cluster = cmdLine.getOptionValue("items_for_cluster");
    if (null != cluster)
        return queries.getItemsForCluster(cluster);

    String domain = cmdLine.getOptionValue("items_for_domain");
    if (null != domain)
        return queries.getItemsForDomain(domain);

    return results;
}

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

private static int parseInt(String queryString, int defaultValue) {
    if (!StringUtils.isBlank(queryString)) {
        try {//from w  ww.  j a  v  a  2s .  co m
            return Integer.parseInt(queryString);
        } catch (NumberFormatException e) {
            Logger.error("Dashboard Controller query string wrong parameter: " + queryString
                    + ". Error message: " + e.getMessage());
        }
    }
    return defaultValue;
}

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  ww .  j  av a  2  s .  co 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);
}

From source file:Main.java

public static Long stringToLong(String str) {
    if (str == null) {
        return null;
    } else {/*from   ww  w .  j a  v  a 2s.  c o  m*/
        try {
            return Long.parseLong(str);
        } catch (NumberFormatException e) {
            try {
                Double d = Double.valueOf(str);
                if (d.doubleValue() > mMaxLong.doubleValue() + 1.0) {
                    Log.w(TAG, "Value " + d + " too large for long");
                    return null;
                }
                return Long.valueOf(d.longValue());
            } catch (NumberFormatException nfe2) {
                Log.w(TAG,
                        "Unable to interpret value " + str + " in field being "
                                + "converted to long, caught NumberFormatException <" + nfe2.getMessage()
                                + "> field discarded");
                return null;
            }
        }
    }
}

From source file:com.alvermont.terraj.fracplanet.io.ColourFile.java

/**
 * Read a colour file and return a list of FloatRGBA values that it contains
 *
 *
 * @param source The <code>File</code> object to use to read from
 * @return A list of <code>FloatRGBA</code> objects as read from the file
 * @throws java.io.IOException If there is an error opening or reading from
 * the file etc.//from w  w w . java2  s. co  m
 */
public static List<FloatRGBA> readFile(File source) throws IOException {
    final BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(source)));

    final List<FloatRGBA> colours = new ArrayList<FloatRGBA>();

    String line = null;

    try {
        do {
            line = reader.readLine();

            if (line != null) {
                line = line.trim();
            }

            if ((line != null) && (line.length() > 0) && !line.startsWith("#")) {
                colours.add(parseColour(line));
            }
        } while (line != null);

        return colours;
    } catch (NumberFormatException ex) {
        log.error("NumberFormatException reading file: " + ex.getMessage(), ex);

        throw new IOException("Bad data found in file");
    } catch (IOException ex) {
        log.error("IOException reading file: " + ex.getMessage(), ex);

        throw ex;
    } finally {
        if (reader != null) {
            reader.close();
        }
    }
}

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

public static Result getScriptRuntimeByJobID(int applicationID, int jobID) {
    ObjectNode result = Json.newObject();

    int attemptNumber = 0;
    String attemptStr = request().getQueryString("attempt_number");
    if (StringUtils.isBlank(attemptStr)) {
        attemptNumber = 0;/*from  w ww  .  j  a v a  2  s.  c  o  m*/
    } else {
        try {
            attemptNumber = Integer.parseInt(attemptStr);
        } catch (NumberFormatException e) {
            Logger.error("ScriptFinder Controller getPagedScripts wrong page parameter. Error message: "
                    + e.getMessage());
            attemptNumber = 0;
        }
    }

    result.put("status", "ok");
    result.set("data", Json.toJson(ScriptFinderDAO.getPagedScriptRuntime(applicationID, jobID)));
    return ok(result);
}

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

public static Result getScriptLineageByJobID(int applicationID, int jobID) {
    ObjectNode result = Json.newObject();

    int attemptNumber = 0;
    String attemptStr = request().getQueryString("attempt_number");
    if (StringUtils.isBlank(attemptStr)) {
        attemptNumber = 0;//from www .j  ava2s .c  o  m
    } else {
        try {
            attemptNumber = Integer.parseInt(attemptStr);
        } catch (NumberFormatException e) {
            Logger.error("ScriptFinder Controller getPagedScripts wrong page parameter. Error message: "
                    + e.getMessage());
            attemptNumber = 0;
        }
    }

    result.put("status", "ok");
    result.set("data", Json.toJson(ScriptFinderDAO.getScriptLineage(applicationID, jobID)));
    return ok(result);
}

From source file:de.berlios.jhelpdesk.model.TicketStatus.java

public static List<TicketStatus> listFromString(String inputString) {
    List<TicketStatus> resultList = new ArrayList<TicketStatus>();
    if (inputString != null) {
        for (String statusId : inputString.split(",")) {
            try {
                resultList.add(TicketStatus.fromInt(Integer.parseInt(statusId)));
            } catch (NumberFormatException nfe) {
                log.debug(nfe.getMessage());
            }/*from  ww w  .j ava  2s.c o  m*/
        }
    }
    return resultList;
}

From source file:com.arcao.geocaching.api.data.coordinates.CoordinatesParser.java

protected static ParseResult parse(String coordinate, CoordinateType coordinateType) throws ParseException {
    Pattern pattern;/*from   ww w.  j a va 2 s  .c o  m*/

    switch (coordinateType) {
    case LAT_UNSAFE:
        pattern = LATITUDE_PATTERN_UNSAFE;
        break;
    case LON_UNSAFE:
        pattern = LONGITUDE_PATTERN_UNSAFE;
        break;
    case LON:
        pattern = LONGITUDE_PATTERN;
        break;
    case LAT:
    default:
        pattern = LATITUDE_PATTERN;
        break;
    }

    final Matcher matcher = pattern.matcher(coordinate);

    if (matcher.find()) {
        double sign = matcher.group(1).equalsIgnoreCase("S") || matcher.group(1).equalsIgnoreCase("W") ? -1.0
                : 1.0;
        double degree = Double.parseDouble(matcher.group(2));

        if (degree < 0) {
            sign = -1;
            degree = Math.abs(degree);
        }

        double minutes = 0.0;
        double seconds = 0.0;

        if (matcher.group(3) != null) {
            minutes = Double.parseDouble(matcher.group(3));

            if (matcher.group(4) != null) {
                seconds = Double.parseDouble("0." + matcher.group(4)) * 60.0;
            } else if (matcher.group(5) != null) {
                seconds = Double.parseDouble(matcher.group(5).replace(",", "."));
            }
        }

        double result = sign * (degree + minutes / 60.0 + seconds / 3600.0);

        // normalize result
        switch (coordinateType) {
        case LON_UNSAFE:
        case LON:
            result = normalize(result, -180, 180);
            break;
        case LAT_UNSAFE:
        case LAT:
        default:
            result = normalize(result, -90, 90);
            break;
        }

        return new ParseResult(result, matcher.start(), matcher.group().length());
    } else {

        // Nothing found with "N 52...", try to match string as decimaldegree
        try {
            final String[] items = StringUtils.split(coordinate.trim());
            if (items.length > 0) {
                final int index = (coordinateType == CoordinateType.LON ? items.length - 1 : 0);
                final int pos = (coordinateType == CoordinateType.LON ? coordinate.lastIndexOf(items[index])
                        : coordinate.indexOf(items[index]));
                return new ParseResult(Double.parseDouble(items[index]), pos, items[index].length());
            }
        } catch (NumberFormatException e) {
            logger.error(e.getMessage(), e);
        }
    }
    throw new ParseException("Could not parse coordinate: \"" + coordinate + "\"", 0);
}

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

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

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

    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("ScriptFinder Controller getPagedScripts wrong size parameter. Error message: "
                    + e.getMessage());
            size = 10;
        }
    }

    String filterOptStr = request().getQueryString("query");
    JsonNode filterOpt = null;
    try {
        String filterOptStrDecode = URLDecoder.decode(filterOptStr, "UTF-8");
        filterOpt = Json.parse(filterOptStrDecode);
    } catch (Exception e) {
        Logger.error("ScriptFinder Controller getScripts query filterOpt wrong JSON format. Error message: "
                + e.getMessage());
        filterOpt = null;
    }

    result.put("status", "ok");
    result.set("data", ScriptFinderDAO.getPagedScripts(filterOpt, page, size));
    return ok(result);
}