
com.github.dakusui.valid8j_pcond.internals.InternalChecks Maven / Gradle / Ivy
The newest version!
package com.github.dakusui.valid8j_pcond.internals;
import com.github.dakusui.valid8j_pcond.core.refl.ReflUtils;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.function.Function;
import java.util.function.Predicate;
import java.util.function.Supplier;
import static java.lang.String.format;
import static java.util.Collections.emptySet;
import static java.util.Collections.unmodifiableList;
import static java.util.stream.Collectors.toList;
public enum InternalChecks {
;
private static final Set> PRIMITIVE_WRAPPERS = new HashSet>() {{
add(Integer.class);
add(Long.class);
add(Boolean.class);
add(Byte.class);
add(Character.class);
add(Float.class);
add(Double.class);
add(Short.class);
add(Void.class);
}};
public static void checkArgument(boolean b, Supplier messageFormatter) {
if (!b)
throw new IllegalArgumentException(messageFormatter.get());
}
public static V requireArgument(V arg, Predicate super V> predicate, Supplier messageFormatter) {
if (!predicate.test(arg))
throw new IllegalArgumentException(messageFormatter.get());
return arg;
}
public static V ensureValue(V value, Predicate super V> predicate, Function messageFormatter) {
if (!predicate.test(value))
throw new IllegalStateException(messageFormatter.apply(value));
return value;
}
public static V requireState(V arg, Predicate super V> predicate, Function messageFormatter) {
if (!predicate.test(arg))
throw new IllegalStateException(messageFormatter.apply(arg));
return arg;
}
public static Method requireStaticMethod(Method method) {
if (!Modifier.isStatic(method.getModifiers()))
throw new IllegalArgumentException(String.format("The specified method '%s' is not static", method));
return method;
}
public static List
© 2015 - 2025 Weber Informatics LLC | Privacy Policy