Java Assert Not Null assertNotNullArgument(Object obj, String argName)

Here you can find the source of assertNotNullArgument(Object obj, String argName)

Description

assert Not Null Argument

License

Apache License

Declaration

public static void assertNotNullArgument(Object obj, String argName) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

public class Main {
    public static void assertNotNullArgument(Object obj, String argName) {
        if (obj == null) {
            throw new IllegalArgumentException(
                    "Null Object specified as argument. argumentName["
                            + argName + "]");
        }//from  ww  w  .  j a  v a  2 s.c  om
        if (obj instanceof String) {
            assertQualifiedString((String) obj, argName);
        }
    }

    public static void assertQualifiedString(String str, String argName) {
        if (!isQualifiedString(str)) {
            throw new IllegalArgumentException(
                    "Null or zero length string found. str[" + str
                            + "] argumentName[" + argName + "]");
        }
    }

    /**
     * This method will check for the null string
     * 
     * @param str to be check
     * @return true if string is not null
     */
    public static boolean isQualifiedString(String str) {
        return str != null && str.trim().length() > 0;
    }
}

Related

  1. assertNotNull(T o)
  2. assertNotNull(T obj)
  3. assertNotNull(T object, String fieldName)
  4. assertNotNull(T value, String message)
  5. assertNotNullArg(Object value, String argName)
  6. assertNotNullEightBytes(byte[] bytes)
  7. assertNotNullNotEmpty(String obj, String paramName)
  8. assertNotNullOrThrowException(final Object... objects)
  9. assertObjectNotNull(final Object object)