Skip to content

Commit 0424064

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 2c95f28 commit 0424064

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.25.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
@@ -86,6 +86,12 @@ public void initialize() {
8686
public ArrayList<PT> get() {
8787
return new ArrayList<PT>(getInstances());
8888
}
89+
90+
@Override
91+
public Class<?> getType() {
92+
return getPluginType();
93+
}
94+
8995
});
9096
}
9197

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

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

286+
@Override
287+
public Class<?> getType() {
288+
return ScriptInfo.class;
289+
}
290+
286291
});
287292
}
288293

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)