diff --git a/lib/src/main/java/net/tomatentum/cutin/MethodExecutor.java b/lib/src/main/java/net/tomatentum/cutin/MethodExecutor.java index 81bcd5e..3b16087 100644 --- a/lib/src/main/java/net/tomatentum/cutin/MethodExecutor.java +++ b/lib/src/main/java/net/tomatentum/cutin/MethodExecutor.java @@ -1,7 +1,7 @@ package net.tomatentum.cutin; -public interface MethodExecutor { +public interface MethodExecutor { - void handle(Object context); + void handle(C context); } diff --git a/lib/src/main/java/net/tomatentum/cutin/MethodProcessor.java b/lib/src/main/java/net/tomatentum/cutin/MethodProcessor.java index 01853b4..04bb4fb 100644 --- a/lib/src/main/java/net/tomatentum/cutin/MethodProcessor.java +++ b/lib/src/main/java/net/tomatentum/cutin/MethodProcessor.java @@ -2,8 +2,8 @@ package net.tomatentum.cutin; import net.tomatentum.cutin.container.MethodContainer; -public interface MethodProcessor { +public interface MethodProcessor { - void process(Object context, MethodContainer methodContainer); + void process(Object context, MethodContainer methodContainer); } diff --git a/lib/src/main/java/net/tomatentum/cutin/ProcessorContainer.java b/lib/src/main/java/net/tomatentum/cutin/ProcessorContainer.java index 0015a78..1855994 100644 --- a/lib/src/main/java/net/tomatentum/cutin/ProcessorContainer.java +++ b/lib/src/main/java/net/tomatentum/cutin/ProcessorContainer.java @@ -2,10 +2,10 @@ package net.tomatentum.cutin; import java.util.Collection; -public interface ProcessorContainer { +public interface ProcessorContainer { - ProcessorContainer addProcessor(MethodProcessor processor); + ProcessorContainer addProcessor(MethodProcessor processor); - Collection> processor(); + Collection> processor(); } diff --git a/lib/src/main/java/net/tomatentum/cutin/ProcessorMethodExecutor.java b/lib/src/main/java/net/tomatentum/cutin/ProcessorMethodExecutor.java index 23041a3..3f1a043 100644 --- a/lib/src/main/java/net/tomatentum/cutin/ProcessorMethodExecutor.java +++ b/lib/src/main/java/net/tomatentum/cutin/ProcessorMethodExecutor.java @@ -9,26 +9,26 @@ import org.slf4j.LoggerFactory; import net.tomatentum.cutin.container.MethodContainer; -public class ProcessorMethodExecutor implements MethodExecutor, ProcessorContainer { +public class ProcessorMethodExecutor implements MethodExecutor, ProcessorContainer { private Logger logger = LoggerFactory.getLogger(getClass()); - private MethodContainer methodContainer; - private Set> processors; + private MethodContainer methodContainer; + private Set> processors; - public ProcessorMethodExecutor(MethodContainer methodContainer) { + public ProcessorMethodExecutor(MethodContainer methodContainer) { this.methodContainer = methodContainer; this.processors = new HashSet<>(); } @Override - public ProcessorContainer addProcessor(MethodProcessor processor) { + public ProcessorContainer addProcessor(MethodProcessor processor) { processors.add(processor); return this; } @Override - public Collection> processor() { + public Collection> processor() { return this.processors; } diff --git a/lib/src/main/java/net/tomatentum/cutin/ReflectedMethodFactory.java b/lib/src/main/java/net/tomatentum/cutin/ReflectedMethodFactory.java index 1c1338b..28ca15a 100644 --- a/lib/src/main/java/net/tomatentum/cutin/ReflectedMethodFactory.java +++ b/lib/src/main/java/net/tomatentum/cutin/ReflectedMethodFactory.java @@ -7,14 +7,14 @@ import java.util.Optional; import net.tomatentum.cutin.method.ReflectedMethod; -public interface ReflectedMethodFactory { - Optional> produce(Method method, Object containingClass); - ReflectedMethodFactory addFactory(Factory factory); +public interface ReflectedMethodFactory { + Optional> produce(Method method, Object containingClass); + ReflectedMethodFactory addFactory(Factory factory); - public interface Factory { + public interface Factory { - Optional> produce(Method method, Object containingObject); - void addParser(ReflectedMethod method, List parser); + Optional> produce(Method method, Object containingObject); + void addParser(ReflectedMethod method, List parser); } } \ No newline at end of file diff --git a/lib/src/main/java/net/tomatentum/cutin/ReflectedMethodFactoryImpl.java b/lib/src/main/java/net/tomatentum/cutin/ReflectedMethodFactoryImpl.java index 431e8f5..94e20d3 100644 --- a/lib/src/main/java/net/tomatentum/cutin/ReflectedMethodFactoryImpl.java +++ b/lib/src/main/java/net/tomatentum/cutin/ReflectedMethodFactoryImpl.java @@ -12,23 +12,23 @@ import net.tomatentum.cutin.method.ReflectedMethod; import net.tomatentum.cutin.util.ReflectionUtil; -public class ReflectedMethodFactoryImpl implements ReflectedMethodFactory { +public class ReflectedMethodFactoryImpl implements ReflectedMethodFactory { private Logger logger = LoggerFactory.getLogger(getClass()); - private List> factories; + private List> factories; public ReflectedMethodFactoryImpl() { this(new ArrayList<>()); } - public ReflectedMethodFactoryImpl(List> factories) { + public ReflectedMethodFactoryImpl(List> factories) { this.factories = factories; } @Override - public Optional> produce(Method method, Object containingClass) { - Optional> rmethod = this.factories.stream() + public Optional> produce(Method method, Object containingClass) { + Optional> rmethod = this.factories.stream() .map(f -> factoryProduce(f, method, containingClass)) .filter(Optional::isPresent) .map(Optional::get) @@ -42,14 +42,14 @@ public class ReflectedMethodFactoryImpl implements ReflectedMe } @Override - public ReflectedMethodFactory addFactory(Factory factory) { + public ReflectedMethodFactory addFactory(Factory factory) { this.factories.add(factory); return this; } - private Optional> factoryProduce(Factory factory, Method method, Object containingClass) { + private Optional> factoryProduce(Factory factory, Method method, Object containingClass) { List parser = new ArrayList<>(); - Optional> m = factory.produce(method, containingClass); + Optional> m = factory.produce(method, containingClass); m.ifPresent(x -> { factory.addParser(x, parser); parser.forEach(MethodParser::parse); diff --git a/lib/src/main/java/net/tomatentum/cutin/container/LoneMethodContainer.java b/lib/src/main/java/net/tomatentum/cutin/container/LoneMethodContainer.java index a06f10b..071759f 100644 --- a/lib/src/main/java/net/tomatentum/cutin/container/LoneMethodContainer.java +++ b/lib/src/main/java/net/tomatentum/cutin/container/LoneMethodContainer.java @@ -11,24 +11,24 @@ import java.util.Set; import net.tomatentum.cutin.ReflectedMethodFactory; import net.tomatentum.cutin.method.ReflectedMethod; -public class LoneMethodContainer implements MethodContainer { +public class LoneMethodContainer implements MethodContainer { - private Map> methodStore; - private ReflectedMethodFactory factory; + private Map> methodStore; + private ReflectedMethodFactory factory; - public LoneMethodContainer(ReflectedMethodFactory factory) { + public LoneMethodContainer(ReflectedMethodFactory factory) { this.methodStore = new HashMap<>(); this.factory = factory; } @Override - public MethodContainer addMethod(ReflectedMethod method) { + public MethodContainer addMethod(ReflectedMethod method) { this.methodStore.put(method.identifier(), method); return this; } @Override - public MethodContainer addMethods(Object containingObject, Method... methods) { + public MethodContainer addMethods(Object containingObject, Method... methods) { for (Method method : methods) this.factory.produce(method, containingObject) .ifPresent(this::addMethod); @@ -41,17 +41,17 @@ public class LoneMethodContainer implements MethodContainer } @Override - public Collection> methods() { + public Collection> methods() { return this.methodStore.values(); } @Override - public Collection> findFor(I identifier) { + public Collection> findFor(I identifier) { return Arrays.asList(this.methodStore.get(identifier)); } @Override - public Optional> findFirstFor(I identifier) { + public Optional> findFirstFor(I identifier) { return findFor(identifier).stream().findFirst(); } diff --git a/lib/src/main/java/net/tomatentum/cutin/container/MethodContainer.java b/lib/src/main/java/net/tomatentum/cutin/container/MethodContainer.java index efbde45..d5097d8 100644 --- a/lib/src/main/java/net/tomatentum/cutin/container/MethodContainer.java +++ b/lib/src/main/java/net/tomatentum/cutin/container/MethodContainer.java @@ -7,24 +7,24 @@ import java.util.Set; import net.tomatentum.cutin.method.ReflectedMethod; -public interface MethodContainer { +public interface MethodContainer { - MethodContainer addMethod(ReflectedMethod method); - default MethodContainer addMethods(ReflectedMethod[] methods) { - for (ReflectedMethod reflectedMethod : methods) { + MethodContainer addMethod(ReflectedMethod method); + default MethodContainer addMethods(ReflectedMethod[] methods) { + for (ReflectedMethod reflectedMethod : methods) { this.addMethod(reflectedMethod); } return this; } - MethodContainer addMethods(Object containingObject, Method... methods); - default MethodContainer addAllMethods(Object containingObject) { + MethodContainer addMethods(Object containingObject, Method... methods); + default MethodContainer addAllMethods(Object containingObject) { this.addMethods(containingObject, containingObject.getClass().getDeclaredMethods()); return this; } Set identifiers(); - Collection> methods(); - Collection> findFor(I identifier); - Optional> findFirstFor(I identifier); + Collection> methods(); + Collection> findFor(I identifier); + Optional> findFirstFor(I identifier); } diff --git a/lib/src/main/java/net/tomatentum/cutin/container/MultiMethodContainer.java b/lib/src/main/java/net/tomatentum/cutin/container/MultiMethodContainer.java index 327d8e5..86b18ae 100644 --- a/lib/src/main/java/net/tomatentum/cutin/container/MultiMethodContainer.java +++ b/lib/src/main/java/net/tomatentum/cutin/container/MultiMethodContainer.java @@ -14,28 +14,28 @@ import net.tomatentum.cutin.ReflectedMethodFactory; import net.tomatentum.cutin.method.ReflectedMethod; import net.tomatentum.cutin.util.ReflectionUtil; -public class MultiMethodContainer implements MethodContainer { +public class MultiMethodContainer implements MethodContainer { - private Set> entries; - private ReflectedMethodFactory factory; + private Set> entries; + private ReflectedMethodFactory factory; - public MultiMethodContainer(ReflectedMethodFactory factory) { + public MultiMethodContainer(ReflectedMethodFactory factory) { this.entries = new HashSet<>(); this.factory = factory; } @Override - public MethodContainer addMethod(ReflectedMethod method) { - Optional> oentry = this.entries.stream() + public MethodContainer addMethod(ReflectedMethod method) { + Optional> oentry = this.entries.stream() .filter(e -> method.identifier().equals(e.identifier())) .findFirst(); - Entry entry = oentry.orElse(new Entry<>(method.identifier())).addMethod(method); + Entry entry = oentry.orElse(new Entry<>(method.identifier())).addMethod(method); if (oentry.isEmpty()) this.entries.add(entry); return this; } @Override - public MethodContainer addMethods(Object containingObject, Method... methods) { + public MethodContainer addMethods(Object containingObject, Method... methods) { for (Method method : methods) this.factory.produce(method, containingObject) .ifPresent(this::addMethod); @@ -50,14 +50,14 @@ public class MultiMethodContainer implements MethodContainer> methods() { + public Collection> methods() { return this.entries.stream() .flatMap(e -> e.methods.stream()) .toList(); } @Override - public Collection> findFor(I identifier) { + public Collection> findFor(I identifier) { return this.entries.stream() .filter(e -> e.identifier().equals(identifier)) .flatMap(e -> e.methods.stream()) @@ -65,18 +65,18 @@ public class MultiMethodContainer implements MethodContainer> findFirstFor(I identifier) { + public Optional> findFirstFor(I identifier) { return this.entries.stream() .filter(e -> e.identifier().equals(identifier)) .flatMap(e -> e.methods.stream()) .findFirst(); } - protected Set> entries() { + protected Set> entries() { return this.entries; } - public static record Entry(I identifier, Set> methods) { + public static record Entry(I identifier, Set> methods) { public Entry(I identifier) { this(identifier, new HashSet<>()); @@ -84,7 +84,7 @@ public class MultiMethodContainer implements MethodContainer addMethod(ReflectedMethod method) { + public Entry addMethod(ReflectedMethod method) { I midentifier = method.identifier(); if (!this.identifier().equals(midentifier)) @@ -95,7 +95,7 @@ public class MultiMethodContainer implements MethodContainer { @@ -110,7 +110,7 @@ public class MultiMethodContainer implements MethodContainer other = (Entry) obj; + Entry other = (Entry) obj; return other.identifier().equals(identifier()); } diff --git a/lib/src/main/java/net/tomatentum/cutin/method/BestCandidateMethod.java b/lib/src/main/java/net/tomatentum/cutin/method/BestCandidateMethod.java index a09dd39..88a476a 100644 --- a/lib/src/main/java/net/tomatentum/cutin/method/BestCandidateMethod.java +++ b/lib/src/main/java/net/tomatentum/cutin/method/BestCandidateMethod.java @@ -11,7 +11,7 @@ import net.tomatentum.cutin.ReflectedMethodFactory; import net.tomatentum.cutin.container.MethodContainer; import net.tomatentum.cutin.util.ReflectionUtil; -public class BestCandidateMethod extends ReflectedMethod { +public class BestCandidateMethod extends ReflectedMethod { private String methodName; private I identifier; @@ -42,7 +42,7 @@ public class BestCandidateMethod extends ReflectedMethod { } @Override - public Object run(Object context) { + public Object run(C context) { Method[] methods = Arrays.stream(containingObject.getClass().getDeclaredMethods()) .filter(x -> x.getName().equals(methodName)) .filter(x -> !x.isBridge()) @@ -63,7 +63,7 @@ public class BestCandidateMethod extends ReflectedMethod { @Override public boolean equals(Object obj) { - if (obj instanceof BestCandidateMethod bcMethod) { + if (obj instanceof BestCandidateMethod bcMethod) { return this.containingObject().getClass().equals(bcMethod.containingObject().getClass()) && this.methodName.equals(bcMethod.methodName); } @@ -75,21 +75,21 @@ public class BestCandidateMethod extends ReflectedMethod { return Objects.hash(containingObject.getClass(), methodName); } - public abstract static class Factory implements ReflectedMethodFactory.Factory { + public abstract static class Factory implements ReflectedMethodFactory.Factory { - private MethodContainer methodContainer; + private MethodContainer methodContainer; private String methodName; private Object[] additionalParameters; - protected Factory(MethodContainer methodContainer, String methodName, Object... additionalParameters) { + protected Factory(MethodContainer methodContainer, String methodName, Object... additionalParameters) { this.methodContainer = methodContainer; this.methodName = methodName; this.additionalParameters = additionalParameters; } @Override - public Optional> produce(Method method, Object containingObject) { - BestCandidateMethod bcMethod = new BestCandidateMethod<>( + public Optional> produce(Method method, Object containingObject) { + BestCandidateMethod bcMethod = new BestCandidateMethod<>( methodName, containingObject, additionalParameters); if (methodContainer.methods().contains(bcMethod)) return Optional.empty(); diff --git a/lib/src/main/java/net/tomatentum/cutin/method/ReflectedMethod.java b/lib/src/main/java/net/tomatentum/cutin/method/ReflectedMethod.java index d8c4fdd..3f69c47 100644 --- a/lib/src/main/java/net/tomatentum/cutin/method/ReflectedMethod.java +++ b/lib/src/main/java/net/tomatentum/cutin/method/ReflectedMethod.java @@ -12,7 +12,7 @@ import org.slf4j.LoggerFactory; import net.tomatentum.cutin.util.ReflectionUtil; -public abstract class ReflectedMethod { +public abstract class ReflectedMethod { private Logger logger = LoggerFactory.getLogger(getClass()); @@ -26,11 +26,11 @@ public abstract class ReflectedMethod { this.containingObject = containingObject; } - public abstract Object getParameter(Object context, int index); + public abstract Object getParameter(C context, int index); public abstract I identifier(); - public Object run(Object context) { + public Object run(C context) { method.setAccessible(true); try { return method.invoke(containingObject, getParameters(context)); @@ -48,7 +48,7 @@ public abstract class ReflectedMethod { return this.containingObject; } - private Object[] getParameters(Object context) { + private Object[] getParameters(C context) { int parameterCount = method.getParameterCount(); List parameters = new ArrayList<>(); diff --git a/lib/src/test/java/net/tomatentum/cutin/ReflectedMethodTest.java b/lib/src/test/java/net/tomatentum/cutin/ReflectedMethodTest.java index dfa66d6..3bb28a7 100644 --- a/lib/src/test/java/net/tomatentum/cutin/ReflectedMethodTest.java +++ b/lib/src/test/java/net/tomatentum/cutin/ReflectedMethodTest.java @@ -11,14 +11,14 @@ class ReflectedMethodTest { @Test void methodTest() { - ReflectedMethod method = new TestReflectedMethod(new TestMethodClass()); + ReflectedMethod method = new TestReflectedMethod(new TestMethodClass()); Object result = method.run("testContext"); assertTrue((boolean)result); } @Test void testBCMethod() { - ReflectedMethod method = new BestCandidateMethod( + ReflectedMethod method = new BestCandidateMethod( "test", new TestMethodClass(), "ident", diff --git a/lib/src/test/java/net/tomatentum/cutin/TestReflectedMethod.java b/lib/src/test/java/net/tomatentum/cutin/TestReflectedMethod.java index d18c140..08611d6 100644 --- a/lib/src/test/java/net/tomatentum/cutin/TestReflectedMethod.java +++ b/lib/src/test/java/net/tomatentum/cutin/TestReflectedMethod.java @@ -4,7 +4,7 @@ import java.lang.reflect.Method; import net.tomatentum.cutin.method.ReflectedMethod; -public class TestReflectedMethod extends ReflectedMethod { +public class TestReflectedMethod extends ReflectedMethod { protected TestReflectedMethod(Object containingObject) { super(getMethod(containingObject), containingObject); @@ -12,7 +12,7 @@ public class TestReflectedMethod extends ReflectedMethod { } @Override - public Object getParameter(Object context, int index) { + public Object getParameter(String context, int index) { return 2; }