/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.apache.wicket.util.lang;

import org.apache.wicket.util.string.Strings;

/**
 * 
 */
public class Args
{
	/**
	 * Checks argument is not null
	 * 
	 * @param <T>
	 * @param argument
	 * @param name
	 * @return The 'argument' parameter
	 * @throws IllegalArgumentException
	 */
	public static <T> T notNull(final T argument, final String name)
	{
		if (argument == null)
		{
			throw new IllegalArgumentException("Argument '" + name + "' may not be null.");
		}
		return argument;
	}

	/**
	 * Checks argument is not empty (not null and has a non-whitespace character)
	 * 
	 * @param argument
	 * @param name
	 * @return The 'argument' parameter
	 * @throws IllegalArgumentException
	 */
	public static CharSequence notEmpty(final CharSequence argument, final String name)
	{
		if (Strings.isEmpty(argument))
		{
			throw new IllegalArgumentException("Argument '" + name +
				"' may not be null or empty string.");
		}
		return argument;
	}

	/**
	 * Checks if argument is within a range
	 * 
	 * @param <T>
	 * @param min
	 * @param max
	 * @param value
	 * @param name
	 * @throws IllegalArgumentException
	 */
	public static <T extends Comparable<T>> void withinRange(final T min, final T max,
		final T value, final String name)
	{
		notNull(min, name);
		notNull(max, name);
		if ((value.compareTo(min) < 0) || (value.compareTo(max) > 0))
		{
			throw new IllegalArgumentException(
				String.format("Argument '%s' must have a value within [%s,%s], but was %s", name,
					min, max, value));
		}
	}

	/**
	 * Check if argument is true
	 * 
	 * @param argument
	 * @param msg
	 * @param params
	 * @return argument
	 */
	public static boolean isTrue(final boolean argument, final String msg, final Object... params)
	{
		if (argument == false)
		{
			throw new IllegalArgumentException(format(msg, params));
		}
		return argument;
	}

	/**
	 * Check if argument is false
	 * 
	 * @param argument
	 * @param msg
	 * @param params
	 * @return argument
	 */
	public static boolean isFalse(final boolean argument, final String msg, final Object... params)
	{
		if (argument == true)
		{
			throw new IllegalArgumentException(format(msg, params));
		}
		return argument;
	}

	/**
	 * Format the message. Allow for "{}" as well as %s etc. (see Formatter).
	 * 
	 * @param msg
	 * @param params
	 * @return formatted message
	 */
	static String format(String msg, final Object... params)
	{
		msg = msg.replaceAll("\\{\\}", "%s");
		return String.format(msg, params);
	}
}

@@ -1392,39 +1392,225 @@
  @param 
-argument%0A%09 * @param nam
+%3CT%3E%0A%09 *            the type of the argument to check for emptiness%0A%09 * %0A%09 * @param argument%0A%09 *            the argument to check for emptiness%0A%09 * @param name%0A%09 *            the name to use in the error messag
 e%0A%09 * @r
@@ -1615,33 +1615,39 @@
 @return The 
-'
+%7B@code 
 argument
 ' parameter%0A
@@ -1626,33 +1626,33 @@
  %7B@code argument
-'
+%7D
  parameter%0A%09 * @
@@ -1637,32 +1637,45 @@
 ument%7D parameter
+ if not empty
 %0A%09 * @throws Ill
@@ -1688,32 +1688,90 @@
 gumentException%0A
+%09 *             when the passed %7B@code argument%7D is empty%0A
 %09 */%0A%09public sta
@@ -1774,16 +1774,27 @@
  static 
+%3CT extends 
 CharSequ
@@ -1797,16 +1797,19 @@
 Sequence
+%3E T
  notEmpt
@@ -1816,28 +1816,17 @@
 y(final 
-CharSequence
+T
  argumen
@@ -1946,21 +1946,17 @@
 + name +
-%0A%09%09%09%09
+ 
 %22' may n
@@ -1978,15 +1978,8 @@
 mpty
- string
 .%22);

Make Args.notEmpty() smarter. Improve its javadocs.