Class Checks

java.lang.Object
me.ahoo.cosid.internal.Checks

public final class Checks extends Object
Argument, state and null checks, and the small string helpers they need, without Guava. Messages use %s placeholders like Guava's Preconditions.

Internal to CosId: not part of the public API.

Since:
4.0.0
  • Method Summary

    Modifier and Type
    Method
    Description
    static void
    checkArgument(boolean expression)
    Checks an argument.
    static void
    checkArgument(boolean expression, @Nullable String template, long arg)
    Checks an argument without boxing or allocating when it holds: for hot paths.
    static void
    checkArgument(boolean expression, @Nullable String template, long arg1, long arg2)
    Checks an argument without boxing or allocating when it holds: for hot paths.
    static void
    checkArgument(boolean expression, @Nullable String template, @Nullable Object... args)
    Checks an argument.
    static void
    checkArgument(boolean expression, @Nullable String template, @Nullable Object arg1, @Nullable Object arg2)
    Checks an argument without allocating an array when it holds: for hot paths.
    static <T> T
    checkNotNull(T reference)
    Checks that a reference is not null.
    static <T> T
    checkNotNull(T reference, @Nullable String template, @Nullable Object... args)
    Checks that a reference is not null.
    static void
    checkState(boolean expression, @Nullable String template, @Nullable Object... args)
    Checks a state.
    A factory of daemon threads with the given name.
    static boolean
    isNullOrEmpty(@Nullable String string)
     
    static String
    lenientFormat(@Nullable String template, @Nullable Object... args)
    Replaces each %s in template with the next argument; arguments left over are appended in square brackets.
    static String
    padStart(String string, int minLength, char padChar)
    Left-pads string with padChar to minLength.
    static String
    toString(Object self, Object... namesAndValues)
    ClassName{name=value, ...}, the format of Guava's MoreObjects.toStringHelper.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • checkArgument

      public static void checkArgument(boolean expression, @Nullable String template, @Nullable Object... args)
      Checks an argument.
      Throws:
      IllegalArgumentException - with the formatted message if expression is false
    • checkArgument

      public static void checkArgument(boolean expression, @Nullable String template, long arg)
      Checks an argument without boxing or allocating when it holds: for hot paths.
      Throws:
      IllegalArgumentException - with the formatted message if expression is false
    • checkArgument

      public static void checkArgument(boolean expression, @Nullable String template, long arg1, long arg2)
      Checks an argument without boxing or allocating when it holds: for hot paths.
      Throws:
      IllegalArgumentException - with the formatted message if expression is false
    • checkArgument

      public static void checkArgument(boolean expression, @Nullable String template, @Nullable Object arg1, @Nullable Object arg2)
      Checks an argument without allocating an array when it holds: for hot paths.
      Throws:
      IllegalArgumentException - with the formatted message if expression is false
    • checkArgument

      public static void checkArgument(boolean expression)
      Checks an argument.
      Throws:
      IllegalArgumentException - if expression is false
    • checkState

      public static void checkState(boolean expression, @Nullable String template, @Nullable Object... args)
      Checks a state.
      Throws:
      IllegalStateException - with the formatted message if expression is false
    • checkNotNull

      public static <T> T checkNotNull(T reference, @Nullable String template, @Nullable Object... args)
      Checks that a reference is not null.
      Returns:
      reference
      Throws:
      NullPointerException - with the formatted message if reference is null
    • checkNotNull

      public static <T> T checkNotNull(T reference)
      Checks that a reference is not null.
      Returns:
      reference
      Throws:
      NullPointerException - if reference is null
    • isNullOrEmpty

      public static boolean isNullOrEmpty(@Nullable String string)
    • padStart

      public static String padStart(String string, int minLength, char padChar)
      Left-pads string with padChar to minLength.
    • lenientFormat

      public static String lenientFormat(@Nullable String template, @Nullable Object... args)
      Replaces each %s in template with the next argument; arguments left over are appended in square brackets. The same behavior as Guava's Strings.lenientFormat.
    • toString

      public static String toString(Object self, Object... namesAndValues)
      ClassName{name=value, ...}, the format of Guava's MoreObjects.toStringHelper.
    • daemonThreadFactory

      public static ThreadFactory daemonThreadFactory(String name)
      A factory of daemon threads with the given name. A %d in the name is replaced by a counter starting at 0.