mirror of
https://github.com/oxen-io/session-android.git
synced 2025-01-07 23:27:42 +00:00
25 lines
758 B
Java
25 lines
758 B
Java
|
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);
|
||
|
}
|
||
|
|
||
|
public @NonNull
|
||
|
Job instantiate(@NonNull String jobFactoryKey, @NonNull Job.Parameters parameters, @NonNull Data data) {
|
||
|
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.");
|
||
|
}
|
||
|
}
|
||
|
}
|