001 /******************************************************************************* 002 * Portions created by Sebastian Thomschke are copyright (c) 2005-2011 Sebastian 003 * Thomschke. 004 * 005 * All Rights Reserved. This program and the accompanying materials 006 * are made available under the terms of the Eclipse Public License v1.0 007 * which accompanies this distribution, and is available at 008 * http://www.eclipse.org/legal/epl-v10.html 009 * 010 * Contributors: 011 * Sebastian Thomschke - initial implementation. 012 *******************************************************************************/ 013 package net.sf.oval.internal.util; 014 015 /** 016 * @author Sebastian Thomschke 017 */ 018 public final class Assert 019 { 020 private static RuntimeException _adjustStacktrace(final RuntimeException ex) 021 { 022 final StackTraceElement[] stack = ex.getStackTrace(); 023 final StackTraceElement[] newStack = new StackTraceElement[stack.length - 1]; 024 System.arraycopy(stack, 1, newStack, 0, stack.length - 1); 025 ex.setStackTrace(newStack); 026 return ex; 027 } 028 029 public static <T> void argumentNotEmpty(final String name, final String value) throws IllegalArgumentException 030 { 031 if (value == null) throw _adjustStacktrace(new IllegalArgumentException("[" + name + "] must not be null")); 032 if (value.length() == 0) 033 throw _adjustStacktrace(new IllegalArgumentException("[" + name + "] must not be empty")); 034 } 035 036 public static <T> void argumentNotEmpty(final String name, final T[] value) throws IllegalArgumentException 037 { 038 if (value == null) throw _adjustStacktrace(new IllegalArgumentException("[" + name + "] must not be null")); 039 if (value.length == 0) 040 throw _adjustStacktrace(new IllegalArgumentException("[" + name + "] must not be empty")); 041 } 042 043 public static void argumentNotNull(final String name, final Object value) throws IllegalArgumentException 044 { 045 if (value == null) throw _adjustStacktrace(new IllegalArgumentException("[" + name + "] must not be null")); 046 } 047 048 /** 049 * private constructor 050 */ 051 private Assert() 052 { 053 super(); 054 } 055 }