mirror of
https://github.com/CarmJos/EasyConfiguration.git
synced 2026-06-04 18:48:20 +08:00
feat(map): Add more builder functions
This commit is contained in:
@@ -3,10 +3,7 @@ package cc.carm.lib.configuration.builder.map;
|
|||||||
import cc.carm.lib.configuration.adapter.ValueType;
|
import cc.carm.lib.configuration.adapter.ValueType;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.*;
|
||||||
import java.util.LinkedHashMap;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.TreeMap;
|
|
||||||
import java.util.function.Supplier;
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
public class ConfigMapCreator<K, V> {
|
public class ConfigMapCreator<K, V> {
|
||||||
@@ -45,4 +42,8 @@ public class ConfigMapCreator<K, V> {
|
|||||||
return constructor(TreeMap::new);
|
return constructor(TreeMap::new);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public @NotNull ConfigMapBuilder<TreeMap<K, V>, K, V> asTreeMap(@NotNull Comparator<? super K> comparator) {
|
||||||
|
return constructor(() -> new TreeMap<>(comparator));
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -75,6 +75,10 @@ public class SectionMapBuilder<MAP extends Map<K, V>, K, V>
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public @NotNull SectionMapBuilder<MAP, K, V> defaults(@NotNull K key, @NotNull V value) {
|
||||||
|
return defaults(map -> map.put(key, value));
|
||||||
|
}
|
||||||
|
|
||||||
public @NotNull ValueAdapter<K> buildKeyAdapter() {
|
public @NotNull ValueAdapter<K> buildKeyAdapter() {
|
||||||
return new ValueAdapter<>(this.keyType)
|
return new ValueAdapter<>(this.keyType)
|
||||||
.parser((holder, type, data) -> {
|
.parser((holder, type, data) -> {
|
||||||
|
|||||||
@@ -53,6 +53,10 @@ public class SourceMapBuilder<MAP extends Map<K, V>, SOURCE, K, V>
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public @NotNull SourceMapBuilder<MAP, SOURCE, K, V> defaults(@NotNull K key, @NotNull V value) {
|
||||||
|
return defaults(map -> map.put(key, value));
|
||||||
|
}
|
||||||
|
|
||||||
public @NotNull SourceMapBuilder<MAP, SOURCE, K, V> parseKey(@NotNull DataFunction<String, K> keyParser) {
|
public @NotNull SourceMapBuilder<MAP, SOURCE, K, V> parseKey(@NotNull DataFunction<String, K> keyParser) {
|
||||||
return parseKey((holder, data) -> keyParser.handle(data));
|
return parseKey((holder, data) -> keyParser.handle(data));
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user