Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
</parent>

<artifactId>scijava-common</artifactId>
<version>2.40.1-SNAPSHOT</version>
<version>2.41.0-SNAPSHOT</version>

<name>SciJava Common</name>
<description>SciJava Common is a shared library for SciJava software. It provides a plugin framework, with an extensible mechanism for service discovery, backed by its own annotation processor, so that plugins can be loaded dynamically. It is used by both ImageJ and SCIFIO.</description>
Expand Down
24 changes: 20 additions & 4 deletions src/main/java/org/scijava/module/DefaultModuleService.java
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public class DefaultModuleService extends AbstractService implements
private PrefService prefService;

@Parameter
private ConvertService conversionService;
private ConvertService convertService;

/** Index of registered modules. */
private ModuleIndex moduleIndex;
Expand Down Expand Up @@ -269,7 +269,7 @@ public <T> void save(final ModuleItem<T> item, final T value) {
final String sValue = value == null ? "" : value.toString();

// do not persist if object cannot be converted back from a string
if (!conversionService.supports(sValue, item.getType())) return;
if (!convertService.supports(sValue, item.getType())) return;

final String persistKey = item.getPersistKey();
if (persistKey == null || persistKey.isEmpty()) {
Expand Down Expand Up @@ -297,9 +297,25 @@ public <T> T load(final ModuleItem<T> item) {
// if persisted value has never been set before return null
if (sValue == null) return null;

return conversionService.convert(sValue, item.getType());
return convertService.convert(sValue, item.getType());
}

@Override
public <T> T getDefaultValue(final ModuleItem<T> item) {
final T min = item.getMinimumValue();
if (min != null) return min;
final T softMin = item.getSoftMinimum();
if (softMin != null) return softMin;
final T max = item.getMaximumValue();
if (max != null) return max;
final T softMax = item.getSoftMaximum();
if (softMax != null) return softMax;
final T zero = convertService.convert("0", item.getType());
if (zero != null) return zero;
// no known default value
return null;
}

// -- Service methods --

@Override
Expand Down Expand Up @@ -399,7 +415,7 @@ private void assignInputs(final Module module,
}
else {
final Class<?> type = input.getType();
converted = conversionService.convert(value, type);
converted = convertService.convert(value, type);
if (value != null && converted == null) {
log.error("For input " + name + ": incompatible object " +
value.getClass().getName() + " for type " + type.getName());
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/org/scijava/module/ModuleService.java
Original file line number Diff line number Diff line change
Expand Up @@ -285,4 +285,8 @@ <M extends Module> Future<M> run(M module,
* {@link ModuleItem}.
*/
<T> T load(ModuleItem<T> item);

/** Gets the default value of the given {@link ModuleItem}. */
<T> T getDefaultValue(final ModuleItem<T> item);

}