24 lines
798 B
Java
24 lines
798 B
Java
package tschipp.carryon.platform;
|
|
|
|
import tschipp.carryon.Constants;
|
|
import tschipp.carryon.platform.services.IGamestagePlatformHelper;
|
|
import tschipp.carryon.platform.services.IPlatformHelper;
|
|
|
|
import java.util.ServiceLoader;
|
|
|
|
public class Services {
|
|
|
|
public static final IPlatformHelper PLATFORM = load(IPlatformHelper.class);
|
|
|
|
public static final IGamestagePlatformHelper GAMESTAGES = load(IGamestagePlatformHelper.class);
|
|
|
|
public static <T> T load(Class<T> clazz) {
|
|
|
|
final T loadedService = ServiceLoader.load(clazz)
|
|
.findFirst()
|
|
.orElseThrow(() -> new NullPointerException("Failed to load service for " + clazz.getName()));
|
|
Constants.LOG.debug("Loaded {} for service {}", loadedService, clazz);
|
|
return loadedService;
|
|
}
|
|
}
|