2019-03-28 08:56:35 -07:00
|
|
|
package org.thoughtcrime.securesms.jobmanager;
|
|
|
|
|
|
|
|
import android.support.annotation.NonNull;
|
|
|
|
|
|
|
|
import java.util.HashMap;
|
|
|
|
import java.util.Map;
|
|
|
|
|
|
|
|
class JobInstantiator {
|
|
|
|
|
|
|
|
private final Map<String, Job.Factory> jobFactories;
|
|
|
|
|
|
|
|
JobInstantiator(@NonNull Map<String, Job.Factory> jobFactories) {
|
|
|
|
this.jobFactories = new HashMap<>(jobFactories);
|
|
|
|
}
|
|
|
|
|
2019-04-17 10:21:30 -04:00
|
|
|
public @NonNull Job instantiate(@NonNull String jobFactoryKey, @NonNull Job.Parameters parameters, @NonNull Data data) {
|
2019-03-28 08:56:35 -07:00
|
|
|
if (jobFactories.containsKey(jobFactoryKey)) {
|
|
|
|
return jobFactories.get(jobFactoryKey).create(parameters, data);
|
|
|
|
} else {
|
|
|
|
throw new IllegalStateException("Tried to instantiate a job with key '" + jobFactoryKey + "', but no matching factory was found.");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|