Package io.opentelemetry.api.internal
Class Utils
- java.lang.Object
-
- io.opentelemetry.api.internal.Utils
-
@Immutable public final class Utils extends java.lang.ObjectGeneral internal utility methods.
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static voidcheckArgument(boolean isValid, java.lang.String errorMessage)Throws anIllegalArgumentExceptionif the argument is false.static voidcheckArgument(boolean expression, java.lang.String errorMessageTemplate, java.lang.Object... errorMessageArgs)Throws anIllegalArgumentExceptionif the argument is false.static voidcheckState(boolean isValid, java.lang.String errorMessage)Throws anIllegalStateExceptionif the argument is false.static voidvalidateLabelPairs(java.lang.String[] keyValuePairs)Validates that the array of Strings is 1) even in length, and 2) they can be formed into valid pairs where the first item in the pair is not null.
-
-
-
Method Detail
-
checkArgument
public static void checkArgument(boolean isValid, java.lang.String errorMessage)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.
-
checkArgument
public static void checkArgument(boolean expression, java.lang.String errorMessageTemplate, java.lang.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:
java.lang.IllegalArgumentException- ifexpressionis falsejava.lang.NullPointerException- if the check fails and eithererrorMessageTemplateorerrorMessageArgsis null (don't let this happen)
-
checkState
public static void checkState(boolean isValid, java.lang.String errorMessage)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.
-
validateLabelPairs
public static void validateLabelPairs(java.lang.String[] keyValuePairs)
Validates that the array of Strings is 1) even in length, and 2) they can be formed into valid pairs where the first item in the pair is not null.TODO: write unit tests for this method.
- Parameters:
keyValuePairs- The String[] to validate for correctness.- Throws:
java.lang.IllegalArgumentException- if any of the preconditions are violated.
-
-