Example usage for java.lang NumberFormatException NumberFormatException

List of usage examples for java.lang NumberFormatException NumberFormatException

Introduction

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

Prototype

public NumberFormatException(String s) 

Source Link

Document

Constructs a NumberFormatException with the specified detail message.

Usage

From source file:TypeUtil.java

/** Parse an int from a substring.
 * Negative numbers are not handled./*w ww  .  ja  v a2 s.com*/
 * @param s String
 * @param offset Offset within string
 * @param length Length of integer or -1 for remainder of string
 * @param base base of the integer
 * @exception NumberFormatException 
 */
public static int parseInt(String s, int offset, int length, int base) throws NumberFormatException {
    int value = 0;

    if (length < 0)
        length = s.length() - offset;

    for (int i = 0; i < length; i++) {
        char c = s.charAt(offset + i);

        int digit = c - '0';
        if (digit < 0 || digit >= base || digit >= 10) {
            digit = 10 + c - 'A';
            if (digit < 10 || digit >= base)
                digit = 10 + c - 'a';
        }
        if (digit < 0 || digit >= base)
            throw new NumberFormatException(s.substring(offset, offset + length));
        value = value * base + digit;
    }
    return value;
}

From source file:com.gargoylesoftware.htmlunit.html.HtmlArea.java

private Ellipse2D parseCircle() {
    final String[] coords = StringUtils.split(getCoordsAttribute(), ',');
    final String radiusString = coords[2].trim();

    final int radius;
    try {//w ww .ja  v a  2 s .  c  o  m
        radius = Integer.parseInt(radiusString);
    } catch (final NumberFormatException nfe) {
        throw new NumberFormatException("Circle radius of " + radiusString + " is not yet implemented.");
    }

    final double centerX = Double.parseDouble(coords[0].trim());
    final double centerY = Double.parseDouble(coords[1].trim());
    final Ellipse2D ellipse = new Ellipse2D.Double(centerX - (double) radius / 2, centerY - (double) radius / 2,
            radius, radius);
    return ellipse;
}

From source file:com.baasbox.util.QueryParams.java

public static QueryParams getParamsFromQueryString(Map<String, String[]> queryString) {
    String fields;//from  w w  w.j a va 2s .co  m
    String where;
    Integer page;
    Integer recordPerPage;
    String groupBy;
    String orderBy;
    Integer depth;
    Boolean count;
    Integer skip;
    String[] params;

    String fieldsFromQS = null;
    String whereFromQS = null;
    String pageFromQS = null;
    String recordPerPageFromQS = null;
    String orderByFromQS = null;
    String groupByFromQS = null;
    String depthFromQS = null;
    String countFromQS = null;
    String skipFromQS = null;

    if (BaasBoxLogger.isTraceEnabled())
        BaasBoxLogger.trace("Method Start");
    //      Map <String,String[]> queryString = header.queryString();
    if (queryString.get(IQueryParametersKeys.FIELDS) != null)
        fieldsFromQS = queryString.get(IQueryParametersKeys.FIELDS)[0];
    if (queryString.get(IQueryParametersKeys.WHERE) != null)
        whereFromQS = queryString.get(IQueryParametersKeys.WHERE)[0];
    if (queryString.get(IQueryParametersKeys.PAGE) != null)
        pageFromQS = queryString.get(IQueryParametersKeys.PAGE)[0];
    if (queryString.get(IQueryParametersKeys.RECORD_PER_PAGE) != null)
        recordPerPageFromQS = queryString.get(IQueryParametersKeys.RECORD_PER_PAGE)[0];
    if (queryString.get(IQueryParametersKeys.RECORDS_PER_PAGE) != null)
        recordPerPageFromQS = queryString.get(IQueryParametersKeys.RECORDS_PER_PAGE)[0];
    if (queryString.get(IQueryParametersKeys.ORDER_BY) != null)
        orderByFromQS = queryString.get(IQueryParametersKeys.ORDER_BY)[0];
    if (queryString.get(IQueryParametersKeys.GROUP_BY) != null)
        groupByFromQS = queryString.get(IQueryParametersKeys.GROUP_BY)[0];
    if (queryString.get(IQueryParametersKeys.DEPTH) != null)
        depthFromQS = queryString.get(IQueryParametersKeys.DEPTH)[0];
    if (queryString.get(IQueryParametersKeys.COUNT) != null)
        countFromQS = queryString.get(IQueryParametersKeys.COUNT)[0];
    if (queryString.get(IQueryParametersKeys.SKIP) != null)
        skipFromQS = queryString.get(IQueryParametersKeys.SKIP)[0];

    params = queryString.get(IQueryParametersKeys.PARAMS);

    fields = fieldsFromQS;
    where = whereFromQS;
    groupBy = groupByFromQS;
    orderBy = orderByFromQS;
    try {
        page = pageFromQS == null ? null : new Integer(pageFromQS);
    } catch (NumberFormatException e) {
        throw new NumberFormatException(IQueryParametersKeys.PAGE + " parameter must be a valid Integer");
    }
    try {
        recordPerPage = recordPerPageFromQS == null ? null : new Integer(recordPerPageFromQS);
    } catch (NumberFormatException e) {
        throw new NumberFormatException(
                IQueryParametersKeys.RECORDS_PER_PAGE + " parameter must be a valid Integer");
    }
    try {
        depth = depthFromQS == null ? null : new Integer(depthFromQS);
    } catch (NumberFormatException e) {
        throw new NumberFormatException(IQueryParametersKeys.DEPTH + " parameter must be a valid Integer");
    }
    try {
        count = countFromQS == null ? null : new Boolean(countFromQS);
    } catch (NumberFormatException e) {
        throw new NumberFormatException(IQueryParametersKeys.COUNT + " parameter must be true or false");
    }
    try {
        skip = skipFromQS == null ? null : new Integer(skipFromQS);
    } catch (NumberFormatException e) {
        throw new NumberFormatException(IQueryParametersKeys.SKIP + " parameter must be a valid Integer");
    }
    QueryParams qryp = new QueryParams(fields, groupBy, where, page, recordPerPage, orderBy, depth, params,
            count, skip);

    if (BaasBoxLogger.isTraceEnabled())
        BaasBoxLogger.trace("Method End");

    return qryp;

}

From source file:org.ardverk.daap.DaapUtil.java

/**
 *
 *//*www.ja va 2 s. com*/
public static long parseUInt(String value) throws NumberFormatException {
    try {
        return UIntChunk.checkUIntRange(Long.parseLong(value));
    } catch (IllegalArgumentException err) {
        throw new NumberFormatException("For input: " + value);
    }
}

From source file:com.core.meka.SOMController.java

private double[][] crearArreglo(String[] patrones, TextArea resultArea) throws NumberFormatException {
    int totalPatrones = patrones.length;
    int dimension = patrones[0].split(",").length;
    double[][] result = new double[totalPatrones][dimension];

    for (int i = 0; i < totalPatrones; i++) {
        String[] patron = patrones[i].split(",");
        double[] patronDouble = new double[dimension];
        for (int j = 0; j < patron.length; j++) {
            try {
                patronDouble[j] = Double.valueOf(patron[j]);
            } catch (NumberFormatException e) {
                resultArea.setText("Imposible formatear ese numero, verifiquelo\n"
                        + e.getMessage().replaceAll("\\)", ")\n")
                                .replaceAll("For input string", "Cadena de entrada")
                                .replaceAll("multiple points", "Puntos multiples")
                        + ": " + patron[j] + "\n\n" + resultArea.getText());
                throw new NumberFormatException("Imposible formatear ese numero, veriquelo");
            }//from  ww w .j  av a  2s . c  o m
        }
        result[i] = patronDouble;
    }

    return result;
}

From source file:keel.Algorithms.Neural_Networks.NNEP_Common.problem.ProblemEvaluator.java

/**
 * <p> //  ww w  .java 2  s.c  o m
 * Read and normalize evaluator datasets
 * </p>
 * @throws IOException Data not correct
 * @throws NumberFormatException Format of data not correct
 */
public void readData() throws IOException, NumberFormatException {

    // Read trainData
    try {
        unscaledTrainData.read();
    } catch (IOException e) {
        throw new IOException("trainData IOException: " + e.getLocalizedMessage());
    } catch (NumberFormatException e) {
        throw new NumberFormatException("trainData NumberFormatException: " + e.getLocalizedMessage());
    }

    // Read testData
    try {
        unscaledTestData.read();
    } catch (IOException e) {
        throw new IOException("testData IOException: " + e.getLocalizedMessage());
    } catch (NumberFormatException e) {
        throw new NumberFormatException("testData NumberFormatException: " + e.getLocalizedMessage());
    }

    normalizeData();
}

From source file:Main.java

public static float fastGetFloat(String raw, int precision) {
    if (!TextUtils.isEmpty(raw)) {
        boolean positive = true;
        int loc = 0;
        if (raw.charAt(0) == '-') {
            positive = false;// w w  w .  j a v  a  2 s  .c  o m
            loc++;
        } else if (raw.charAt(0) == '+') {
            loc++;
        }

        char digit;
        float result = 0;
        while (loc < raw.length() && (digit = raw.charAt(loc)) >= '0' && digit <= '9') {
            result = result * 10 + digit - '0';
            loc++;
        }

        if (loc < raw.length()) {
            if (raw.charAt(loc) == '.') {
                loc++;
                int remainderLength = 10;
                int counter = 0;
                while (loc < raw.length() && counter < precision
                        && ((digit = raw.charAt(loc)) >= '0' && digit <= '9')) {
                    result += (digit - '0') / (float) remainderLength;
                    remainderLength *= 10;
                    loc++;
                    counter++;
                }
            } else {
                throw new NumberFormatException("Illegal separator");
            }
        }

        if (!positive)
            result *= -1;
        return result;
    }
    throw new NumberFormatException("NullNumber");
}

From source file:TypeUtil.java

/** Parse an int from a byte array of ascii characters.
 * Negative numbers are not handled.//  w  w  w  .  j a  v  a 2 s.c o  m
 * @param b byte array
 * @param offset Offset within string
 * @param length Length of integer or -1 for remainder of string
 * @param base base of the integer
 * @exception NumberFormatException 
 */
public static int parseInt(byte[] b, int offset, int length, int base) throws NumberFormatException {
    int value = 0;

    if (length < 0)
        length = b.length - offset;

    for (int i = 0; i < length; i++) {
        char c = (char) (0xff & b[offset + i]);

        int digit = c - '0';
        if (digit < 0 || digit >= base || digit >= 10) {
            digit = 10 + c - 'A';
            if (digit < 10 || digit >= base)
                digit = 10 + c - 'a';
        }
        if (digit < 0 || digit >= base)
            throw new NumberFormatException(new String(b, offset, length));
        value = value * base + digit;
    }
    return value;
}

From source file:org.tupelo_schneck.electric.Options.java

private boolean optionalBoolean(OptionWrapper cmd, String long_param, String short_param, boolean defaultVal) {
    String val = cmd.getOptionValue(long_param, short_param);
    if (val == null)
        return !defaultVal;
    else {/*  w ww .  j  a  v a 2s.co m*/
        val = val.toLowerCase();
        if ("yes".equals(val) || "true".equals(val)) {
            return true;
        }
        if ("no".equals(val) || "false".equals(val)) {
            return false;
        }
        throw new NumberFormatException("expecting true/false or yes/no for " + val);
    }
}

From source file:org.deegree.tools.rendering.manager.DataManager.java

/**
 * @param optionValue/*from   w w w  .  j  a  va2s  . c  o  m*/
 * @return
 */
private static double[] createTranslationVector(String optionValue) {
    double[] result = new double[2];
    if (optionValue != null && !"".equals(optionValue)) {
        try {
            result = ArrayUtils.splitAsDoubles(optionValue, ",");
            if (result.length != 2) {
                throw new NumberFormatException(
                        "Illigal number of values, only two dimensional translations are allowed");
            }
        } catch (NumberFormatException e) {
            System.err.println("Translation vector " + optionValue
                    + " could not be read, please make sure it is a comma seperated list of (floating point) numbers: "
                    + e.getLocalizedMessage());
        }
    }
    return result;
}