Convert Pair to record (#4485)

This commit is contained in:
Glavo 2025-09-15 15:31:17 +08:00 committed by GitHub
parent 7ce59cac2c
commit 15e490f313
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 6 additions and 54 deletions

View File

@ -22,6 +22,7 @@ import org.jackhuang.hmcl.auth.yggdrasil.GameProfile;
import org.jackhuang.hmcl.auth.yggdrasil.TextureModel;
import org.jackhuang.hmcl.util.KeyUtils;
import org.jackhuang.hmcl.util.Lang;
import org.jackhuang.hmcl.util.Pair;
import org.jackhuang.hmcl.util.gson.JsonUtils;
import org.jackhuang.hmcl.util.gson.UUIDTypeAdapter;
import org.jackhuang.hmcl.util.io.HttpServer;
@ -232,12 +233,7 @@ public class YggdrasilServer extends HttpServer {
// === properties ===
@SafeVarargs
public static List<?> properties(Map.Entry<String, String>... entries) {
return properties(false, entries);
}
@SafeVarargs
public static List<?> properties(boolean sign, Map.Entry<String, String>... entries) {
public static List<?> properties(boolean sign, Pair<String, String>... entries) {
return Stream.of(entries)
.map(entry -> {
LinkedHashMap<String, String> property = new LinkedHashMap<>();
@ -248,7 +244,6 @@ public class YggdrasilServer extends HttpServer {
}
return property;
})
.collect(Collectors.toList());
.toList();
}
}

View File

@ -17,70 +17,27 @@
*/
package org.jackhuang.hmcl.util;
import java.util.Map;
import java.util.Objects;
import org.jetbrains.annotations.NotNull;
/**
*
* @author huangyuhui
*/
public final class Pair<K, V> implements Map.Entry<K, V> {
public record Pair<K, V>(K key, V value) {
public static <K, V> Pair<K, V> pair(K key, V value) {
return new Pair<>(key, value);
}
private K key;
private V value;
private Pair(K key, V value) {
this.key = key;
this.value = value;
}
@Override
public K getKey() {
return key;
}
public void setKey(K key) {
this.key = key;
}
@Override
public V getValue() {
return value;
}
@Override
public V setValue(V value) {
V original = this.value;
this.value = value;
return original;
}
@Override
public int hashCode() {
int hash = 7;
hash = 23 * hash + Objects.hashCode(this.key);
hash = 23 * hash + Objects.hashCode(this.value);
return hash;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
final Pair<?, ?> other = (Pair<?, ?>) obj;
return Objects.equals(this.key, other.key) && Objects.equals(this.value, other.value);
}
@Override
public String toString() {
public @NotNull String toString() {
return "(" + key + ", " + value + ")";
}
}