Class ArgumentCheck

java.lang.Object
org.faktorips.util.ArgumentCheck

public class ArgumentCheck extends Object
A class that provides static methods to check method arguments, e.g. check if an argument is not null or is an instance of a specific class.

All methods have an "optional" context parameter. If the check fails, the context's toString method is called and put into the IllegalArgumentException that is thrown. In this way you can provide some information in which context the check has failed and avoid to create a String object in the default case, when the check passes successfully.

  • Method Summary

    Modifier and Type
    Method
    Description
    static final void
    atLeast(Collection<?> c, int size)
    Checks if the given collection has at least the given size.
    static final void
    equals(Object arg1, Object arg2)
    Checks if the indicated arguments are equal.
    static final void
    equals(Object arg1, Object arg2, Object context)
    Checks if the indicated arguments are equal.
    static final void
    isInstanceOf(Object arg, Class<?> clazz)
    Checks if the indicated argument is an instance of the indicated class.
    static final void
    isInstanceOf(Object arg, Class<?> clazz, Object context)
    Checks if the indicated argument is an instance of the indicated class.
    static final void
    isSubclassOf(Class<?> subclass, Class<?> superclass)
    Checks if the given subclass is a subclass of the given superclass.
    static final void
    isTrue(boolean arg)
    Checks if the indicated argument is true.
    static final void
    isTrue(boolean arg, Object context)
    Checks if the indicated argument is true.
    static final void
    length(Object[] arg, int length)
    Checks if the indicated array has the indicated length.
    static final void
    length(Object[] a, int length, Object context)
    Checks if the indicated array has the indicated length.
    static final void
    nodeName(Node node, String name)
    Checks if the given xml node has the given name.
    static final void
    Checks if the indicated argument is not null.
    static final void
    notNull(Object[] arg)
    Checks if the provided array or one of the objects at the array's positions is null.
    static final void
    notNull(Object[] arg, Object context)
    Checks if the provided array or the objects at the array positions are null.
    static final void
    notNull(Object arg, Object context)
    Checks if the indicated argument is not null.

    Methods inherited from class java.lang.Object

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

    • notNull

      public static final void notNull(Object arg)
      Checks if the indicated argument is not null.
      Parameters:
      arg - the argument to check.
      Throws:
      NullPointerException - if arg is null.
    • notNull

      public static final void notNull(Object[] arg)
      Checks if the provided array or one of the objects at the array's positions is null. If so a NullPointerException is thrown.
      Parameters:
      arg - the argument to check.
    • notNull

      public static final void notNull(Object[] arg, Object context)
      Checks if the provided array or the objects at the array positions are null. If so a NullPointerException is thrown.
      Parameters:
      arg - the argument to check.
      context - information, in case the test fails, the context's toString()
    • notNull

      public static final void notNull(Object arg, Object context)
      Checks if the indicated argument is not null.
      Parameters:
      arg - the argument to check.
      context - context information, in case the test fails, the context's toString() method is called and the result passed to the NullPointerException.
      Throws:
      NullPointerException - if arg is null.
    • isTrue

      public static final void isTrue(boolean arg)
      Checks if the indicated argument is true.
      Parameters:
      arg - the argument to check.
      Throws:
      NullPointerException - if arg is null.
    • isTrue

      public static final void isTrue(boolean arg, Object context)
      Checks if the indicated argument is true.
      Parameters:
      arg - the argument to check.
      Throws:
      NullPointerException - if arg is null.
    • equals

      public static final void equals(Object arg1, Object arg2)
      Checks if the indicated arguments are equal.
      Throws:
      IllegalArgumentException - if arg1.equals(arg2) returns falls.
    • equals

      public static final void equals(Object arg1, Object arg2, Object context)
      Checks if the indicated arguments are equal.
      Throws:
      IllegalArgumentException - if arg1.equals(arg2) returns falls.
    • isInstanceOf

      public static final void isInstanceOf(Object arg, Class<?> clazz)
      Checks if the indicated argument is an instance of the indicated class.
      Parameters:
      arg - the argument to check.
      Throws:
      IllegalArgumentException - if arg is null.
    • isInstanceOf

      public static final void isInstanceOf(Object arg, Class<?> clazz, Object context)
      Checks if the indicated argument is an instance of the indicated class.
      Parameters:
      arg - the argument to check.
      Throws:
      IllegalArgumentException - if arg is null.
    • length

      public static final void length(Object[] arg, int length)
      Checks if the indicated array has the indicated length.
      Parameters:
      arg - the array to check.
      length - the expected array length
      Throws:
      IllegalArgumentException - if the array has not the given length.
    • atLeast

      public static final void atLeast(Collection<?> c, int size)
      Checks if the given collection has at least the given size.
      Parameters:
      c - the collection to check.
      size - the expected array length
      Throws:
      IllegalArgumentException - if the array has not the given length.
    • length

      public static final void length(Object[] a, int length, Object context)
      Checks if the indicated array has the indicated length.
      Parameters:
      a - the array to check.
      length - the expected array length
      context - an Object whose toString is used as the message for the IllegalArgumentException if it is thrown
      Throws:
      IllegalArgumentException - if the array has not the given length.
    • isSubclassOf

      public static final void isSubclassOf(Class<?> subclass, Class<?> superclass)
      Checks if the given subclass is a subclass of the given superclass.
      Throws:
      IllegalArgumentException - if subclass is not a subclass of superclass.
    • nodeName

      public static final void nodeName(Node node, String name)
      Checks if the given xml node has the given name.
      Throws:
      IllegalArgumentException - if the node has not the expected name.
      NullPointerException - if node is null.