View Javadoc
1   /*******************************************************************************
2    * Portions created by Sebastian Thomschke are copyright (c) 2005-2011 Sebastian
3    * Thomschke.
4    * 
5    * All Rights Reserved. This program and the accompanying materials
6    * are made available under the terms of the Eclipse Public License v1.0
7    * which accompanies this distribution, and is available at
8    * http://www.eclipse.org/legal/epl-v10.html
9    * 
10   * Contributors:
11   *     Sebastian Thomschke - initial implementation.
12   *******************************************************************************/
13  package net.sf.oval.internal.util;
14  
15  /**
16   * @author Sebastian Thomschke
17   */
18  public final class Assert
19  {
20  	private static RuntimeException _adjustStacktrace(final RuntimeException ex)
21  	{
22  		final StackTraceElement[] stack = ex.getStackTrace();
23  		final StackTraceElement[] newStack = new StackTraceElement[stack.length - 1];
24  		System.arraycopy(stack, 1, newStack, 0, stack.length - 1);
25  		ex.setStackTrace(newStack);
26  		return ex;
27  	}
28  
29  	public static <T> void argumentNotEmpty(final String name, final String value) throws IllegalArgumentException
30  	{
31  		if (value == null) throw _adjustStacktrace(new IllegalArgumentException("[" + name + "] must not be null"));
32  		if (value.length() == 0)
33  			throw _adjustStacktrace(new IllegalArgumentException("[" + name + "] must not be empty"));
34  	}
35  
36  	public static <T> void argumentNotEmpty(final String name, final T[] value) throws IllegalArgumentException
37  	{
38  		if (value == null) throw _adjustStacktrace(new IllegalArgumentException("[" + name + "] must not be null"));
39  		if (value.length == 0)
40  			throw _adjustStacktrace(new IllegalArgumentException("[" + name + "] must not be empty"));
41  	}
42  
43  	public static void argumentNotNull(final String name, final Object value) throws IllegalArgumentException
44  	{
45  		if (value == null) throw _adjustStacktrace(new IllegalArgumentException("[" + name + "] must not be null"));
46  	}
47  
48  	/**
49  	 * private constructor
50  	 */
51  	private Assert()
52  	{
53  		super();
54  	}
55  }