Get rid of singleton, and refactor LauncherFactory to be a static class

Signed-off-by: solonovamax <solonovamax@12oclockpoint.com>
This commit is contained in:
solonovamax 2022-10-27 18:01:17 -04:00 committed by TheKodeToad
parent e68dcea6bc
commit 9062d28704
2 changed files with 17 additions and 19 deletions

View File

@ -138,10 +138,7 @@ public final class EntryPoint {
}
try {
Launcher launcher =
LauncherFactory
.INSTANCE
.createLauncher(params);
Launcher launcher = LauncherFactory.createLauncher(params);
launcher.launch();

View File

@ -35,6 +35,7 @@
package org.prismlauncher;
import org.prismlauncher.impl.LegacyLauncher;
import org.prismlauncher.impl.StandardLauncher;
import org.prismlauncher.utils.Parameters;
@ -42,13 +43,11 @@ import org.prismlauncher.utils.Parameters;
import java.util.HashMap;
import java.util.Map;
public final class LauncherFactory {
public static final LauncherFactory INSTANCE = new LauncherFactory();
private final Map<String, LauncherProvider> launcherRegistry = new HashMap<>();
private LauncherFactory() {
private static final Map<String, LauncherProvider> launcherRegistry = new HashMap<>();
static {
launcherRegistry.put("standard", new LauncherProvider() {
@Override
public Launcher provide(Parameters parameters) {
@ -62,22 +61,24 @@ public final class LauncherFactory {
}
});
}
public Launcher createLauncher(Parameters parameters) {
private LauncherFactory() {
}
public static Launcher createLauncher(Parameters parameters) {
String name = parameters.first("launcher");
LauncherProvider launcherProvider = launcherRegistry.get(name);
if (launcherProvider == null)
throw new IllegalArgumentException("Invalid launcher type: " + name);
return launcherProvider.provide(parameters);
}
public interface LauncherProvider {
Launcher provide(Parameters parameters);
}
}