feat(factory): add Identifier Generic
This commit is contained in:
parent
c0da5ee75d
commit
1891037ed7
@ -5,14 +5,14 @@ import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
|
||||
public interface ReflectedMethodFactory {
|
||||
Optional<ReflectedMethod> produce(Method method, Object containingClass);
|
||||
ReflectedMethodFactory addFactory(Factory factory);
|
||||
public interface ReflectedMethodFactory<I extends Object> {
|
||||
Optional<ReflectedMethod<I>> produce(Method method, Object containingClass);
|
||||
ReflectedMethodFactory<I> addFactory(Factory<I> factory);
|
||||
|
||||
public interface Factory {
|
||||
public interface Factory<I extends Object> {
|
||||
|
||||
Optional<ReflectedMethod> produce(Method method, Object containingObject);
|
||||
void addParser(ReflectedMethod method, List<MethodParser> parser);
|
||||
Optional<ReflectedMethod<I>> produce(Method method, Object containingObject);
|
||||
void addParser(ReflectedMethod<I> method, List<MethodParser> parser);
|
||||
|
||||
}
|
||||
}
|
@ -11,23 +11,23 @@ import org.slf4j.LoggerFactory;
|
||||
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 List<Factory> factories;
|
||||
private List<Factory<I>> factories;
|
||||
|
||||
public ReflectedMethodFactoryImpl() {
|
||||
this(new ArrayList<>());
|
||||
}
|
||||
|
||||
public ReflectedMethodFactoryImpl(List<Factory> factories) {
|
||||
public ReflectedMethodFactoryImpl(List<Factory<I>> factories) {
|
||||
this.factories = factories;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<ReflectedMethod> produce(Method method, Object containingClass) {
|
||||
Optional<ReflectedMethod> rmethod = this.factories.stream()
|
||||
public Optional<ReflectedMethod<I>> produce(Method method, Object containingClass) {
|
||||
Optional<ReflectedMethod<I>> rmethod = this.factories.stream()
|
||||
.map(f -> factoryProduce(f, method, containingClass))
|
||||
.filter(Optional::isPresent)
|
||||
.map(Optional::get)
|
||||
@ -41,14 +41,14 @@ public class ReflectedMethodFactoryImpl implements ReflectedMethodFactory {
|
||||
}
|
||||
|
||||
@Override
|
||||
public ReflectedMethodFactory addFactory(Factory factory) {
|
||||
public ReflectedMethodFactory<I> addFactory(Factory<I> factory) {
|
||||
this.factories.add(factory);
|
||||
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<>();
|
||||
Optional<ReflectedMethod> m = factory.produce(method, containingClass);
|
||||
Optional<ReflectedMethod<I>> m = factory.produce(method, containingClass);
|
||||
m.ifPresent(x -> {
|
||||
factory.addParser(x, parser);
|
||||
parser.forEach(MethodParser::parse);
|
||||
|
@ -14,9 +14,9 @@ import net.tomatentum.cutin.ReflectedMethodFactory;
|
||||
public class LoneMethodContainer<I extends Object> implements MethodContainer<I> {
|
||||
|
||||
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.factory = factory;
|
||||
}
|
||||
|
@ -17,9 +17,9 @@ import net.tomatentum.cutin.util.ReflectionUtil;
|
||||
public class MultiMethodContainer<I extends Object> implements MethodContainer<I> {
|
||||
|
||||
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.factory = factory;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user