Class LongUtils

java.lang.Object
org.apache.jackrabbit.oak.commons.LongUtils

public final class LongUtils extends Object
  • Method Details

    • safeAdd

      public static long safeAdd(long a, long b)
      Sums a and b and verifies that it doesn't overflow in signed long arithmetic, in which case Long.MAX_VALUE will be returned instead of the result. Note: this method is a variant of LongMath.checkedAdd(long, long) that returns Long.MAX_VALUE instead of throwing ArithmeticException.
      See Also:
      • LongMath.checkedAdd(long, long)
    • calculateExpirationTime

      public static long calculateExpirationTime(long expiration)
      Calculate an expiration time based on new Date().getTime() and the specified expiration in number of milliseconds.
      Parameters:
      expiration - The expiration in milliseconds.
      Returns:
      The expiration time.
    • tryParse

      public static Long tryParse(String string)
      Parses the specified string as a signed decimal long value. Unlike Long.parseLong(String), this method returns null instead 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)