refactor(bcmethod): move duplicate checking out of factory
This commit is contained in:
parent
4dd7b70f40
commit
ad2c4c00f6
@ -29,6 +29,10 @@ public class LoneMethodContainer<I extends Object, C extends Object> implements
|
||||
|
||||
@Override
|
||||
public MethodContainer<I, C> addMethod(ReflectedMethod<I, C> method) {
|
||||
if (this.methodStore.keySet().contains(method.identifier())) {
|
||||
logger.warn("Could not add {} to container because the same identifier was already present.", method);
|
||||
return this;
|
||||
}
|
||||
this.methodStore.put(method.identifier(), method);
|
||||
logger.debug("Added {} to container", method);
|
||||
return this;
|
||||
|
@ -5,14 +5,10 @@ import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
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> {
|
||||
@ -70,27 +66,5 @@ public abstract class BestCandidateMethod<I extends Object, C extends Object> ex
|
||||
}
|
||||
return parameters;
|
||||
}
|
||||
|
||||
public abstract static class Factory<I extends Object, C extends Object> implements ReflectedMethodFactory.Factory<I, C> {
|
||||
|
||||
private MethodContainer<I, C> methodContainer;
|
||||
private String methodName;
|
||||
|
||||
protected Factory(MethodContainer<I, C> methodContainer, String methodName) {
|
||||
this.methodContainer = methodContainer;
|
||||
this.methodName = methodName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<ReflectedMethod<I, C>> produce(Method method, Object containingObject, ParserResults results) {
|
||||
Optional<BestCandidateMethod<I, C>> bcMethod = bcProduce(methodName, containingObject, results);
|
||||
if (bcMethod.isEmpty() || methodContainer.methods().contains(bcMethod.get()))
|
||||
return Optional.empty();
|
||||
return Optional.of(bcMethod.get());
|
||||
}
|
||||
|
||||
protected abstract Optional<BestCandidateMethod<I, C>> bcProduce(String methodName, Object containingObject, ParserResults results);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user