mirror of
https://github.com/HMCL-dev/HMCL.git
synced 2025-09-22 18:51:46 -04:00
Convert Pair to record (#4485)
This commit is contained in:
parent
7ce59cac2c
commit
15e490f313
@ -22,6 +22,7 @@ import org.jackhuang.hmcl.auth.yggdrasil.GameProfile;
|
|||||||
import org.jackhuang.hmcl.auth.yggdrasil.TextureModel;
|
import org.jackhuang.hmcl.auth.yggdrasil.TextureModel;
|
||||||
import org.jackhuang.hmcl.util.KeyUtils;
|
import org.jackhuang.hmcl.util.KeyUtils;
|
||||||
import org.jackhuang.hmcl.util.Lang;
|
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.JsonUtils;
|
||||||
import org.jackhuang.hmcl.util.gson.UUIDTypeAdapter;
|
import org.jackhuang.hmcl.util.gson.UUIDTypeAdapter;
|
||||||
import org.jackhuang.hmcl.util.io.HttpServer;
|
import org.jackhuang.hmcl.util.io.HttpServer;
|
||||||
@ -232,12 +233,7 @@ public class YggdrasilServer extends HttpServer {
|
|||||||
// === properties ===
|
// === properties ===
|
||||||
|
|
||||||
@SafeVarargs
|
@SafeVarargs
|
||||||
public static List<?> properties(Map.Entry<String, String>... entries) {
|
public static List<?> properties(boolean sign, Pair<String, String>... entries) {
|
||||||
return properties(false, entries);
|
|
||||||
}
|
|
||||||
|
|
||||||
@SafeVarargs
|
|
||||||
public static List<?> properties(boolean sign, Map.Entry<String, String>... entries) {
|
|
||||||
return Stream.of(entries)
|
return Stream.of(entries)
|
||||||
.map(entry -> {
|
.map(entry -> {
|
||||||
LinkedHashMap<String, String> property = new LinkedHashMap<>();
|
LinkedHashMap<String, String> property = new LinkedHashMap<>();
|
||||||
@ -248,7 +244,6 @@ public class YggdrasilServer extends HttpServer {
|
|||||||
}
|
}
|
||||||
return property;
|
return property;
|
||||||
})
|
})
|
||||||
.collect(Collectors.toList());
|
.toList();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -17,70 +17,27 @@
|
|||||||
*/
|
*/
|
||||||
package org.jackhuang.hmcl.util;
|
package org.jackhuang.hmcl.util;
|
||||||
|
|
||||||
import java.util.Map;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import java.util.Objects;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
|
||||||
* @author huangyuhui
|
* @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) {
|
public static <K, V> Pair<K, V> pair(K key, V value) {
|
||||||
return new Pair<>(key, 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() {
|
public K getKey() {
|
||||||
return key;
|
return key;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setKey(K key) {
|
|
||||||
this.key = key;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public V getValue() {
|
public V getValue() {
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public V setValue(V value) {
|
public @NotNull String toString() {
|
||||||
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() {
|
|
||||||
return "(" + key + ", " + value + ")";
|
return "(" + key + ", " + value + ")";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user