List of usage examples for java.lang Long parseLong
public static long parseLong(String s) throws NumberFormatException
From source file:Main.java
public static long[] parseLongArray(final String string, final char token) { if (string == null) return new long[0]; final String[] items_string_array = string.split(String.valueOf(token)); final ArrayList<Long> items_list = new ArrayList<Long>(); for (final String id_string : items_string_array) { try {/*w w w.j a v a 2s . c o m*/ items_list.add(Long.parseLong(id_string)); } catch (final NumberFormatException e) { // Ignore. } } final int list_size = items_list.size(); final long[] array = new long[list_size]; for (int i = 0; i < list_size; i++) { array[i] = items_list.get(i); } return array; }
From source file:AIR.Common.Web.WebHelper.java
public static long getQueryValueLong(String name) { String value = getQueryString(name); if (StringUtils.isEmpty(value)) return 0; return Long.parseLong(value); }
From source file:Main.java
/** * Returns the long attribute value for the passed name in the passed node. * @param node the node to get the attribute from * @param name the name of the attribute * @param defaultValue the value to return if the node did not contain the attribute * @return The attribute value or the default value if it is not found. *///from ww w . j a va 2 s . c o m public static long getLongAttributeByName(Node node, String name, long defaultValue) { String s = getAttributeByName(node, name, null); if (s == null) return defaultValue; try { return Long.parseLong(s.trim()); } catch (Exception e) { return defaultValue; } }
From source file:gov.nih.nci.caarray.application.util.Utils.java
/** * @param value the value to test./*from w w w . ja v a 2 s .c o m*/ * @return true is the value can be parsed as an Long. */ public static boolean isLong(String value) { try { Long.parseLong(value); return true; } catch (NumberFormatException e) { return false; } }
From source file:com.scf.web.context.spring.ProjectLog4jWebConfigurer.java
public static void initLogging(ServletContext servletContext, String location) { if (location != null) { try {//from ww w .j ava 2 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:net.larry1123.util.api.time.StringTime.java
/** * Takes just a number or a set of numbers with a D, H, M or, S fallowing it * The letters can be upper or lower case * 15h 50m 5s/*ww w . j a v a2 s . c o m*/ * * @param string Whole String to decode into parts * * @return the amount of time in milliseconds that the time string Decodes to */ public static long millisecondsFromString(String string) { if (string == null) { throw new NullPointerException("String can not be null"); } string = string.trim(); long ret = 0; try { ret = Long.parseLong(string); } catch (NumberFormatException e) { for (String part : string.split(" ")) { if (part.length() >= 2) { String time = part.substring(part.length() - 1); switch (Part.getFromString(time)) { case DAYS: try { Long days = Long.parseLong(part.substring(0, part.length() - 1)); ret += days * DateUtils.MILLIS_PER_DAY; } catch (NumberFormatException error) { // DO nothing right now } break; case HOUR: try { Long hours = Long.parseLong(part.substring(0, part.length() - 1)); ret += hours * DateUtils.MILLIS_PER_HOUR; } catch (NumberFormatException error) { // DO nothing right now } break; case MINUTES: try { Long minutes = Long.parseLong(part.substring(0, part.length() - 1)); ret += minutes * DateUtils.MILLIS_PER_MINUTE; } catch (NumberFormatException error) { // DO nothing right now } break; case SECONDS: try { Long seconds = Long.parseLong(part.substring(0, part.length() - 1)); ret += seconds * DateUtils.MILLIS_PER_SECOND; } catch (NumberFormatException error) { // DO nothing right now } break; default: // Something is malformed just let it fly by and keep going break; } } else if (part.length() == 1) { switch (Part.getFromString("" + part.charAt(1))) { case DAYS: ret += DateUtils.MILLIS_PER_DAY; break; case HOUR: ret += DateUtils.MILLIS_PER_HOUR; break; case MINUTES: ret += DateUtils.MILLIS_PER_MINUTE; break; case SECONDS: ret += DateUtils.MILLIS_PER_SECOND; break; default: // Something is malformed just let it fly by and keep going break; } } } } return ret; }
From source file:com.todoroo.astrid.data.RemoteModel.java
public static boolean isValidUuid(String uuid) { try {/* ww w .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:Main.java
/** * get total size of ram. Work for all API levels. * @return total size in byte//w w w . ja v a2s.c om * @deprecated */ public static long getTotalRamSize() { StringBuilder sb = new StringBuilder(); //read this file and pick up numbers File file = new File("/proc/meminfo"); BufferedReader br = null; try { br = new BufferedReader(new FileReader(file)); String readLine = br.readLine(); char[] charArray = readLine.toCharArray(); for (char c : charArray) { if (c >= '0' && c <= '9') { sb.append(c); } } String string = sb.toString(); long parseLong = Long.parseLong(string); return parseLong * 1024; } catch (Exception e) { e.printStackTrace(); } finally { if (br != null) { try { br.close(); } catch (IOException e) { e.printStackTrace(); } } } return 0; }
From source file:Main.java
private static long parserNumber(String line) throws Exception { long ret = 0; if (!TextUtils.isEmpty(line)) { String[] delim = line.split(" "); if (delim.length >= 1) { ret = Long.parseLong(delim[0]); }//from www . j a va 2s . c om } return ret; }
From source file:Main.java
/** * Add an entry to the database/*from w w w.j a v a 2s .co m*/ * * @param db * pointer to database * @param recordLine * String with a record * format: yy,mm,dd,hh:mm,light,solar,consumption * e.g.: "15,08,13,13:54,35000,613.456,-120.22" */ public static void addDay(SQLiteDatabase db, String recordLine) { /* Parse the string into its single values */ String[] valuesPerLine = recordLine.split(","); if (valuesPerLine.length == 1) { return; } /** String list with hour & minute values */ String[] hourSplit = valuesPerLine[3].split(":"); /** ContentValues to hold the measured and calculated values to be added to the database */ ContentValues values = new ContentValues(14); values.put("year", Integer.parseInt(valuesPerLine[0])); values.put("month", Integer.parseInt(valuesPerLine[1])); values.put("day", Integer.parseInt(valuesPerLine[2])); values.put("hour", Integer.parseInt(hourSplit[0])); values.put("minute", Integer.parseInt(hourSplit[1])); values.put("solar", Double.parseDouble(valuesPerLine[5])); values.put("cons", Double.parseDouble(valuesPerLine[6])); values.put("light", Long.parseLong(valuesPerLine[4])); db.insert(TABLE_NAME, null, values); }