BLEEDING EDGE v1.3_061

This commit is contained in:
Paldiu 2021-03-01 23:21:49 -06:00
parent 5f37e63b0f
commit 5490213609
2 changed files with 8 additions and 2 deletions

View File

@ -9,6 +9,7 @@ import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Objects;
import java.util.Set;
public final class ReflectionTools {
@ -58,7 +59,7 @@ public final class ReflectionTools {
public Method getMethod(Class<?> clazz, String name, Class<?>... params) {
try {
return Wrapper.of(clazz.getMethod(name, params))
.filter(obj -> obj.setAccessible(true))
.perform(obj -> obj.setAccessible(true))
.get();
} catch (NoSuchMethodException e) {
return null;

View File

@ -6,6 +6,7 @@ import org.apache.commons.lang.builder.HashCodeBuilder;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.function.Predicate;
public final class Wrapper<T> {
protected T bean;
@ -61,7 +62,7 @@ public final class Wrapper<T> {
return new Wrapper<>(function.apply(get()));
}
public final Wrapper<T> filter(Consumer<? super T> consumer) {
public final Wrapper<T> perform(Consumer<? super T> consumer) {
consumer.accept(get());
return this;
}
@ -70,4 +71,8 @@ public final class Wrapper<T> {
supplier.get();
return this;
}
public final Wrapper<T> filter(Predicate<? super T> predicate) {
return predicate.test(get()) ? this : null;
}
}