openrat-java-client

Unnamed repository; edit this file 'description' to name the repository.
git clone http://git.code.weiherhei.de/openrat-java-client.git
Log | Files | Refs

NumberUtils.java (743B)


      1 package de.openrat.client.util;
      2 
      3 public class NumberUtils
      4 {
      5 	/**
      6 	 * Null-safe and Exception-safe conversion from {@link String} to
      7 	 * {@link Integer}.
      8 	 * 
      9 	 * @param number
     10 	 *            Number
     11 	 * @return int (0, if number is not a number)
     12 	 */
     13 	public static int toInt(String number)
     14 	{
     15 		try
     16 		{
     17 			return Integer.parseInt(number);
     18 		}
     19 		catch (NumberFormatException e)
     20 		{
     21 			return 0;
     22 		}
     23 	}
     24 
     25 	/**
     26 	 * Null-safe and Exception-safe conversion from {@link String} to
     27 	 * {@link Long}.
     28 	 * 
     29 	 * @param number
     30 	 *            Number
     31 	 * @return int (0, if number is not a number)
     32 	 */
     33 	public static long toLong(String number)
     34 	{
     35 		try
     36 		{
     37 			return Long.parseLong(number);
     38 		}
     39 		catch (NumberFormatException e)
     40 		{
     41 			return 0;
     42 		}
     43 	}
     44 
     45 }