diff --git a/HMCLCore/src/main/java/org/jackhuang/hmcl/download/liteloader/LiteLoaderBMCLVersionList.java b/HMCLCore/src/main/java/org/jackhuang/hmcl/download/liteloader/LiteLoaderBMCLVersionList.java index c80aa47a956..c1fe0d4647e 100644 --- a/HMCLCore/src/main/java/org/jackhuang/hmcl/download/liteloader/LiteLoaderBMCLVersionList.java +++ b/HMCLCore/src/main/java/org/jackhuang/hmcl/download/liteloader/LiteLoaderBMCLVersionList.java @@ -43,15 +43,7 @@ public boolean hasType() { return false; } - private static final class LiteLoaderBMCLVersion { - - private final LiteLoaderVersion build; - private final String version; - - public LiteLoaderBMCLVersion(LiteLoaderVersion build, String version) { - this.build = build; - this.version = version; - } + private record LiteLoaderBMCLVersion(LiteLoaderVersion build, String version) { } @Override @@ -78,7 +70,7 @@ public Task refreshAsync(String gameVersion) { downloadProvider.getApiRoot() + "/liteloader/download", Collections.singletonMap("version", v.version) )), - v.build.getTweakClass(), v.build.getLibraries() + v.build.tweakClass(), v.build.libraries() )); } finally { lock.writeLock().unlock(); diff --git a/HMCLCore/src/main/java/org/jackhuang/hmcl/download/liteloader/LiteLoaderBranch.java b/HMCLCore/src/main/java/org/jackhuang/hmcl/download/liteloader/LiteLoaderBranch.java index ec27e0f34de..6dabbb5a38a 100644 --- a/HMCLCore/src/main/java/org/jackhuang/hmcl/download/liteloader/LiteLoaderBranch.java +++ b/HMCLCore/src/main/java/org/jackhuang/hmcl/download/liteloader/LiteLoaderBranch.java @@ -30,33 +30,11 @@ * @author huangyuhui */ @Immutable -public final class LiteLoaderBranch { +public record LiteLoaderBranch(@SerializedName("libraries") Collection libraries, + @SerializedName("com.mumfrey:liteloader") Map liteLoader) { - @SerializedName("libraries") - private final Collection libraries; - - @SerializedName("com.mumfrey:liteloader") - private final Map liteLoader; - - /** - * No-arg constructor for Gson. - */ - @SuppressWarnings("unused") - public LiteLoaderBranch() { - this(Collections.emptySet(), Collections.emptyMap()); + public LiteLoaderBranch { + libraries = libraries == null ? Collections.emptySet() : Collections.unmodifiableCollection(libraries); + liteLoader = liteLoader == null ? Collections.emptyMap() : Collections.unmodifiableMap(liteLoader); } - - public LiteLoaderBranch(Collection libraries, Map liteLoader) { - this.libraries = libraries; - this.liteLoader = liteLoader; - } - - public Collection getLibraries() { - return Collections.unmodifiableCollection(libraries); - } - - public Map getLiteLoader() { - return Collections.unmodifiableMap(liteLoader); - } - } diff --git a/HMCLCore/src/main/java/org/jackhuang/hmcl/download/liteloader/LiteLoaderGameVersions.java b/HMCLCore/src/main/java/org/jackhuang/hmcl/download/liteloader/LiteLoaderGameVersions.java index ce93ad820f0..da1aab3ff5f 100644 --- a/HMCLCore/src/main/java/org/jackhuang/hmcl/download/liteloader/LiteLoaderGameVersions.java +++ b/HMCLCore/src/main/java/org/jackhuang/hmcl/download/liteloader/LiteLoaderGameVersions.java @@ -25,41 +25,7 @@ * @author huangyuhui */ @Immutable -public final class LiteLoaderGameVersions { - - @SerializedName("repo") - private final LiteLoaderRepository repoitory; - - @SerializedName("artefacts") - private final LiteLoaderBranch artifacts; - - @SerializedName("snapshots") - private final LiteLoaderBranch snapshots; - - /** - * No-arg constructor for Gson. - */ - @SuppressWarnings("unused") - public LiteLoaderGameVersions() { - this(null, null, null); - } - - public LiteLoaderGameVersions(LiteLoaderRepository repoitory, LiteLoaderBranch artifacts, LiteLoaderBranch snapshots) { - this.repoitory = repoitory; - this.artifacts = artifacts; - this.snapshots = snapshots; - } - - public LiteLoaderRepository getRepoitory() { - return repoitory; - } - - public LiteLoaderBranch getArtifacts() { - return artifacts; - } - - public LiteLoaderBranch getSnapshots() { - return snapshots; - } - +public record LiteLoaderGameVersions(@SerializedName("repo") LiteLoaderRepository repoitory, + @SerializedName("artefacts") LiteLoaderBranch artifacts, + @SerializedName("snapshots") LiteLoaderBranch snapshots) { } diff --git a/HMCLCore/src/main/java/org/jackhuang/hmcl/download/liteloader/LiteLoaderRepository.java b/HMCLCore/src/main/java/org/jackhuang/hmcl/download/liteloader/LiteLoaderRepository.java index d3e836d3183..fda6679d64d 100644 --- a/HMCLCore/src/main/java/org/jackhuang/hmcl/download/liteloader/LiteLoaderRepository.java +++ b/HMCLCore/src/main/java/org/jackhuang/hmcl/download/liteloader/LiteLoaderRepository.java @@ -25,49 +25,13 @@ * @author huangyuhui */ @Immutable -public final class LiteLoaderRepository { - - @SerializedName("stream") - private final String stream; - - @SerializedName("type") - private final String type; - - @SerializedName("url") - private final String url; - - @SerializedName("classifier") - private final String classifier; - - /** - * No-arg constructor for Gson. - */ - @SuppressWarnings("unused") - public LiteLoaderRepository() { - this("", "", "", ""); - } - - public LiteLoaderRepository(String stream, String type, String url, String classifier) { - this.stream = stream; - this.type = type; - this.url = url; - this.classifier = classifier; - } - - public String getStream() { - return stream; - } - - public String getType() { - return type; - } - - public String getUrl() { - return url; - } - - public String getClassifier() { - return classifier; +public record LiteLoaderRepository(@SerializedName("stream") String stream, @SerializedName("type") String type, + @SerializedName("url") String url, @SerializedName("classifier") String classifier) { + + public LiteLoaderRepository { + if (stream == null) stream = ""; + if (type == null) type = ""; + if (url == null) url = ""; + if (classifier == null) classifier = ""; } - } diff --git a/HMCLCore/src/main/java/org/jackhuang/hmcl/download/liteloader/LiteLoaderVersion.java b/HMCLCore/src/main/java/org/jackhuang/hmcl/download/liteloader/LiteLoaderVersion.java index 653739ff6cf..6d82a1c3fef 100644 --- a/HMCLCore/src/main/java/org/jackhuang/hmcl/download/liteloader/LiteLoaderVersion.java +++ b/HMCLCore/src/main/java/org/jackhuang/hmcl/download/liteloader/LiteLoaderVersion.java @@ -28,59 +28,15 @@ * @author huangyuhui */ @Immutable -public final class LiteLoaderVersion { - private final String tweakClass; - private final String file; - private final String version; - private final String md5; - private final String timestamp; - private final int lastSuccessfulBuild; - private final Collection libraries; +public record LiteLoaderVersion(String tweakClass, String file, String version, String md5, String timestamp, + int lastSuccessfulBuild, Collection libraries) { - /** - * No-arg constructor for Gson. - */ - @SuppressWarnings("unused") - public LiteLoaderVersion() { - this("", "", "", "", "", 0, Collections.emptySet()); + public LiteLoaderVersion { + if (tweakClass == null) tweakClass = ""; + if (file == null) file = ""; + if (version == null) version = ""; + if (md5 == null) md5 = ""; + if (timestamp == null) timestamp = ""; + libraries = libraries == null ? Collections.emptySet() : Collections.unmodifiableCollection(libraries); } - - public LiteLoaderVersion(String tweakClass, String file, String version, String md5, String timestamp, int lastSuccessfulBuild, Collection libraries) { - this.tweakClass = tweakClass; - this.file = file; - this.version = version; - this.md5 = md5; - this.timestamp = timestamp; - this.lastSuccessfulBuild = lastSuccessfulBuild; - this.libraries = libraries; - } - - public String getTweakClass() { - return tweakClass; - } - - public String getFile() { - return file; - } - - public String getVersion() { - return version; - } - - public String getMd5() { - return md5; - } - - public String getTimestamp() { - return timestamp; - } - - public int getLastSuccessfulBuild() { - return lastSuccessfulBuild; - } - - public Collection getLibraries() { - return Collections.unmodifiableCollection(libraries); - } - } diff --git a/HMCLCore/src/main/java/org/jackhuang/hmcl/download/liteloader/LiteLoaderVersionList.java b/HMCLCore/src/main/java/org/jackhuang/hmcl/download/liteloader/LiteLoaderVersionList.java index dffb8cd2eb4..b9d93cb52b5 100644 --- a/HMCLCore/src/main/java/org/jackhuang/hmcl/download/liteloader/LiteLoaderVersionList.java +++ b/HMCLCore/src/main/java/org/jackhuang/hmcl/download/liteloader/LiteLoaderVersionList.java @@ -55,15 +55,15 @@ public Task refreshAsync(String gameVersion) { return new GetTask(downloadProvider.injectURLWithCandidates(LITELOADER_LIST)) .thenGetJsonAsync(LiteLoaderVersionsRoot.class) .thenAcceptAsync(root -> { - LiteLoaderGameVersions versions = root.getVersions().get(gameVersion); + LiteLoaderGameVersions versions = root.versions().get(gameVersion); if (versions == null) { return; } LiteLoaderRemoteVersion snapshot = null; - if (versions.getSnapshots() != null) { + if (versions.snapshots() != null) { try { - snapshot = loadSnapshotVersion(gameVersion, versions.getSnapshots().getLiteLoader().get("latest")); + snapshot = loadSnapshotVersion(gameVersion, versions.snapshots().liteLoader().get("latest")); } catch (IOException e) { throw new UncheckedIOException(e); } @@ -73,8 +73,8 @@ public Task refreshAsync(String gameVersion) { try { this.versions.clear(); - if (versions.getRepoitory() != null && versions.getArtifacts() != null) { - loadArtifactVersion(gameVersion, versions.getRepoitory(), versions.getArtifacts()); + if (versions.repoitory() != null && versions.artifacts() != null) { + loadArtifactVersion(gameVersion, versions.repoitory(), versions.artifacts()); } if (snapshot != null) { @@ -92,16 +92,16 @@ public Task refreshAsync() { } private void loadArtifactVersion(String gameVersion, LiteLoaderRepository repository, LiteLoaderBranch branch) { - for (Map.Entry entry : branch.getLiteLoader().entrySet()) { + for (Map.Entry entry : branch.liteLoader().entrySet()) { String branchName = entry.getKey(); LiteLoaderVersion v = entry.getValue(); if ("latest".equals(branchName)) continue; versions.put(gameVersion, new LiteLoaderRemoteVersion( - gameVersion, v.getVersion(), RemoteVersion.Type.RELEASE, - Collections.singletonList(repository.getUrl() + "com/mumfrey/liteloader/" + gameVersion + "/" + v.getFile()), - v.getTweakClass(), v.getLibraries() + gameVersion, v.version(), RemoteVersion.Type.RELEASE, + Collections.singletonList(repository.url() + "com/mumfrey/liteloader/" + gameVersion + "/" + v.file()), + v.tweakClass(), v.libraries() )); } } @@ -119,7 +119,7 @@ private LiteLoaderRemoteVersion loadSnapshotVersion(String gameVersion, LiteLoad return new LiteLoaderRemoteVersion( gameVersion, timestamp + "-" + buildNumber, RemoteVersion.Type.SNAPSHOT, Collections.singletonList(String.format(SNAPSHOT_FILE, gameVersion, gameVersion, timestamp, buildNumber)), - v.getTweakClass(), v.getLibraries() + v.tweakClass(), v.libraries() ); } } diff --git a/HMCLCore/src/main/java/org/jackhuang/hmcl/download/liteloader/LiteLoaderVersionsMeta.java b/HMCLCore/src/main/java/org/jackhuang/hmcl/download/liteloader/LiteLoaderVersionsMeta.java index b451942d6e2..e6c2b0eb639 100644 --- a/HMCLCore/src/main/java/org/jackhuang/hmcl/download/liteloader/LiteLoaderVersionsMeta.java +++ b/HMCLCore/src/main/java/org/jackhuang/hmcl/download/liteloader/LiteLoaderVersionsMeta.java @@ -25,37 +25,12 @@ * @author huangyuhui */ @Immutable -public final class LiteLoaderVersionsMeta { +public record LiteLoaderVersionsMeta(@SerializedName("description") String description, + @SerializedName("authors") String authors, @SerializedName("url") String url) { - @SerializedName("description") - private final String description; - - @SerializedName("authors") - private final String authors; - - @SerializedName("url") - private final String url; - - public LiteLoaderVersionsMeta() { - this("", "", ""); - } - - public LiteLoaderVersionsMeta(String description, String authors, String url) { - this.description = description; - this.authors = authors; - this.url = url; - } - - public String getDescription() { - return description; - } - - public String getAuthors() { - return authors; + public LiteLoaderVersionsMeta { + if (description == null) description = ""; + if (authors == null) authors = ""; + if (url == null) url = ""; } - - public String getUrl() { - return url; - } - } diff --git a/HMCLCore/src/main/java/org/jackhuang/hmcl/download/liteloader/LiteLoaderVersionsRoot.java b/HMCLCore/src/main/java/org/jackhuang/hmcl/download/liteloader/LiteLoaderVersionsRoot.java index 5f65a2f8e81..63549e14f71 100644 --- a/HMCLCore/src/main/java/org/jackhuang/hmcl/download/liteloader/LiteLoaderVersionsRoot.java +++ b/HMCLCore/src/main/java/org/jackhuang/hmcl/download/liteloader/LiteLoaderVersionsRoot.java @@ -19,6 +19,7 @@ import com.google.gson.annotations.SerializedName; import org.jackhuang.hmcl.util.Immutable; +import org.jetbrains.annotations.Nullable; import java.util.Collections; import java.util.Map; @@ -28,29 +29,10 @@ * @author huangyuhui */ @Immutable -public final class LiteLoaderVersionsRoot { +public record LiteLoaderVersionsRoot(@SerializedName("versions") Map versions, + @SerializedName("meta") @Nullable LiteLoaderVersionsMeta meta) { - @SerializedName("versions") - private final Map versions; - - @SerializedName("meta") - private final LiteLoaderVersionsMeta meta; - - public LiteLoaderVersionsRoot() { - this(Collections.emptyMap(), null); + public LiteLoaderVersionsRoot { + versions = versions == null ? Collections.emptyMap() : Collections.unmodifiableMap(versions); } - - public LiteLoaderVersionsRoot(Map versions, LiteLoaderVersionsMeta meta) { - this.versions = versions; - this.meta = meta; - } - - public Map getVersions() { - return Collections.unmodifiableMap(versions); - } - - public LiteLoaderVersionsMeta getMeta() { - return meta; - } - }