Class LongUtils
- java.lang.Object
-
- org.apache.jackrabbit.oak.commons.LongUtils
-
public final class LongUtils extends java.lang.Object
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static longcalculateExpirationTime(long expiration)Calculate an expiration time based onnew Date().getTime()and the specifiedexpirationin number of milliseconds.static longsafeAdd(long a, long b)Sumsaandband verifies that it doesn't overflow in signed long arithmetic, in which caseLong.MAX_VALUEwill be returned instead of the result.static java.lang.LongtryParse(java.lang.String string)Parses the specified string as a signed decimal long value.
-
-
-
Method Detail
-
safeAdd
public static long safeAdd(long a, long b)Sumsaandband verifies that it doesn't overflow in signed long arithmetic, in which caseLong.MAX_VALUEwill be returned instead of the result. Note: this method is a variant ofLongMath.checkedAdd(long, long)that returnsLong.MAX_VALUEinstead of throwingArithmeticException.- See Also:
LongMath.checkedAdd(long, long)
-
calculateExpirationTime
public static long calculateExpirationTime(long expiration)
Calculate an expiration time based onnew Date().getTime()and the specifiedexpirationin number of milliseconds.- Parameters:
expiration- The expiration in milliseconds.- Returns:
- The expiration time.
-
tryParse
public static java.lang.Long tryParse(java.lang.String string)
Parses the specified string as a signed decimal long value. UnlikeLong.parseLong(String), this method returnsnullinstead of throwing an exception if parsing fails. This can be significantly more efficient when the string to be parsed is often invalid, as raising an exception is an expensive operation.This is a simplified version of Longs.tryParse() in Guava. This version is hardcoded to only support radix 10.
- See Also:
Longs.tryParse(String)
-
-