-
-
Save walmyrcarvalho/cbdd666d2b0281b7ee69 to your computer and use it in GitHub Desktop.
Small Preconditions helper class for your Offensive 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
import android.support.annotation.Nullable; | |
// Based on http://google-collections.googlecode.com/svn-history/r78/trunk/javadoc/com/google/common/base/Preconditions.html | |
public class Preconditions { | |
public static void checkArgument(boolean expression, @Nullable Object errorMessage) { | |
if (!expression) { | |
throw new IllegalArgumentException(String.valueOf(errorMessage)); | |
} | |
} | |
public static void checkState(boolean expression, @Nullable Object errorMessage) { | |
if (!expression) { | |
throw new IllegalStateException(String.valueOf(errorMessage)); | |
} | |
} | |
public static <T> T checkNotNull(T reference, @Nullable Object errorMessage) { | |
if (reference == null) { | |
throw new NullPointerException(String.valueOf(errorMessage)); | |
} | |
return reference; | |
} | |
public static <T> T checkNull(T reference, @Nullable Object errorMessage) { | |
checkState(reference == null, errorMessage); | |
return reference; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment