private static String badElementIndex(int index, int size, @Nullable String desc) { if (index < 0) { return lenientFormat("%s (%s) must not be negative", desc, index); } else if (size < 0) { throw new IllegalArgumentException("negative size: " + size); } else { // index >= size return lenientFormat("%s (%s) must be less than size (%s)", desc, index, size); } }
private static String badPositionIndex(int index, int size, @Nullable String desc) { if (index < 0) { return lenientFormat("%s (%s) must not be negative", desc, index); } else if (size < 0) { throw new IllegalArgumentException("negative size: " + size); } else { // index > size return lenientFormat("%s (%s) must not be greater than size (%s)", desc, index, size); } }
/** * Ensures the truth of an expression involving one or more parameters to the calling method. * * <p>See {@link #checkArgument(boolean, String, Object...)} for details. * * @since 20.0 (varargs overload since 2.0) */ public static void checkArgument(boolean b, @Nullable String errorMessageTemplate, int p1) { if (!b) { throw new IllegalArgumentException(lenientFormat(errorMessageTemplate, p1)); } }
/** * Ensures the truth of an expression involving one or more parameters to the calling method. * * <p>See {@link #checkArgument(boolean, String, Object...)} for details. * * @since 20.0 (varargs overload since 2.0) */ public static void checkArgument(boolean b, @Nullable String errorMessageTemplate, char p1) { if (!b) { throw new IllegalArgumentException(lenientFormat(errorMessageTemplate, p1)); } }
/** * Ensures the truth of an expression involving one or more parameters to the calling method. * * <p>See {@link #checkArgument(boolean, String, Object...)} for details. * * @since 20.0 (varargs overload since 2.0) */ public static void checkArgument(boolean b, @Nullable String errorMessageTemplate, long p1) { if (!b) { throw new IllegalArgumentException(lenientFormat(errorMessageTemplate, p1)); } }
/** * Ensures the truth of an expression involving one or more parameters to the calling method. * * <p>See {@link #checkArgument(boolean, String, Object...)} for details. * * @since 20.0 (varargs overload since 2.0) */ public static void checkArgument( boolean b, @Nullable String errorMessageTemplate, int p1, int p2) { if (!b) { throw new IllegalArgumentException(lenientFormat(errorMessageTemplate, p1, p2)); } }
/** * Ensures the truth of an expression involving one or more parameters to the calling method. * * <p>See {@link #checkArgument(boolean, String, Object...)} for details. * * @since 20.0 (varargs overload since 2.0) */ public static void checkArgument( boolean b, @Nullable String errorMessageTemplate, long p1, char p2) { if (!b) { throw new IllegalArgumentException(lenientFormat(errorMessageTemplate, p1, p2)); } }
/** * Ensures the truth of an expression involving one or more parameters to the calling method. * * <p>See {@link #checkArgument(boolean, String, Object...)} for details. * * @since 20.0 (varargs overload since 2.0) */ public static void checkArgument( boolean b, @Nullable String errorMessageTemplate, long p1, long p2) { if (!b) { throw new IllegalArgumentException(lenientFormat(errorMessageTemplate, p1, p2)); } }
/** * Ensures the truth of an expression involving the state of the calling instance, but not * involving any parameters to the calling method. * * <p>See {@link #checkState(boolean, String, Object...)} for details. * * @since 20.0 (varargs overload since 2.0) */ public static void checkState(boolean b, @Nullable String errorMessageTemplate, int p1) { if (!b) { throw new IllegalStateException(lenientFormat(errorMessageTemplate, p1)); } }
/** * Ensures the truth of an expression involving the state of the calling instance, but not * involving any parameters to the calling method. * * <p>See {@link #checkState(boolean, String, Object...)} for details. * * @since 20.0 (varargs overload since 2.0) */ public static void checkState(boolean b, @Nullable String errorMessageTemplate, long p1) { if (!b) { throw new IllegalStateException(lenientFormat(errorMessageTemplate, p1)); } }
/** * Ensures the truth of an expression involving the state of the calling instance, but not * involving any parameters to the calling method. * * <p>See {@link #checkState(boolean, String, Object...)} for details. * * @since 20.0 (varargs overload since 2.0) */ public static void checkState(boolean b, @Nullable String errorMessageTemplate, char p1, int p2) { if (!b) { throw new IllegalStateException(lenientFormat(errorMessageTemplate, p1, p2)); } }
/** * Ensures the truth of an expression involving one or more parameters to the calling method. * * <p>See {@link #checkArgument(boolean, String, Object...)} for details. * * @since 20.0 (varargs overload since 2.0) */ public static void checkArgument( boolean b, @Nullable String errorMessageTemplate, char p1, long p2) { if (!b) { throw new IllegalArgumentException(lenientFormat(errorMessageTemplate, p1, p2)); } }
/** * Ensures the truth of an expression involving one or more parameters to the calling method. * * <p>See {@link #checkArgument(boolean, String, Object...)} for details. * * @since 20.0 (varargs overload since 2.0) */ public static void checkArgument( boolean b, @Nullable String errorMessageTemplate, char p1, @Nullable Object p2) { if (!b) { throw new IllegalArgumentException(lenientFormat(errorMessageTemplate, p1, p2)); } }
/** * Ensures the truth of an expression involving one or more parameters to the calling method. * * <p>See {@link #checkArgument(boolean, String, Object...)} for details. * * @since 20.0 (varargs overload since 2.0) */ public static void checkArgument( boolean b, @Nullable String errorMessageTemplate, long p1, @Nullable Object p2) { if (!b) { throw new IllegalArgumentException(lenientFormat(errorMessageTemplate, p1, p2)); } }
/** * Ensures the truth of an expression involving one or more parameters to the calling method. * * <p>See {@link #checkArgument(boolean, String, Object...)} for details. * * @since 20.0 (varargs overload since 2.0) */ public static void checkArgument( boolean b, @Nullable String errorMessageTemplate, @Nullable Object p1, char p2) { if (!b) { throw new IllegalArgumentException(lenientFormat(errorMessageTemplate, p1, p2)); } }
/** * Ensures the truth of an expression involving one or more parameters to the calling method. * * <p>See {@link #checkArgument(boolean, String, Object...)} for details. * * @since 20.0 (varargs overload since 2.0) */ public static void checkArgument( boolean b, @Nullable String errorMessageTemplate, @Nullable Object p1, int p2) { if (!b) { throw new IllegalArgumentException(lenientFormat(errorMessageTemplate, p1, p2)); } }
private static String badPositionIndexes(int start, int end, int size) { if (start < 0 || start > size) { return badPositionIndex(start, size, "start index"); } if (end < 0 || end > size) { return badPositionIndex(end, size, "end index"); } // end < start return lenientFormat("end index (%s) must not be less than start index (%s)", end, start); } }
/** * Ensures that {@code expression} is {@code true}, throwing a {@code VerifyException} with a * custom message otherwise. * * <p>See {@link #verify(boolean, String, Object...)} for details. * * @since 23.1 (varargs overload since 17.0) */ public static void verify(boolean expression, @Nullable String errorMessageTemplate, int p1) { if (!expression) { throw new VerifyException(lenientFormat(errorMessageTemplate, p1)); } }
public void testLenientFormat_badArgumentToString_gwtFriendly() { assertThat(Strings.lenientFormat("boiler %s plate", new ThrowsOnToString())) .matches( "boiler <.*> plate"); }
@GwtIncompatible // GWT reflection includes less data public void testLenientFormat_badArgumentToString() { assertThat(Strings.lenientFormat("boiler %s plate", new ThrowsOnToString())) .matches( "boiler <com\\.google\\.common\\.base\\.StringsTest\\$ThrowsOnToString@[0-9a-f]+ " + "threw java\\.lang\\.UnsupportedOperationException> plate"); }