Class Utils
java.lang.Object
io.opencensus.internal.Utils
General internal utility methods.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic voidcheckArgument(boolean isValid, Object errorMessage) Throws anIllegalArgumentExceptionif the argument is false.static voidcheckArgument(boolean expression, String errorMessageTemplate, Object... errorMessageArgs) Throws anIllegalArgumentExceptionif the argument is false.static voidcheckIndex(int index, int size) Validates an index in an array or other container.static <T> voidcheckListElementNotNull(List<T> list, Object errorMessage) Throws aNullPointerExceptionif any of the list elements is null.static <K,V> void checkMapElementNotNull(Map<K, V> map, Object errorMessage) Throws aNullPointerExceptionif any of the map elements is null.static <T> TcheckNotNull(T arg, Object errorMessage) Throws aNullPointerExceptionif the argument is null.static voidcheckState(boolean isValid, Object errorMessage) Throws anIllegalStateExceptionif the argument is false.static booleanequalsObjects(Object x, Object y) Compares two Objects for equality.private static StringSubstitutes each%sintemplatewith an argument.
-
Constructor Details
-
Utils
private Utils()
-
-
Method Details
-
checkArgument
Throws anIllegalArgumentExceptionif the argument is false. This method is similar toPreconditions.checkArgument(boolean, Object)from Guava.- Parameters:
isValid- whether the argument check passed.errorMessage- the message to use for the exception. Will be converted to a string usingString.valueOf(Object).
-
checkArgument
public static void checkArgument(boolean expression, String errorMessageTemplate, @Nullable Object... errorMessageArgs) Throws anIllegalArgumentExceptionif the argument is false. This method is similar toPreconditions.checkArgument(boolean, Object)from Guava.- Parameters:
expression- a boolean expressionerrorMessageTemplate- a template for the exception message should the check fail. The message is formed by replacing each%splaceholder in the template with an argument. These are matched by position - the first%sgetserrorMessageArgs[0], etc. Unmatched arguments will be appended to the formatted message in square braces. Unmatched placeholders will be left as-is.errorMessageArgs- the arguments to be substituted into the message template. Arguments are converted to strings usingString.valueOf(Object).- Throws:
IllegalArgumentException- ifexpressionis falseNullPointerException- if the check fails and eithererrorMessageTemplateorerrorMessageArgsis null (don't let this happen)
-
checkState
Throws anIllegalStateExceptionif the argument is false. This method is similar toPreconditions.checkState(boolean, Object)from Guava.- Parameters:
isValid- whether the state check passed.errorMessage- the message to use for the exception. Will be converted to a string usingString.valueOf(Object).
-
checkIndex
public static void checkIndex(int index, int size) Validates an index in an array or other container. This method throws anIllegalArgumentExceptionif the size is negative and throws anIndexOutOfBoundsExceptionif the index is negative or greater than or equal to the size. This method is similar toPreconditions.checkElementIndex(int, int)from Guava.- Parameters:
index- the index to validate.size- the size of the array or container.
-
checkNotNull
Throws aNullPointerExceptionif the argument is null. This method is similar toPreconditions.checkNotNull(Object, Object)from Guava.- Parameters:
arg- the argument to check for null.errorMessage- the message to use for the exception. Will be converted to a string usingString.valueOf(Object).- Returns:
- the argument, if it passes the null check.
-
checkListElementNotNull
Throws aNullPointerExceptionif any of the list elements is null.- Parameters:
list- the argument list to check for null.errorMessage- the message to use for the exception. Will be converted to a string usingString.valueOf(Object).
-
checkMapElementNotNull
Throws aNullPointerExceptionif any of the map elements is null.- Parameters:
map- the argument map to check for null.errorMessage- the message to use for the exception. Will be converted to a string usingString.valueOf(Object).
-
equalsObjects
-
format
Substitutes each%sintemplatewith an argument. These are matched by position: the first%sgetsargs[0], etc. If there are more arguments than placeholders, the unmatched arguments will be appended to the end of the formatted message in square braces.Copied from
Preconditions.format(String, Object...)from Guava- Parameters:
template- a non-null string containing 0 or more%splaceholders.args- the arguments to be substituted into the message template. Arguments are converted to strings usingString.valueOf(Object). Arguments can be null.
-