refac: переосмысление
This commit is contained in:
39
src/main/java/mc/nbt/codec/CodecRegistry.java
Normal file
39
src/main/java/mc/nbt/codec/CodecRegistry.java
Normal file
@@ -0,0 +1,39 @@
|
||||
package mc.nbt.codec;
|
||||
|
||||
import mc.nbt.TagType;
|
||||
import mc.nbt.TagValue;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
||||
public class CodecRegistry {
|
||||
private static final CodecRegistry INSTANCE = new CodecRegistry();
|
||||
|
||||
private final Map<TagType, Codec<? extends TagValue>> codecs;
|
||||
|
||||
private CodecRegistry() {
|
||||
codecs = Map.ofEntries(
|
||||
Map.entry(TagType.BYTE, new ByteTagCodec()),
|
||||
Map.entry(TagType.SHORT, new ShortTagCodec()),
|
||||
Map.entry(TagType.INTEGER, new IntegerTagCodec()),
|
||||
Map.entry(TagType.LONG, new LongTagCodec()),
|
||||
Map.entry(TagType.FLOAT, new FloatTagCodec()),
|
||||
Map.entry(TagType.DOUBLE, new DoubleTagCodec()),
|
||||
Map.entry(TagType.BYTE_ARRAY, new ByteArrayTagCodec()),
|
||||
Map.entry(TagType.INTEGER_ARRAY, new IntegerArrayTagCodec()),
|
||||
Map.entry(TagType.LONG_ARRAY, new LongArrayTagCodec()),
|
||||
Map.entry(TagType.STRING, new StringTagCodec()),
|
||||
Map.entry(TagType.LIST, new ListTagCodec()),
|
||||
Map.entry(TagType.COMPOUND, new CompoundTagCodec()),
|
||||
Map.entry(TagType.END, new EndTagCodec())
|
||||
);
|
||||
}
|
||||
|
||||
public Codec<? extends TagValue> get(TagType tagType) {
|
||||
return codecs.get(Objects.requireNonNull(tagType));
|
||||
}
|
||||
|
||||
public static CodecRegistry getInstance() {
|
||||
return INSTANCE;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user