Java tutorial
//package com.java2s; //License from project: Open Source License import java.util.Collection; public class Main { /** * Validate given string argument isn't null or empty string. * * @param arg argument to validate * @param argName name of the argument to show in error message * @throws IllegalArgumentException */ public static void notNullOrEmpty(String arg, String argName) { if (arg == null || arg.length() < 1) { throw new IllegalArgumentException("argument is null: " + argName); } } /** * Validate given array argument isn't null or empty string. * * @param arg argument to validate * @param argName name of the argument to show in error message * @throws IllegalArgumentException */ public static <T> void notNullOrEmpty(T[] arg, String argName) { if (arg == null || arg.length < 1) { throw new IllegalArgumentException("argument is null: " + argName); } } /** * Validate given collection argument isn't null or empty string. * * @param arg argument to validate * @param argName name of the argument to show in error message * @throws IllegalArgumentException */ public static <T> void notNullOrEmpty(Collection<T> arg, String argName) { if (arg == null || arg.size() < 1) { throw new IllegalArgumentException("argument is null: " + argName); } } }