Clean up
This commit is contained in:
parent
63659703b5
commit
8f4eef7999
|
@ -1,7 +1,6 @@
|
||||||
package io.gitlab.jfronny.globalization.mixin;
|
package io.gitlab.jfronny.globalization.mixin;
|
||||||
|
|
||||||
import com.google.common.collect.ImmutableMap;
|
import com.google.common.collect.ImmutableMap;
|
||||||
import io.gitlab.jfronny.globalization.DelegateHashMap;
|
|
||||||
import io.gitlab.jfronny.globalization.GlobalizationMap;
|
import io.gitlab.jfronny.globalization.GlobalizationMap;
|
||||||
import net.minecraft.client.resource.language.LanguageDefinition;
|
import net.minecraft.client.resource.language.LanguageDefinition;
|
||||||
import net.minecraft.client.resource.language.TranslationStorage;
|
import net.minecraft.client.resource.language.TranslationStorage;
|
||||||
|
@ -11,7 +10,8 @@ import org.spongepowered.asm.mixin.injection.*;
|
||||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||||
import org.spongepowered.asm.mixin.injection.callback.LocalCapture;
|
import org.spongepowered.asm.mixin.injection.callback.LocalCapture;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
@Mixin(TranslationStorage.class)
|
@Mixin(TranslationStorage.class)
|
||||||
public class TranslationStorageMixin {
|
public class TranslationStorageMixin {
|
||||||
|
|
|
@ -1,147 +0,0 @@
|
||||||
package io.gitlab.jfronny.globalization;
|
|
||||||
|
|
||||||
import java.util.*;
|
|
||||||
import java.util.function.*;
|
|
||||||
|
|
||||||
public class DelegateHashMap<M extends Map<K, V>, K, V> extends HashMap<K, V> {
|
|
||||||
private final M delegate;
|
|
||||||
|
|
||||||
public DelegateHashMap(M delegate) {
|
|
||||||
this.delegate = delegate;
|
|
||||||
}
|
|
||||||
|
|
||||||
public M getDelegate() {
|
|
||||||
if (!super.isEmpty()) throw new IllegalStateException("Something accesses this maps internal state");
|
|
||||||
return delegate;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int size() {
|
|
||||||
return delegate.size();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isEmpty() {
|
|
||||||
return delegate.isEmpty();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public V get(Object key) {
|
|
||||||
return delegate.get(key);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean containsKey(Object key) {
|
|
||||||
return delegate.containsKey(key);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public V put(K key, V value) {
|
|
||||||
return delegate.put(key, value);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void putAll(Map<? extends K, ? extends V> m) {
|
|
||||||
delegate.putAll(m);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public V remove(Object key) {
|
|
||||||
return delegate.remove(key);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void clear() {
|
|
||||||
delegate.clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean containsValue(Object value) {
|
|
||||||
return delegate.containsValue(value);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Set<K> keySet() {
|
|
||||||
return delegate.keySet();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Collection<V> values() {
|
|
||||||
return delegate.values();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Set<Entry<K, V>> entrySet() {
|
|
||||||
return delegate.entrySet();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public V getOrDefault(Object key, V defaultValue) {
|
|
||||||
return delegate.getOrDefault(key, defaultValue);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public V putIfAbsent(K key, V value) {
|
|
||||||
return delegate.putIfAbsent(key, value);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean remove(Object key, Object value) {
|
|
||||||
return delegate.remove(key, value);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean replace(K key, V oldValue, V newValue) {
|
|
||||||
return delegate.replace(key, oldValue, newValue);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public V replace(K key, V value) {
|
|
||||||
return delegate.replace(key, value);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public V computeIfAbsent(K key, Function<? super K, ? extends V> mappingFunction) {
|
|
||||||
return delegate.computeIfAbsent(key, mappingFunction);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public V computeIfPresent(K key, BiFunction<? super K, ? super V, ? extends V> remappingFunction) {
|
|
||||||
return delegate.computeIfPresent(key, remappingFunction);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public V compute(K key, BiFunction<? super K, ? super V, ? extends V> remappingFunction) {
|
|
||||||
return delegate.compute(key, remappingFunction);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public V merge(K key, V value, BiFunction<? super V, ? super V, ? extends V> remappingFunction) {
|
|
||||||
return delegate.merge(key, value, remappingFunction);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void forEach(BiConsumer<? super K, ? super V> action) {
|
|
||||||
delegate.forEach(action);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void replaceAll(BiFunction<? super K, ? super V, ? extends V> function) {
|
|
||||||
delegate.replaceAll(function);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean equals(Object o) {
|
|
||||||
return delegate.equals(o);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int hashCode() {
|
|
||||||
return delegate.hashCode();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return delegate.toString();
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,12 +1,7 @@
|
||||||
package io.gitlab.jfronny.globalization;
|
package io.gitlab.jfronny.globalization;
|
||||||
|
|
||||||
import io.gitlab.jfronny.commons.log.Logger;
|
import io.gitlab.jfronny.commons.log.Logger;
|
||||||
import net.fabricmc.api.ModInitializer;
|
|
||||||
|
|
||||||
public class Globalization implements ModInitializer {
|
public class Globalization {
|
||||||
public static final Logger LOG = Logger.forName("globalization");
|
public static final Logger LOG = Logger.forName("globalization");
|
||||||
@Override
|
|
||||||
public void onInitialize() {
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,7 +32,7 @@ public class GlobalizationMap extends AbstractMap<String, String> {
|
||||||
.map(Map::entrySet)
|
.map(Map::entrySet)
|
||||||
.flatMap(Collection::stream)
|
.flatMap(Collection::stream)
|
||||||
.filter(s -> !target.containsKey(s.getKey()))
|
.filter(s -> !target.containsKey(s.getKey()))
|
||||||
.collect(Collectors.toMap(Entry::getKey, Entry::getValue));
|
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
|
||||||
Properties cache = new Properties();
|
Properties cache = new Properties();
|
||||||
T targetLang = service.parseLang(GlobalizationConfig.targetCode);
|
T targetLang = service.parseLang(GlobalizationConfig.targetCode);
|
||||||
Path cacheFile = targetPath.resolve(targetLang.getIdentifier() + ".cache");
|
Path cacheFile = targetPath.resolve(targetLang.getIdentifier() + ".cache");
|
||||||
|
@ -89,17 +89,40 @@ public class GlobalizationMap extends AbstractMap<String, String> {
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
public Set<Entry<String, String>> entrySet() {
|
public Set<Map.Entry<String, String>> entrySet() {
|
||||||
return pools.stream()
|
return pools.stream()
|
||||||
.map(Map::entrySet)
|
.map(Map::entrySet)
|
||||||
.flatMap(Collection::stream)
|
.flatMap(Collection::stream)
|
||||||
.collect(Collectors.groupingBy(Entry::getKey, Collectors.toList()))
|
.collect(Collectors.groupingBy(Map.Entry::getKey, Collectors.toList()))
|
||||||
.entrySet()
|
.entrySet()
|
||||||
.stream()
|
.stream()
|
||||||
.map(s -> new MapEntry<>(s.getKey(), s.getValue().get(s.getValue().size() - 1).getValue()))
|
.map(s -> new Entry<>(s.getKey(), s.getValue().get(s.getValue().size() - 1).getValue()))
|
||||||
.collect(Collectors.toUnmodifiableSet());
|
.collect(Collectors.toUnmodifiableSet());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public record Entry<K, V>(K key, V value) implements Map.Entry<K, V> {
|
||||||
|
@Override
|
||||||
|
public K getKey() {
|
||||||
|
return key;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public V getValue() {
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public V setValue(V v) {
|
||||||
|
throw new UnsupportedOperationException();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
@Override
|
||||||
|
public Set<String> keySet() {
|
||||||
|
return pools.stream().flatMap(s -> s.keySet().stream()).collect(Collectors.toUnmodifiableSet());
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isEmpty() {
|
public boolean isEmpty() {
|
||||||
return pools.isEmpty() || (pools.size() == 1 && pools.get(0).isEmpty());
|
return pools.isEmpty() || (pools.size() == 1 && pools.get(0).isEmpty());
|
||||||
|
@ -129,10 +152,4 @@ public class GlobalizationMap extends AbstractMap<String, String> {
|
||||||
public void clear() {
|
public void clear() {
|
||||||
throw new UnsupportedOperationException();
|
throw new UnsupportedOperationException();
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
|
||||||
@Override
|
|
||||||
public Set<String> keySet() {
|
|
||||||
return pools.stream().flatMap(s -> s.keySet().stream()).collect(Collectors.toUnmodifiableSet());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,20 +0,0 @@
|
||||||
package io.gitlab.jfronny.globalization;
|
|
||||||
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
public record MapEntry<K, V>(K key, V value) implements Map.Entry<K, V> {
|
|
||||||
@Override
|
|
||||||
public K getKey() {
|
|
||||||
return key;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public V getValue() {
|
|
||||||
return value;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public V setValue(V v) {
|
|
||||||
throw new UnsupportedOperationException();
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -15,8 +15,7 @@
|
||||||
"icon": "assets/globalization/icon.png",
|
"icon": "assets/globalization/icon.png",
|
||||||
"environment": "client",
|
"environment": "client",
|
||||||
"entrypoints": {
|
"entrypoints": {
|
||||||
"libjf:config": ["io.gitlab.jfronny.globalization.JFC_GlobalizationConfig"],
|
"libjf:config": ["io.gitlab.jfronny.globalization.JFC_GlobalizationConfig"]
|
||||||
"main": ["io.gitlab.jfronny.globalization.Globalization"]
|
|
||||||
},
|
},
|
||||||
"mixins": [
|
"mixins": [
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue
Block a user