Skip to content

Commit 8bbb47a

Browse files
committed
LazyObjects: add getType() method
This breaks backwards compatibility, so bumps the development snapshot version to 3.0.0. The rationale is to make it possible for the ObjectIndex to better discriminate which objects should be resolved for a particular call to ObjectIndex#get(Class). The current behavior is to resolve _all_ pending objects with _any_ call to get(Class), which is generally suboptimal.
1 parent 5ef3f68 commit 8bbb47a

File tree

5 files changed

+24
-1
lines changed

5 files changed

+24
-1
lines changed

pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
</parent>
1111

1212
<artifactId>scijava-common</artifactId>
13-
<version>2.41.1-SNAPSHOT</version>
13+
<version>3.0.0-SNAPSHOT</version>
1414

1515
<name>SciJava Common</name>
1616
<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>

src/main/java/org/scijava/object/LazyObjects.java

+7
Original file line numberDiff line numberDiff line change
@@ -45,4 +45,11 @@ public interface LazyObjects<T> {
4545
/** Gets the collection of objects. */
4646
Collection<T> get();
4747

48+
/**
49+
* The type of the objects which will be resolved from a call to
50+
* {@link #get()}. This information is used to determine whether to resolve
51+
* the objects in response to an {@link ObjectIndex#get(Class)} call.
52+
*/
53+
Class<?> getType();
54+
4855
}

src/main/java/org/scijava/plugin/AbstractSingletonService.java

+6
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,12 @@ public void initialize() {
9191
public ArrayList<PT> get() {
9292
return new ArrayList<PT>(getInstances());
9393
}
94+
95+
@Override
96+
public Class<?> getType() {
97+
return getPluginType();
98+
}
99+
94100
});
95101
}
96102

src/main/java/org/scijava/script/DefaultScriptService.java

+5
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,11 @@ public Collection<ScriptInfo> get() {
285285
return scripts().values();
286286
}
287287

288+
@Override
289+
public Class<?> getType() {
290+
return ScriptInfo.class;
291+
}
292+
288293
});
289294
}
290295

src/test/java/org/scijava/object/ObjectIndexTest.java

+5
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,11 @@ public Collection<String> get() {
7171
return Arrays.asList(o4, o5, o6);
7272
}
7373

74+
@Override
75+
public Class<?> getType() {
76+
return String.class;
77+
}
78+
7479
});
7580

7681
final List<Object> all = objectIndex.getAll();

0 commit comments

Comments
 (0)