List of usage examples for java.lang Long parseLong
public static long parseLong(String s) throws NumberFormatException
From source file:Main.java
public static void shiftTableUriIds(HashMap<String, ArrayList<ContentValues>> operationMap, String tableName, String idColumnName, String authority, String path, long topTableId) { ArrayList<ContentValues> restoreOperations = operationMap.get(tableName); if (null == restoreOperations) { return;/*from w ww .java2s . c o m*/ } for (ContentValues restoreCv : restoreOperations) { if (restoreCv.containsKey(idColumnName) && null != restoreCv.getAsString(idColumnName)) { Uri uri = Uri.parse(restoreCv.getAsString(idColumnName)); if ("content".equalsIgnoreCase(uri.getScheme()) && authority.equals(uri.getAuthority()) && uri.getPath().substring(0, uri.getPath().lastIndexOf('/')).equals(path)) { Uri.Builder newUri = uri.buildUpon() .path(uri.getPath().substring(0, uri.getPath().lastIndexOf('/'))) .appendPath(String.valueOf( Long.parseLong(uri.getPath().substring(uri.getPath().lastIndexOf('/') + 1)) + topTableId)); // Log.v("URI", uri.getPath().substring(uri.getPath().lastIndexOf('/')+1)); // Log.v("URI", String.valueOf(Long.parseLong(uri.getPath().substring(uri.getPath().lastIndexOf('/')+1)) + topTableId)); restoreCv.put(idColumnName, newUri.build().toString()); } } } }
From source file:Main.java
/** * Convert a String to a long if possible. Instead of throwing an exception like Long.parseLong() does, return a specified default long value if an error is * encountered.// w w w . j a v a 2 s .c om * * @param string * String to be parsed * @param defaultValue * default value to be returned if a parse error * @return parsed long value */ public static long parseLong(final String string, final long defaultValue) { try { return Long.parseLong(string); } catch (final Exception e) { return defaultValue; } }
From source file:org.aevans.goat.net.ConnectionUtils.java
public static ConnectionKeepAliveStrategy getConnectionKeepAliveStrategy(final int keepAlive) { return new ConnectionKeepAliveStrategy() { public long getKeepAliveDuration(HttpResponse response, HttpContext context) { // Honor 'keep-alive' header HeaderElementIterator it = new BasicHeaderElementIterator( response.headerIterator(HTTP.CONN_KEEP_ALIVE)); while (it.hasNext()) { HeaderElement he = it.nextElement(); String param = he.getName(); String value = he.getValue(); if (value != null && param.equalsIgnoreCase("timeout")) { try { return Long.parseLong(value) * 1000; } catch (NumberFormatException ignore) { }//from w ww .j a v a 2 s . c o m } } return keepAlive * 1000; } }; }
From source file:Main.java
private static long stringToLong(String s) { if (s == null) return -1; try {/*from ww w .ja v a2s .c o m*/ return Long.parseLong(s); } catch (NumberFormatException e) { return -1; } }
From source file:Main.java
public static long[] fromString(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 {/*from w w w .j a va 2 s. c om*/ 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:Main.java
@NonNull public static long[] parseLongArray(final String string, final char token) { if (TextUtils.isEmpty(string)) return new long[0]; final String[] itemsStringArray = string.split(String.valueOf(token)); final long[] array = new long[itemsStringArray.length]; for (int i = 0, j = itemsStringArray.length; i < j; i++) { try {/*from w w w . ja v a 2 s . c om*/ array[i] = Long.parseLong(itemsStringArray[i]); } catch (final NumberFormatException e) { return new long[0]; } } return array; }
From source file:Utils.java
public static long getElementLongValue(Document document, Element parent, String string) { return Long.parseLong(getElementStringValue(document, parent, string)); }
From source file:Main.java
public static long toTime(String expr) { Pattern p = Pattern.compile("(-?)([0-9][0-9]):([0-9][0-9]):([0-9][0-9])([\\.:][0-9][0-9]?[0-9]?)?"); Matcher m = p.matcher(expr);/* ww w. j av a2 s .c om*/ if (m.matches()) { String minus = m.group(1); String hours = m.group(2); String minutes = m.group(3); String seconds = m.group(4); String fraction = m.group(5); if (fraction == null) { fraction = ".000"; } fraction = fraction.replace(":", "."); long ms = Long.parseLong(hours) * 60 * 60 * 1000; ms += Long.parseLong(minutes) * 60 * 1000; ms += Long.parseLong(seconds) * 1000; if (fraction.contains(":")) { ms += Double.parseDouble("0" + fraction.replace(":", ".")) * 40 * 1000; // 40ms == 25fps - simplifying assumption should be ok for here } else { ms += Double.parseDouble("0" + fraction) * 1000; } return ms * ("-".equals(minus) ? -1 : 1); } else { throw new RuntimeException("Cannot match '" + expr + "' to time expression"); } }
From source file:com.qubole.rubix.bookkeeper.utils.DiskUtils.java
public static long getActualSize(String path) throws IOException { File file = new File(path); String cmd = "ls -s " + path + " | cut -d ' ' -f 1"; ShellExec se = new ShellExec(cmd); log.debug("Running: " + cmd); ShellExec.CommandResult cr = se.runCmd(); long size = Long.parseLong(cr.getOut().trim()); return size * 1024; }
From source file:com.vmware.identity.openidconnect.protocol.ParameterMapUtils.java
public static long getLong(Map<String, String> parameters, String key) throws ParseException { Validate.notNull(parameters, "parameters"); Validate.notEmpty(key, "key"); String stringValue = ParameterMapUtils.getString(parameters, key); try {/* www .j a v a 2 s.com*/ return Long.parseLong(stringValue); } catch (NumberFormatException e) { throw new ParseException(String.format("invalid %s parameter", key), e); } }