refactor(factory): move to own package and add factories getter

This commit is contained in:
tueem 2025-04-30 12:56:48 +02:00
parent 8d24604707
commit 4dd7b70f40
Signed by: tueem
GPG Key ID: 65C8667EC17A88FB
5 changed files with 17 additions and 12 deletions

View File

@ -12,7 +12,7 @@ import java.util.Set;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import net.tomatentum.cutin.ReflectedMethodFactory;
import net.tomatentum.cutin.factory.ReflectedMethodFactory;
import net.tomatentum.cutin.method.ReflectedMethod;
public class LoneMethodContainer<I extends Object, C extends Object> implements MethodContainer<I, C> {

View File

@ -10,7 +10,7 @@ import java.util.stream.Collectors;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import net.tomatentum.cutin.ReflectedMethodFactory;
import net.tomatentum.cutin.factory.ReflectedMethodFactory;
import net.tomatentum.cutin.method.ReflectedMethod;
import net.tomatentum.cutin.util.ReflectionUtil;

View File

@ -1,16 +1,18 @@
package net.tomatentum.cutin;
package net.tomatentum.cutin.factory;
import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.Optional;
import java.util.Set;
import net.tomatentum.cutin.MethodParser;
import net.tomatentum.cutin.method.ReflectedMethod;
public interface ReflectedMethodFactory<I extends Object, C extends Object> {
Optional<ReflectedMethod<I, C>> produce(Method method, Object containingClass);
ReflectedMethodFactory<I, C> addFactory(Factory<I, C> factory);
Set<ReflectedMethodFactory.Factory<I, C>> factories();
public interface Factory<I extends Object, C extends Object> {

View File

@ -1,30 +1,28 @@
package net.tomatentum.cutin;
package net.tomatentum.cutin.factory;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Optional;
import java.util.Set;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import net.tomatentum.cutin.MethodParser;
import net.tomatentum.cutin.method.ReflectedMethod;
import net.tomatentum.cutin.util.ReflectionUtil;
public class ReflectedMethodFactoryImpl<I extends Object, C extends Object> implements ReflectedMethodFactory<I, C> {
private Logger logger = LoggerFactory.getLogger(getClass());
private List<Factory<I, C>> factories;
private Set<Factory<I, C>> factories;
public ReflectedMethodFactoryImpl() {
this(new ArrayList<>());
this(new HashSet<>());
}
public ReflectedMethodFactoryImpl(List<Factory<I, C>> factories) {
public ReflectedMethodFactoryImpl(Set<Factory<I, C>> factories) {
this.factories = factories;
}
@ -51,6 +49,11 @@ public class ReflectedMethodFactoryImpl<I extends Object, C extends Object> impl
return this;
}
@Override
public Set<Factory<I, C>> factories() {
return this.factories;
}
private Optional<ReflectedMethod<I, C>> factoryProduce(Factory<I, C> factory, Method method, Object containingClass) {
Set<MethodParser> parser = new HashSet<>();
factory.addParser(parser);

View File

@ -10,9 +10,9 @@ import java.util.Optional;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import net.tomatentum.cutin.ReflectedMethodFactory;
import net.tomatentum.cutin.ReflectedMethodFactory.ParserResults;
import net.tomatentum.cutin.container.MethodContainer;
import net.tomatentum.cutin.factory.ReflectedMethodFactory;
import net.tomatentum.cutin.factory.ReflectedMethodFactory.ParserResults;
import net.tomatentum.cutin.util.ReflectionUtil;
public abstract class BestCandidateMethod<I extends Object, C extends Object> extends ReflectedMethod<I, C> {