/** * Assert that the provided object is an instance of the provided class. * <pre class="code">Assert.instanceOf(Foo.class, foo, "Foo expected");</pre> * @param type the type to check against * @param obj the object to check * @param message a message which will be prepended to provide further context. * If it is empty or ends in ":" or ";" or "," or ".", a full exception message * will be appended. If it ends in a space, the name of the offending object's * type will be appended. In any other case, a ":" with a space and the name * of the offending object's type will be appended. * @throws IllegalArgumentException if the object is not an instance of type */ public static void isInstanceOf(Class<?> type, @Nullable Object obj, String message) { notNull(type, "Type to check against must not be null"); if (!type.isInstance(obj)) { instanceCheckFailed(type, obj, message); } }
/** * Assert that the provided object is an instance of the provided class. * <pre class="code"> * Assert.instanceOf(Foo.class, foo, () -> "Processing " + Foo.class.getSimpleName() + ":"); * </pre> * @param type the type to check against * @param obj the object to check * @param messageSupplier a supplier for the exception message to use if the * assertion fails. See {@link #isInstanceOf(Class, Object, String)} for details. * @throws IllegalArgumentException if the object is not an instance of type * @since 5.0 */ public static void isInstanceOf(Class<?> type, @Nullable Object obj, Supplier<String> messageSupplier) { notNull(type, "Type to check against must not be null"); if (!type.isInstance(obj)) { instanceCheckFailed(type, obj, nullSafeGet(messageSupplier)); } }
/** * Assert that the provided object is an instance of the provided class. * <pre class="code">Assert.instanceOf(Foo.class, foo, "Foo expected");</pre> * @param type the type to check against * @param obj the object to check * @param message a message which will be prepended to provide further context. * If it is empty or ends in ":" or ";" or "," or ".", a full exception message * will be appended. If it ends in a space, the name of the offending object's * type will be appended. In any other case, a ":" with a space and the name * of the offending object's type will be appended. * @throws IllegalArgumentException if the object is not an instance of type */ public static void isInstanceOf(Class<?> type, @Nullable Object obj, String message) { notNull(type, "Type to check against must not be null"); if (!type.isInstance(obj)) { instanceCheckFailed(type, obj, message); } }
/** * Assert that the provided object is an instance of the provided class. * <pre class="code"> * Assert.instanceOf(Foo.class, foo, () -> "Processing " + Foo.class.getSimpleName() + ":"); * </pre> * @param type the type to check against * @param obj the object to check * @param messageSupplier a supplier for the exception message to use if the * assertion fails. See {@link #isInstanceOf(Class, Object, String)} for details. * @throws IllegalArgumentException if the object is not an instance of type * @since 5.0 */ public static void isInstanceOf(Class<?> type, @Nullable Object obj, Supplier<String> messageSupplier) { notNull(type, "Type to check against must not be null"); if (!type.isInstance(obj)) { instanceCheckFailed(type, obj, nullSafeGet(messageSupplier)); } }
/** * Assert that the provided object is an instance of the provided class. * <pre class="code">Assert.instanceOf(Foo.class, foo, "Foo expected");</pre> * @param type the type to check against * @param obj the object to check * @param message a message which will be prepended to provide further context. * If it is empty or ends in ":" or ";" or "," or ".", a full exception message * will be appended. If it ends in a space, the name of the offending object's * type will be appended. In any other case, a ":" with a space and the name * of the offending object's type will be appended. * @throws IllegalArgumentException if the object is not an instance of type */ public static void isInstanceOf(Class<?> type, @Nullable Object obj, String message) { notNull(type, "Type to check against must not be null"); if (!type.isInstance(obj)) { instanceCheckFailed(type, obj, message); } }
/** * Assert that the provided object is an instance of the provided class. * <pre class="code"> * Assert.instanceOf(Foo.class, foo, () -> "Processing " + Foo.class.getSimpleName() + ":"); * </pre> * @param type the type to check against * @param obj the object to check * @param messageSupplier a supplier for the exception message to use if the * assertion fails. See {@link #isInstanceOf(Class, Object, String)} for details. * @throws IllegalArgumentException if the object is not an instance of type * @since 5.0 */ public static void isInstanceOf(Class<?> type, @Nullable Object obj, Supplier<String> messageSupplier) { notNull(type, "Type to check against must not be null"); if (!type.isInstance(obj)) { instanceCheckFailed(type, obj, nullSafeGet(messageSupplier)); } }
notNull(type, "Type to check against must not be null"); if (!type.isInstance(obj)) { instanceCheckFailed(type, obj, message); notNull(type, "Type to check against must not be null"); if (!type.isInstance(obj)) { instanceCheckFailed(type, obj, nullSafeGet(messageSupplier));