From 5490213609ab8f88e0d4bb819c342efc1ba9da43 Mon Sep 17 00:00:00 2001 From: Paldiu Date: Mon, 1 Mar 2021 23:21:49 -0600 Subject: [PATCH] BLEEDING EDGE v1.3_061 --- .../simplexdev/simplexcore/utils/ReflectionTools.java | 3 ++- .../io/github/simplexdev/simplexcore/utils/Wrapper.java | 7 ++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/main/java/io/github/simplexdev/simplexcore/utils/ReflectionTools.java b/src/main/java/io/github/simplexdev/simplexcore/utils/ReflectionTools.java index 795f1eb..146520f 100644 --- a/src/main/java/io/github/simplexdev/simplexcore/utils/ReflectionTools.java +++ b/src/main/java/io/github/simplexdev/simplexcore/utils/ReflectionTools.java @@ -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; diff --git a/src/main/java/io/github/simplexdev/simplexcore/utils/Wrapper.java b/src/main/java/io/github/simplexdev/simplexcore/utils/Wrapper.java index 5e10baa..7ab9ff7 100644 --- a/src/main/java/io/github/simplexdev/simplexcore/utils/Wrapper.java +++ b/src/main/java/io/github/simplexdev/simplexcore/utils/Wrapper.java @@ -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 { protected T bean; @@ -61,7 +62,7 @@ public final class Wrapper { return new Wrapper<>(function.apply(get())); } - public final Wrapper filter(Consumer consumer) { + public final Wrapper perform(Consumer consumer) { consumer.accept(get()); return this; } @@ -70,4 +71,8 @@ public final class Wrapper { supplier.get(); return this; } + + public final Wrapper filter(Predicate predicate) { + return predicate.test(get()) ? this : null; + } }