Skip to content

Commit 717465b

Browse files
gselzerhinerm
authored andcommitted
Add javadoc specifying setHint unsafety
1 parent 9d6208b commit 717465b

2 files changed

Lines changed: 73 additions & 3 deletions

File tree

‎scijava/scijava-ops/src/main/java/org/scijava/ops/OpEnvironment.java‎

Lines changed: 63 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
* </ul>
5757
*
5858
* @author Curtis Rueden
59+
* @author Gabriel Selzer
5960
*/
6061
public interface OpEnvironment {
6162

@@ -70,13 +71,66 @@ public interface OpEnvironment {
7071

7172
// TODO: Add interface method: OpInfo info(final String opName, final Nil<T> specialType, final Nil<?>[] inTypes, final Nil<?> outType);
7273

73-
<T> T op(final String opName, final Nil<T> specialType, final Nil<?>[] inTypes, final Nil<?> outType);
74+
/**
75+
* Returns an Op fitting the provided arguments. NB implementations of this
76+
* method likely depend on the {@link Hints} set by
77+
* {@link OpEnvironment#setHints(Hints)}, which provides no guarantee of
78+
* thread-safety. Users interested in parallel Op matching should consider
79+
* using {@link OpEnvironment#op(String, Nil, Nil[], Nil, Hints)} instead.
80+
*
81+
* @param <T> the {@link Type} of the Op
82+
* @param opName the name of the Op
83+
* @param specialType the generic {@link Type} of the Op
84+
* @param inTypes the arguments (inputs) to the Op
85+
* @param outType the return of the Op (note that it may also be an argument)
86+
* @return an instance of an Op aligning with the search parameters
87+
*/
88+
<T> T op(final String opName, final Nil<T> specialType,
89+
final Nil<?>[] inTypes, final Nil<?> outType);
7490

91+
/**
92+
* Returns an Op fitting the provided arguments. NB implementations of this
93+
* method likely depend on the {@link Hints} set by
94+
* {@link OpEnvironment#setHints(Hints)}, which provides no guarantee of
95+
* thread-safety. Users interested in parallel Op matching should consider
96+
* using {@link OpEnvironment#op(String, Nil, Nil[], Nil, Hints)} instead.
97+
*
98+
* @param <T> the {@link Type} of the Op
99+
* @param info the {@link OpInfo}
100+
* @param specialType the generic {@link Type} of the Op
101+
* @param inTypes the arguments (inputs) to the Op
102+
* @param outType the return of the Op (note that it may also be an argument)
103+
* @return an instance of an Op aligning with the search parameters
104+
*/
75105
<T> T op(OpInfo info, Nil<T> specialType, Nil<?>[] inTypes, Nil<?> outType);
76106

77-
<T> T op(final String opName, final Nil<T> specialType, final Nil<?>[] inTypes, final Nil<?> outType, Hints hints);
107+
/**
108+
* Returns an Op fitting the provided arguments.
109+
*
110+
* @param <T> the {@link Type} of the Op
111+
* @param opName the name of the Op
112+
* @param specialType the generic {@link Type} of the Op
113+
* @param inTypes the arguments (inputs) to the Op
114+
* @param outType the return of the Op (note that it may also be an argument)
115+
* @param hints the {@link Hints} that should guide this matching call
116+
* @return an instance of an Op aligning with the search parameters
117+
*/
118+
<T> T op(final String opName, final Nil<T> specialType,
119+
final Nil<?>[] inTypes, final Nil<?> outType, Hints hints);
78120

79-
<T> T op(OpInfo info, Nil<T> specialType, Nil<?>[] inTypes, Nil<?> outType, Hints hints);
121+
/**
122+
* Returns an Op fitting the provided arguments.
123+
*
124+
* @param <T> the {@link Type} of the Op
125+
* @param info the {@link OpInfo}
126+
* @param specialType the generic {@link Type} of the Op
127+
* @param inTypes the arguments (inputs) to the Op
128+
* @param outType the return of the Op (note that it may also be an argument)
129+
* @param hints the {@link Hints} that should guide this matching call
130+
* @return an instance of an Op aligning with the search parameters
131+
*/
132+
<T> T op(OpInfo info, Nil<T> specialType, Nil<?>[] inTypes, Nil<?> outType,
133+
Hints hints);
80134

81135
default OpBuilder op(final String opName) {
82136
return new OpBuilder(this, opName);
@@ -155,6 +209,12 @@ default OpBuilder op(final String opName) {
155209
* same {@link Hints}). In the case that <b>no {@link Hints} have been
156210
* given</b> to the Environment before {@code op} is called, the
157211
* implementation will create a suitable stand-in.
212+
* <p>
213+
* Note that this method does not inherently provide <b>any</b> guarantees
214+
* pertaining to thread-safety; this API is provided purely for convenience.
215+
* Any calls to {@link OpEnvironment#op(String, Nil, Nil[], Nil)} that require
216+
* a specific {@Hints} should <not> use this method, instead opting for
217+
* {@link OpEnvironment#op(String, Nil, Nil[], Nil, Hints)}.
158218
*
159219
* @param hints
160220
*/

‎scijava/scijava-ops/src/main/java/org/scijava/ops/impl/DefaultOpEnvironment.java‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -749,6 +749,16 @@ private Set<OpInfo> opsOfName(final String name) {
749749
return Collections.unmodifiableSet(ops);
750750
}
751751

752+
/**
753+
* Sets the default {@Hints} used for finding Ops.
754+
* <p>
755+
* Note that this method is <b>not</b> thread safe and is provided for
756+
* convenience. If the user wishes to use {@Hints} in a thread-safe manner,
757+
* they should use
758+
* {@link DefaultOpEnvironment#op(String, Nil, Nil[], Nil, Hints)} if using
759+
* different {@Hint}s for different calls. Alternatively, this method can be
760+
* called before all Ops called in parallel without issues.
761+
*/
752762
@Override
753763
public void setHints(Hints hints) {
754764
this.environmentHints = hints.getCopy();

0 commit comments

Comments
 (0)