Here you can find the source of assertStringNotEmpty(String string, String fieldName)
Parameter | Description |
---|---|
string | the string. |
fieldName | the field name. |
public static String assertStringNotEmpty(String string, String fieldName)
//package com.java2s; //License from project: Amazon Software License public class Main { /**/*from ww w. j a v a2 s. c o m*/ * Asserts that the string is not empty. * @param string the string. * @param fieldName the field name. * @return the string. */ public static String assertStringNotEmpty(String string, String fieldName) { assertNotNull(string, fieldName); if (string.isEmpty()) { throw new IllegalArgumentException(String.format("%s cannot be empty", fieldName)); } return string; } /** * Asserts that the given object is non-null and returns it. * * @param object Object to assert on * @param fieldName Field name to display in exception message if null * @param <T> the type of object. * @return Object if non null */ public static <T> T assertNotNull(T object, String fieldName) { if (object == null) { throw new IllegalArgumentException(String.format("%s cannot be null", fieldName)); } return object; } }