Skip to content

Commit

Permalink
Code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
burningtnt committed Dec 6, 2023
1 parent b340a65 commit cea733e
Showing 1 changed file with 6 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.function.BiFunction;
import java.util.function.BiConsumer;
import java.util.logging.Level;

import static org.jackhuang.hmcl.util.Lang.tryCast;
Expand Down Expand Up @@ -56,9 +56,10 @@ static void upgradeConfig(Config deserialized, Map<?, ?> rawJson) {

LOG.log(Level.INFO, String.format("Updating configuration from %d to %d.", configVersion, CURRENT_VERSION));
Map<?, ?> unmodifiableRawJson = Collections.unmodifiableMap(rawJson);
for (Map.Entry<Integer, BiFunction<Config, Map<?, ?>, Integer>> dfu : collectDFU()) {
for (Map.Entry<Integer, BiConsumer<Config, Map<?, ?>>> dfu : collectDFU()) {
if (configVersion < dfu.getKey()) {
configVersion = dfu.getValue().apply(deserialized, unmodifiableRawJson);
dfu.getValue().accept(deserialized, unmodifiableRawJson);
configVersion = dfu.getKey();
}
}

Expand All @@ -75,8 +76,8 @@ static void upgradeConfig(Config deserialized, Map<?, ?> rawJson) {
*
* <p>The last item must return CURRENT_VERSION, as the config file should always being updated to the latest version.</p>
*/
private static List<Map.Entry<Integer, BiFunction<Config, Map<?, ?>, Integer>>> collectDFU() {
List<Map.Entry<Integer, BiFunction<Config, Map<?, ?>, Integer>>> dfu = Lang.immutableListOf(
private static List<Map.Entry<Integer, BiConsumer<Config, Map<?, ?>>>> collectDFU() {
List<Map.Entry<Integer, BiConsumer<Config, Map<?, ?>>>> dfu = Lang.immutableListOf(
Pair.pair(1, (deserialized, rawJson) -> {
// Upgrade configuration of HMCL 2.x: Convert OfflineAccounts whose stored uuid is important.
tryCast(rawJson.get("auth"), Map.class).ifPresent(auth -> {
Expand Down Expand Up @@ -120,7 +121,6 @@ static void upgradeConfig(Config deserialized, Map<?, ?> rawJson) {
}
});
}
return 1;
})
);

Expand Down

0 comments on commit cea733e

Please sign in to comment.