Class CommonUtils

java.lang.Object
cn.longky.common.utils.CommonUtils

public class CommonUtils extends Object
Since:
1.0
Author:
yingzhan
  • Constructor Details

    • CommonUtils

      public CommonUtils()
  • Method Details

    • safeCast

      public static <T> T safeCast(Object o, Class<T> clazz)
    • firstNonnull

      @SafeVarargs public static <T> T firstNonnull(T... args)
    • firstNonnull

      @SafeVarargs public static <T> T firstNonnull(T defaultValue, Supplier<T>... suppliers)
    • firstMatch

      @SafeVarargs public static <T> T firstMatch(Function<T,Boolean> matcher, T... args)
    • firstMatchWithSuppliers

      @SafeVarargs public static <T> T firstMatchWithSuppliers(Function<T,Boolean> matcher, Supplier<T>... suppliers)
    • swallowException

      public static <T> T swallowException(KSupplier<T> supplier)
    • swallowException

      public static void swallowException(KRunnable runnable)
    • getUuid

      public static String getUuid()
    • getUuid

      public static String getUuid(String replacement)
    • contains

      @SafeVarargs public static <T> boolean contains(T item, T... array)
    • encryptPassword

      public static String encryptPassword(String password, String salt)
    • validatePassword

      public static boolean validatePassword(String rawPassword, String encryptedPassword, String salt)
    • generateRandomString

      public static String generateRandomString(int length, boolean isNumeric, boolean ignoreCase)
    • generateUniqueCodeByUid

      public static String generateUniqueCodeByUid(long userId, int length, boolean isNumeric, int primeOfCharLength, long salt)
    • generateUniqueCodeByUid

      public static String generateUniqueCodeByUid(long userId, int length, boolean isNumeric)
    • stringifySize

      public static String stringifySize(long size)
    • retry

      public static <T> T retry(KSupplier<T> supplier, int maxRetries) throws Throwable
      Throws:
      Throwable
    • retry

      public static <T> T retry(KSupplier<T> supplier, int maxRetries, Duration sleepTime, Class<? extends Throwable> throwableClass, Predicate<T> verifier) throws Throwable
      Throws:
      Throwable
    • retry

      public static <T> T retry(KSupplier<T> supplier, int maxRetries, Duration sleepTime, Class<? extends Throwable> throwableClass, Predicate<T> verifier, T defaultValue) throws Throwable
      Throws:
      Throwable
    • parseLong

      public static Long parseLong(Object o)
    • parseInt

      public static Integer parseInt(Object o)
    • parseBoolean

      public static Boolean parseBoolean(Object o)