List of usage examples for java.lang Long parseLong
public static long parseLong(String s) throws NumberFormatException
From source file:Main.java
public static boolean isNumber(String string) { try {//from w w w . j av a2 s .c o m Long.parseLong(string); } catch (Exception e) { return false; } return true; }
From source file:Main.java
public static long getPid() { RuntimeMXBean mx = ManagementFactory.getRuntimeMXBean(); String[] mxNameTable = mx.getName().split("@"); //$NON-NLS-1$ if (mxNameTable.length == 2) { return Long.parseLong(mxNameTable[0]); } else {/* w w w . j ava 2s . c o m*/ return Thread.currentThread().getId(); } }
From source file:Main.java
public static String getDateFromName(String fName) { if (fName == null) return fName; String name = extractDateFromFName(fName); // output as time or date CharSequence df;// w w w . ja v a2 s. c o m long millis = Long.parseLong(name); if (DateUtils.isToday(millis)) { df = "'today' hh:mmaa"; } else { df = "dd MMM hh:mmaa"; } return (String) DateFormat.format(df, millis); }
From source file:Main.java
public static long contentLongGet(Element e, long defaultLong) { if (e == null) { return defaultLong; } else {/*from w w w . j a v a 2 s . c o m*/ String text = e.getTextContent(); return Long.parseLong(text); } }
From source file:Main.java
public static String formattedDate(String timestamp) { return _df.format(new Date(Long.parseLong(timestamp) * 1000L)); }
From source file:Main.java
public static Set<Long> getLongValues(String[] parameterValues, String message) { Set<Long> ids = null; if (parameterValues != null && parameterValues.length > 0) { ids = new HashSet<>(); for (String parameter : parameterValues) { try { Long id = Long.parseLong(parameter); if (id > 0) { ids.add(Long.parseLong(parameter)); }//from ww w. j a v a 2 s . c o m } catch (NumberFormatException e) { throw new IllegalArgumentException(message); } } } return ids; }
From source file:Main.java
/** * * @param document// w w w. j a v a 2 s. c o m * @param tagName * @return */ public static long getTagValueAsLong(Document document, String tagName) { long tagValue = -1; String tempVal = getTagValueAsString(document, tagName); tagValue = Long.parseLong(tempVal); return tagValue; }
From source file:Main.java
/** * Parse an long from the given string, falling back to the provided number in case of failure. * @param number String containing the long to be parsed. * @param fallback Number to return if parsing fails. * @return Either the parsed number or the fallback. *//*from w w w . java2s .com*/ public static long safeParseLong(String number, long fallback) { try { return Long.parseLong(number); } catch (NumberFormatException nfe) { return fallback; } }
From source file:Main.java
public static String timestempToString(String time) { return FORMAT.format(new Date(Long.parseLong(time) * 1000)); }
From source file:Main.java
public static String calculateSize(String value) { long bytes = Long.parseLong(value); int unit = 1024; if (bytes < unit) return bytes + " B"; int exp = (int) (Math.log(bytes) / Math.log(unit)); String pre = "KMGTPE".charAt(exp - 1) + "i"; return String.format("%.1f %sB", bytes / Math.pow(unit, exp), pre).replace(",", "."); }