mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2025-07-04 00:45:57 +00:00
Use generic key mapping function
This commit is contained in:
parent
8670c4cdf3
commit
4fdef98bd9
@ -17,6 +17,7 @@ public class DefinedBiomeColorMappingTemplate implements ObjectTemplate<ColorMap
|
||||
|
||||
@Override
|
||||
public ColorMapping<Biome> get() {
|
||||
return () -> MapUtil.convertKeysToInt(map);
|
||||
var map = MapUtil.mapKeys(this.map, Integer::decode);
|
||||
return () -> map;
|
||||
}
|
||||
}
|
||||
|
@ -2,6 +2,7 @@ package com.dfsek.terra.addons.image.util;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
|
||||
@ -10,14 +11,15 @@ public class MapUtil {
|
||||
private MapUtil() {}
|
||||
|
||||
/**
|
||||
* Utility method for converting config keys into integers,
|
||||
* used because Tectonic does not accept non string keys.
|
||||
* Utility method for applying transformations on a map's keys.
|
||||
*/
|
||||
public static <T> Map<Integer, T> convertKeysToInt(Map<String, T> map) {
|
||||
return map.entrySet().stream()
|
||||
.collect(Collectors.toMap(
|
||||
e -> Integer.decode(e.getKey()),
|
||||
Entry::getValue
|
||||
));
|
||||
public static <O, N, T> Map<N, T> mapKeys(Map<O, T> map, Function<O, N> mappingFunction) {
|
||||
return map
|
||||
.entrySet()
|
||||
.stream()
|
||||
.collect(Collectors.toMap(
|
||||
e -> mappingFunction.apply(e.getKey()),
|
||||
Entry::getValue
|
||||
));
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user