Class Preconditions

java.lang.Object
org.jmxtrans.embedded.util.Preconditions

public class Preconditions
extends Object
Inspired by com.google.common.base.Preconditions
Author:
Cyrille Le Clerc
  • Method Details

    • checkNotNull

      public static <T> T checkNotNull​(T reference) throws NullPointerException
      Check the nullity of the given reference.
      Parameters:
      reference - reference to check
      Returns:
      the given reference
      Throws:
      NullPointerException - if the given reference is null
    • checkNotNull

      public static <T> T checkNotNull​(T reference, @Nullable String message) throws NullPointerException
      Check the nullity of the given reference.
      Parameters:
      reference - reference to check
      message - exception message, can be null
      Returns:
      the given reference
      Throws:
      NullPointerException - if the given reference is null
    • checkNotEmpty

      public static String checkNotEmpty​(String reference) throws IllegalArgumentException
      Check the nullity and emptiness of the given reference.
      Parameters:
      reference - reference to check
      Returns:
      the given reference
      Throws:
      IllegalArgumentException - if the given reference is null
    • checkNotEmpty

      public static String checkNotEmpty​(String reference, @Nullable String message) throws IllegalArgumentException
      Check the nullity and emptiness of the given reference.
      Parameters:
      reference - reference to check
      message - exception message, can be null
      Returns:
      the given reference
      Throws:
      IllegalArgumentException - if the given reference is null
    • checkState

      public static void checkState​(boolean state, @Nullable String message) throws IllegalStateException
      Check the given state.
      Parameters:
      state - the state top check
      message - exception message, can be null
      Throws:
      IllegalStateException - if the given state is false