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 { try {
Launcher launcher = Launcher launcher = LauncherFactory.createLauncher(params);
LauncherFactory
.INSTANCE
.createLauncher(params);
launcher.launch(); launcher.launch();

View File

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