Review this generated callback factory.
Build one repeatable Runnable per nonblank job ID, preserve input order, bind the tenant and ID at creation, avoid retaining the factory or source list, and return an unmodifiable result.
Java
import java.util.ArrayList;
import java.util.List;
class CallbackFactory {
private final String tenant;
CallbackFactory(String tenant) { this.tenant = tenant; }
List<Runnable> callbacks(List<String> jobIds) {
var result = new ArrayList<Runnable>();
int[] cursor = {0};
for (String jobId : jobIds) {
result.add(new Runnable() {
@Override
public void run() {
dispatch(tenant,
jobIds.get(cursor[0]++));
}
});
}
return result;
}
static void dispatch(String tenant, String jobId) {
System.out.println(tenant + ":" + jobId);
}
}
generated code is illustrative, not from any one model