Class SafeIdUtil

java.lang.Object
com.jagrosh.jdautilities.commons.utils.SafeIdUtil

public final class SafeIdUtil extends Object
A Utilities class for safely checking and converting String IDs to longs usable with MiscUtil.parseSnowflake(String), a utility used in several Object#getXById(String) methods.

This class contains two static methods:

Since:
1.2
Author:
Kaidan Gustave
  • Method Details

    • safeConvert

      public static long safeConvert(String id)
      Safely convert the provided String ID to a long usable with MiscUtil.parseSnowflake(String).
      Parameters:
      id - The String ID to be converted
      Returns:
      If the String can be converted into a non-negative long, then it will return the conversion.
      However, if one of the following criteria is met, then this method will return 0L:
    • checkId

      public static boolean checkId(String id)
      Checks if the provided String ID is usable with MiscUtil.parseSnowflake(String).
      Parameters:
      id - The String ID to be converted
      Returns:
      true if both of the following criteria are not met: