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:Main.java

@SuppressWarnings("unchecked")
public static <T> T parse(Class<T> type, String stringValue) throws IllegalArgumentException {
    if (type.equals(String.class)) {
        return (T) stringValue;
    }//from   www  .j  ava  2s. c  o m

    if (type.equals(Boolean.class) || type.equals(boolean.class)) {
        return (T) Boolean.valueOf(stringValue);
    }
    try {
        if (type.equals(Integer.class) || type.equals(int.class)) {
            return (T) Integer.valueOf(stringValue);
        }
        if (type.equals(Long.class) || type.equals(long.class)) {
            return (T) Long.valueOf(stringValue);
        }
        if (type.equals(Short.class) || type.equals(short.class)) {
            return (T) Short.valueOf(stringValue);
        }
        if (type.equals(Byte.class) || type.equals(byte.class)) {
            return (T) Byte.valueOf(stringValue);
        }
        if (type.equals(Double.class) || type.equals(double.class)) {
            return (T) Double.valueOf(stringValue);
        }
        if (type.equals(Float.class) || type.equals(float.class)) {
            return (T) Float.valueOf(stringValue);
        }
        if (type.equals(File.class)) {
            return (T) new File(stringValue);
        }
    } catch (final NumberFormatException e) {
        throw new IllegalArgumentException(e.getMessage(), e);
    }
    if (type.isEnum()) {
        @SuppressWarnings("rawtypes")
        final Class enumType = type;
        return (T) Enum.valueOf(enumType, stringValue);
    }
    throw new IllegalArgumentException("Can't handle type " + type);

}

From source file:net.neurowork.cenatic.centraldir.workers.xml.AbstractXmlImporter.java

public static Integer getId(String id) {
    Integer retId = null;//  ww w . jav a  2s .c om
    try {
        retId = Integer.parseInt(id);
    } catch (NumberFormatException e) {
        logger.error(e.getMessage());
        retId = 0;
    }
    return retId;
}

From source file:com.todoroo.astrid.data.RemoteModel.java

public static boolean isValidUuid(String uuid) {
    try {/*from   www  .j a v  a2  s .c o  m*/
        long value = Long.parseLong(uuid);
        return value > 0;
    } catch (NumberFormatException e) {
        log.error(e.getMessage(), e);
        return isUuidEmpty(uuid);
    }
}

From source file:gov.nasa.ensemble.common.ERGBUtils.java

/**
 * COPIED FROM org.eclipse.jface.resource.StringConverter
 * //from   www  .  jav a 2 s  . c o m
 * Converts the given value into an SWT RGB color value.
 * This method fails if the value does not represent an RGB
 * color value.
 * <p>
 * A valid RGB color value representation is a string of the form
 * <code><it>red</it>,<it>green</it></code>,<it>blue</it></code> where
 * <code><it>red</it></code>, <it>green</it></code>, and 
 * <code><it>blue</it></code> are valid ints.
 * </p>
 *
 * @param value the value to be converted
 * @return the value as an RGB color value
 * @exception DataFormatException if the given value does not represent
 *   an RGB color value
 */
private static ERGB asRGB(String value) throws DataFormatException {
    if (value == null) {
        throw new DataFormatException("Null doesn't represent a valid RGB"); //$NON-NLS-1$
    }
    StringTokenizer stok = new StringTokenizer(value, ","); //$NON-NLS-1$

    try {
        String red = stok.nextToken().trim();
        String green = stok.nextToken().trim();
        String blue = stok.nextToken().trim();
        int rval = 0, gval = 0, bval = 0;
        try {
            rval = Integer.parseInt(red);
            gval = Integer.parseInt(green);
            bval = Integer.parseInt(blue);
        } catch (NumberFormatException e) {
            throw new DataFormatException(e.getMessage());
        }
        return new ERGB(rval, gval, bval);
    } catch (NoSuchElementException e) {
        throw new DataFormatException(e.getMessage());
    }
}

From source file:it.unibas.spicy.persistence.Types.java

public static Object getTypedValue(String type, Object value) throws DAOException {
    if (value == null || value.toString().equalsIgnoreCase("NULL")) {
        return NullValueFactory.getNullValue();
    }/*from   ww  w.  j av a2  s .  c o m*/
    if (type.equals(BOOLEAN)) {
        return Boolean.parseBoolean(value.toString());
    }
    if (type.equals(STRING)) {
        return value.toString();
    }
    if (type.equals(INTEGER)) {
        try {
            return Integer.parseInt(value.toString());
        } catch (NumberFormatException ex) {
            logger.error(ex);
            throw new DAOException(ex.getMessage());
        }
    }
    if (type.equals(DOUBLE)) {
        try {
            return Double.parseDouble(value.toString());
        } catch (NumberFormatException ex) {
            logger.error(ex);
            throw new DAOException(ex.getMessage());
        }
    }
    if (type.equals(FLOAT)) {
        try {
            return Float.parseFloat(value.toString());
        } catch (NumberFormatException ex) {
            logger.error(ex);
            throw new DAOException(ex.getMessage());
        }
    }
    if (type.equals(DATE) || type.equals(DATETIME)) {
        return value.toString();
        //            try {
        //                return DateFormat.getDateInstance().parse(value.toString());
        //            } catch (ParseException ex) {
        //                logger.error(ex);
        //                throw new DAOException(ex.getMessage());
        //            }
    }
    return value.toString();
}

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

public static List<TicketPriority> listFromString(String inputString) {
    List<TicketPriority> resultList = new ArrayList<TicketPriority>();
    if (inputString != null) {
        for (String priorityId : inputString.split(",")) {
            try {
                resultList.add(TicketPriority.fromInt(Integer.parseInt(priorityId)));
            } catch (NumberFormatException nfe) {
                log.debug(nfe.getMessage());
            }//from   w w w  . j  a  va2  s. co  m
        }
    }
    return resultList;
}

From source file:com.scf.web.context.spring.ProjectLog4jWebConfigurer.java

public static void initLogging(ServletContext servletContext, String location) {

    if (location != null) {
        try {//from  www  .  ja  v a2 s.c o m
            // Write log message to server log.
            servletContext.log("Initializing log4j from [" + location + "]");

            // Check whether refresh interval was specified.
            String intervalString = servletContext.getInitParameter(REFRESH_INTERVAL_PARAM);
            if (StringUtils.hasText(intervalString)) {
                // Initialize with refresh interval, i.e. with log4j's watchdog thread,
                // checking the file in the background.
                try {
                    long refreshInterval = Long.parseLong(intervalString);
                    Log4jConfigurer.initLogging(location, refreshInterval);
                } catch (NumberFormatException ex) {
                    throw new IllegalArgumentException(
                            "Invalid 'log4jRefreshInterval' parameter: " + ex.getMessage());
                }
            } else {
                // Initialize without refresh check, i.e. without log4j's watchdog thread.
                Log4jConfigurer.initLogging(location);
            }
        } catch (FileNotFoundException ex) {
            throw new IllegalArgumentException("Invalid 'log4jConfigLocation' parameter: " + ex.getMessage());
        }
    }
}

From source file:de.msg.terminfindung.gui.util.ViewUtil.java

/**
 * Liest einen Request-Parameter aus der URL, wandelt ihn in einen Long-Wert um
 * und gibt diesen Wert zurck./*from  w  ww  .ja v  a  2s .  co m*/
 **
 * @param name  der Namen des Request-Parameters
 * @param context der Spring Request Context
 */
@Deprecated
public static TFNumberHolder getRequestParameterAsLong(String name, ExternalContext context) {

    Long result = 0L;
    String paramValueStr = getRequestParameter(name, context);
    try {
        result = Long.parseLong(paramValueStr);
    } catch (NumberFormatException e) {
        LOG.warn("Request Parameter " + name + " konnte nicht in Long konvertiert werden, gebe 0L zurck",
                e.getMessage());
    }
    return new TFNumberHolder(result);
}

From source file:Main.java

public static Float stringToFloat(String str) {
    if (str == null) {
        return null;
    } else {/*  w ww. j a  v  a 2 s .  c  o  m*/
        try {
            return Float.parseFloat(str);
        } catch (NumberFormatException e) {
            Log.w(TAG,
                    "Unable to interpret value " + str + " in field being "
                            + "converted to float, caught NumberFormatException <" + e.getMessage()
                            + "> field discarded");
            return null;
        }
    }
}

From source file:de.highbyte_le.weberknecht.Version.java

protected static Version parseProperties(Properties properties) {
    try {//from ww w.j a v  a2s .co m
        int major = Integer.parseInt(properties.getProperty("version.weberknecht.major"));
        int minor = Integer.parseInt(properties.getProperty("version.weberknecht.minor"));
        int patch = Integer.parseInt(properties.getProperty("version.weberknecht.patch"));
        String branch = properties.getProperty("version.weberknecht.branch");

        return new Version(major, minor, patch, branch);
    } catch (NumberFormatException e) {
        logger.error("parseProperties() - number format exception: " + e.getMessage());
    }

    return null;
}