Package io.opentelemetry.api.internal
Class Utils
- java.lang.Object
-
- io.opentelemetry.api.internal.Utils
-
@Immutable public final class Utils extends Object
General internal utility methods.
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static void
checkArgument(boolean isValid, String errorMessage)
Throws anIllegalArgumentException
if the argument is false.static void
checkArgument(boolean expression, String errorMessageTemplate, Object... errorMessageArgs)
Throws anIllegalArgumentException
if the argument is false.static void
checkState(boolean isValid, String errorMessage)
Throws anIllegalStateException
if the argument is false.static void
validateLabelPairs(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, String errorMessage)
Throws anIllegalArgumentException
if 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, String errorMessageTemplate, Object... errorMessageArgs)
Throws anIllegalArgumentException
if 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%s
placeholder in the template with an argument. These are matched by position - the first%s
getserrorMessageArgs[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
- ifexpression
is falseNullPointerException
- if the check fails and eithererrorMessageTemplate
orerrorMessageArgs
is null (don't let this happen)
-
checkState
public static void checkState(boolean isValid, String errorMessage)
Throws anIllegalStateException
if 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(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:
IllegalArgumentException
- if any of the preconditions are violated.
-
-