feat(factory): add Identifier Generic
All checks were successful
Build / Gradle-Build (push) Successful in 13s
Publish / Gradle-Publish (push) Successful in 12s
Test / Gradle-Test (push) Successful in 14s

This commit is contained in:
tueem 2025-04-10 15:05:46 +02:00
parent c0da5ee75d
commit 1891037ed7
Signed by: tueem
GPG Key ID: 65C8667EC17A88FB
4 changed files with 18 additions and 18 deletions

View File

@ -5,14 +5,14 @@ import java.util.List;
import java.util.Optional; import java.util.Optional;
public interface ReflectedMethodFactory { public interface ReflectedMethodFactory<I extends Object> {
Optional<ReflectedMethod> produce(Method method, Object containingClass); Optional<ReflectedMethod<I>> produce(Method method, Object containingClass);
ReflectedMethodFactory addFactory(Factory factory); ReflectedMethodFactory<I> addFactory(Factory<I> factory);
public interface Factory { public interface Factory<I extends Object> {
Optional<ReflectedMethod> produce(Method method, Object containingObject); Optional<ReflectedMethod<I>> produce(Method method, Object containingObject);
void addParser(ReflectedMethod method, List<MethodParser> parser); void addParser(ReflectedMethod<I> method, List<MethodParser> parser);
} }
} }

View File

@ -11,23 +11,23 @@ import org.slf4j.LoggerFactory;
import net.tomatentum.cutin.util.ReflectionUtil; import net.tomatentum.cutin.util.ReflectionUtil;
public class ReflectedMethodFactoryImpl implements ReflectedMethodFactory { public class ReflectedMethodFactoryImpl<I extends Object> implements ReflectedMethodFactory<I> {
private Logger logger = LoggerFactory.getLogger(getClass()); private Logger logger = LoggerFactory.getLogger(getClass());
private List<Factory> factories; private List<Factory<I>> factories;
public ReflectedMethodFactoryImpl() { public ReflectedMethodFactoryImpl() {
this(new ArrayList<>()); this(new ArrayList<>());
} }
public ReflectedMethodFactoryImpl(List<Factory> factories) { public ReflectedMethodFactoryImpl(List<Factory<I>> factories) {
this.factories = factories; this.factories = factories;
} }
@Override @Override
public Optional<ReflectedMethod> produce(Method method, Object containingClass) { public Optional<ReflectedMethod<I>> produce(Method method, Object containingClass) {
Optional<ReflectedMethod> rmethod = this.factories.stream() Optional<ReflectedMethod<I>> rmethod = this.factories.stream()
.map(f -> factoryProduce(f, method, containingClass)) .map(f -> factoryProduce(f, method, containingClass))
.filter(Optional::isPresent) .filter(Optional::isPresent)
.map(Optional::get) .map(Optional::get)
@ -41,14 +41,14 @@ public class ReflectedMethodFactoryImpl implements ReflectedMethodFactory {
} }
@Override @Override
public ReflectedMethodFactory addFactory(Factory factory) { public ReflectedMethodFactory<I> addFactory(Factory<I> factory) {
this.factories.add(factory); this.factories.add(factory);
return this; return this;
} }
private Optional<ReflectedMethod> factoryProduce(Factory factory, Method method, Object containingClass) { private Optional<ReflectedMethod<I>> factoryProduce(Factory<I> factory, Method method, Object containingClass) {
List<MethodParser> parser = new ArrayList<>(); List<MethodParser> parser = new ArrayList<>();
Optional<ReflectedMethod> m = factory.produce(method, containingClass); Optional<ReflectedMethod<I>> m = factory.produce(method, containingClass);
m.ifPresent(x -> { m.ifPresent(x -> {
factory.addParser(x, parser); factory.addParser(x, parser);
parser.forEach(MethodParser::parse); parser.forEach(MethodParser::parse);

View File

@ -14,9 +14,9 @@ import net.tomatentum.cutin.ReflectedMethodFactory;
public class LoneMethodContainer<I extends Object> implements MethodContainer<I> { public class LoneMethodContainer<I extends Object> implements MethodContainer<I> {
private Map<I, ReflectedMethod<I>> methodStore; private Map<I, ReflectedMethod<I>> methodStore;
private ReflectedMethodFactory factory; private ReflectedMethodFactory<I> factory;
public LoneMethodContainer(ReflectedMethodFactory factory) { public LoneMethodContainer(ReflectedMethodFactory<I> factory) {
this.methodStore = new HashMap<>(); this.methodStore = new HashMap<>();
this.factory = factory; this.factory = factory;
} }

View File

@ -17,9 +17,9 @@ import net.tomatentum.cutin.util.ReflectionUtil;
public class MultiMethodContainer<I extends Object> implements MethodContainer<I> { public class MultiMethodContainer<I extends Object> implements MethodContainer<I> {
private Set<Entry<I>> entries; private Set<Entry<I>> entries;
private ReflectedMethodFactory factory; private ReflectedMethodFactory<I> factory;
public MultiMethodContainer(ReflectedMethodFactory factory) { public MultiMethodContainer(ReflectedMethodFactory<I> factory) {
this.entries = new HashSet<>(); this.entries = new HashSet<>();
this.factory = factory; this.factory = factory;
} }