Class NullCheck

java.lang.Object
org.luwrain.core.NullCheck

public final class NullCheck extends Object
Simplifies checking of objects validity. This class provides a set of static methods which take care of checking the given data and throw corresponding exceptions. All method are rather short and purposed only for making code more readable and self-documented.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static void
    notEmpty(Object obj, String name)
    Checks that given reference isn't null and obj.toString.isEmpty() returns false.
    static void
    notEmptyArray(Object[] items, String name)
    Checks that the array reference isn't null and the array has at least one item.
    static void
    notEmptyItems(Object[] items, String name)
    Checks that the array reference isn't null and items[i].toString().isEmpt () returns false for all items (if there are any).
    static void
    notNull(Object obj, String name)
    Checks that provided reference isn't null.
    static void
    notNullItems(Object[] items, String name)
    Checks that the array reference isn't null and none of its items are null (if there are any).

    Methods inherited from class java.lang.Object

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

    • NullCheck

      public NullCheck()
  • Method Details

    • notNull

      public static void notNull(Object obj, String name)
      Checks that provided reference isn't null.
      Parameters:
      obj - The reference to check
      name - The reference name to construct better exception message
      Throws:
      NullPointerException
    • notEmpty

      public static void notEmpty(Object obj, String name)
      Checks that given reference isn't null and obj.toString.isEmpty() returns false.
      Parameters:
      obj - The reference to check
      name - The reference name to construct better exception message
      Throws:
      NullPointerException - IllegalArgumentException
    • notNullItems

      public static void notNullItems(Object[] items, String name)
      Checks that the array reference isn't null and none of its items are null (if there are any).
      Parameters:
      items - The reference to an array to check
      name - The reference name to construct better exception message
      Throws:
      NullPointerException
    • notEmptyItems

      public static void notEmptyItems(Object[] items, String name)
      Checks that the array reference isn't null and items[i].toString().isEmpt () returns false for all items (if there are any).
      Parameters:
      items - The reference to an array to check
      name - The reference name to construct better exception message
      Throws:
      NullPointerException - IllegalArgumentException
    • notEmptyArray

      public static void notEmptyArray(Object[] items, String name)
      Checks that the array reference isn't null and the array has at least one item.
      Parameters:
      items - The reference to an array to check
      name - The reference name to construct better exception message
      Throws:
      NullPointerException - IllegalArgumentException