Skip to content

Commit

Permalink
Fixing bug with input class in ModelBuilder.build(Map<String,Object>)
Browse files Browse the repository at this point in the history
  • Loading branch information
kevto committed Jul 6, 2021
1 parent 307f274 commit 4f16b35
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>javax.visrec</groupId>
<artifactId>visrec-api</artifactId>
<version>1.0.4-SNAPSHOT</version>
<version>1.0.5-SNAPSHOT</version>
<packaging>jar</packaging>

<name>javax.visrec:visrec-api</name>
Expand Down
8 changes: 6 additions & 2 deletions src/main/java/javax/visrec/ml/model/ModelBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,22 @@ public interface ModelBuilder<T> {
* @throws javax.visrec.ml.model.ModelCreationException
*/
default T build(Map<String, Object> configuration) throws ModelCreationException {
ModelBuilder<T> thizz = this;
Method[] methods = this.getClass().getDeclaredMethods();
for (Method method : methods) {
if (!method.getName().equals("build") && method.getParameterCount() == 1
&& configuration.containsKey(method.getName())) {
try {
method.invoke(this, configuration.get(method.getName()));
Object obj = method.invoke(thizz, configuration.get(method.getName()));
if (thizz.getClass().isInstance(obj)) {
thizz = (ModelBuilder<T>) thizz.getClass().cast(obj);
}
} catch (IllegalAccessException | InvocationTargetException | IllegalArgumentException e) {
throw new InvalidConfigurationException("Couldn't invoke '" + method.getName() + "'", e);
}
}
}
return build();
return thizz.build();
}

}

0 comments on commit 4f16b35

Please sign in to comment.