Skip to content

Instantly share code, notes, and snippets.

@ankushs92
Created April 16, 2016 17:22
Show Gist options
  • Save ankushs92/5a2a8c46ddefc3f5ffa5c4199e22e90e to your computer and use it in GitHub Desktop.
Save ankushs92/5a2a8c46ddefc3f5ffa5c4199e22e90e to your computer and use it in GitHub Desktop.
Some Pre conditions/assertions that one would encounter in everyday programming
public class PreCondition {
public static <T> void checkNull(final T t, final String errorMsg){
if(t==null){
throw new IllegalArgumentException(errorMsg);
}
}
public static void checkEmptyString(final String str, final String errorMsg){
if(!Strings.hasText(str)){
throw new IllegalArgumentException(errorMsg);
}
}
public static <T> void checkEmptyCollection(final Collection<T> collection,final String errorMsg){
if(collection == null || collection.isEmpty()){
throw new IllegalArgumentException(errorMsg);
}
}
public static void checkExpression(final boolean expression ,final String errorMsg){
if(expression){
throw new IllegalArgumentException(errorMsg);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment