Java Assert Not Null assertStringNotNullNorEmpty(String str, String name)

Here you can find the source of assertStringNotNullNorEmpty(String str, String name)

Description

Check if the given string is null or empty (trimmed).

License

Open Source License

Parameter

Parameter Description
str the given string to check
name the name to identify the string.

Exception

Parameter Description
IllegalArgumentException if the given string is null or empty (trimmed).

Declaration

static void assertStringNotNullNorEmpty(String str, String name) 

Method Source Code

//package com.java2s;

public class Main {
    /**/*  w w w.  j a  va 2s  .  co  m*/
     * Check if the given string is null or empty (trimmed).
     *
     * @param str the given string to check
     * @param name the name to identify the string.
     * @throws IllegalArgumentException if the given string is null or empty (trimmed).
     */
    static void assertStringNotNullNorEmpty(String str, String name) {
        assertObjectNotNull(str, name);

        if (str.trim().length() == 0) {
            throw new IllegalArgumentException(name
                    + " should not be empty (trimmed).");
        }
    }

    /**
     * Check if the given object is null.
     *
     * @param obj the given object to check
     * @param name the name to identify the object.
     * @throws IllegalArgumentException if the given object is null
     */
    static void assertObjectNotNull(Object obj, String name) {
        if (obj == null) {
            throw new IllegalArgumentException(name
                    + " should not be null.");
        }
    }
}

Related

  1. assertParamNotNull(Object check, String paramName)
  2. assertParamNotNull(String param, String paramName)
  3. assertPatternNotNull(String methodName, String pattern)
  4. assertResourceNotNull(String resourcePath, Object resourceHandle)
  5. assertStringNotNullAndNotTrimmedEmpty( String variableName, String value)
  6. assertStringNotNullOrEmpty(String str, String name)
  7. assertStringNotNullOrEmpty_ShorterThan256( String str, String name)