Skip to content
Snippets Groups Projects
Commit 1c28a1aa authored by Benedict Wong's avatar Benedict Wong Committed by android-build-merger
Browse files

Merge "Add message template support for checkStringNotEmpty"

am: 0d0bfc92

Change-Id: I7012673fdf97ddaa5bad49387b3d974ac72daa02
parents a9cc5cf8 0d0bfc92
No related branches found
No related tags found
No related merge requests found
......@@ -101,6 +101,24 @@ public class Preconditions {
return string;
}
/**
* Ensures that an string reference passed as a parameter to the calling method is not empty.
*
* @param string an string reference
* @param messageTemplate a printf-style message template to use if the check fails; will be
* converted to a string using {@link String#format(String, Object...)}
* @param messageArgs arguments for {@code messageTemplate}
* @return the string reference that was validated
* @throws IllegalArgumentException if {@code string} is empty
*/
public static @NonNull <T extends CharSequence> T checkStringNotEmpty(
final T string, final String messageTemplate, final Object... messageArgs) {
if (TextUtils.isEmpty(string)) {
throw new IllegalArgumentException(String.format(messageTemplate, messageArgs));
}
return string;
}
/**
* Ensures that an object reference passed as a parameter to the calling
* method is not null.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment