Created
April 16, 2016 17:22
-
-
Save ankushs92/5a2a8c46ddefc3f5ffa5c4199e22e90e to your computer and use it in GitHub Desktop.
Some Pre conditions/assertions that one would encounter in everyday programming
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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