Class MapCodec<K,V>

java.lang.Object
dev.siroshun.codec4j.api.codec.collection.MapCodec<K,V>
Type Parameters:
K - the type of the key
V - the type of the value
All Implemented Interfaces:
Codec<Map<K,V>>, Decoder<Map<K,V>>, Encoder<Map<K,V>>

public final class MapCodec<K,V> extends Object implements Codec<Map<K,V>>
A Codec for Map.
  • Method Details

    • map

      @Contract("_, _ -> new") @NotNull public static <K, V> @NotNull MapCodec<K,V> map(@NotNull @NotNull Codec<K> keyCodec, @NotNull @NotNull Codec<V> valueCodec)
      Creates a MapCodec with the specified key and value Codec.
      Type Parameters:
      K - the type of the key
      V - the type of the value
      Parameters:
      keyCodec - the Codec for keys
      valueCodec - the Codec for values
      Returns:
      a MapCodec
    • map

      @Contract("_, _, _, _, _ -> new") @NotNull public static <K, V> @NotNull MapCodec<K,V> map(@NotNull @NotNull Codec<K> keyCodec, @NotNull @NotNull Codec<V> valueCodec, @NotNull @NotNull Supplier<Map<K,V>> factory, boolean allowDuplicatedKey, @NotNull @NotNull UnaryOperator<Map<K,V>> finalizer)
      Creates a MapCodec with the specified key and value Codec, the custom Map factory, and other options.
      Type Parameters:
      K - the type of the key
      V - the type of the value
      Parameters:
      keyCodec - the Codec for keys
      valueCodec - the Codec for values
      factory - the custom Map factory
      allowDuplicatedKey - whether to allow duplicated keys
      finalizer - the custom Map finalizer
      Returns:
      a MapCodec
    • create

      @Contract("_ -> new") @NotNull public static <K, V> @NotNull MapCodec<K,V> create(@NotNull @NotNull EntryProcessor<K,V,Map.Entry<K,V>,Map<K,V>> processor)
      Creates a MapCodec with the specified EntryProcessor.
      Type Parameters:
      K - the type of the key
      V - the type of the value
      Parameters:
      processor - the EntryProcessor
      Returns:
      a MapCodec
    • decode

      @NotNull public @NotNull dev.siroshun.jfun.result.Result<Map<K,V>,DecodeError> decode(@NotNull @NotNull In in)
      Description copied from interface: Decoder
      Decodes the data from the provided In.
      Specified by:
      decode in interface Decoder<K>
      Parameters:
      in - the In for reading the data to decode
      Returns:
      a result containing the decoded data, or a DecodeError if the operation failed
    • encode

      @NotNull public <O> @NotNull dev.siroshun.jfun.result.Result<O,EncodeError> encode(@NotNull @NotNull Out<O> out, @UnknownNullability Map<K,V> input)
      Description copied from interface: Encoder
      Encodes the data from the provided Encoder to the provided Out.
      Specified by:
      encode in interface Encoder<K>
      Type Parameters:
      O - the type of the output destination
      Parameters:
      out - the Out for writing the encoded data
      input - the input data to encode
      Returns:
      a result containing the encoded data, or a EncodeError if the operation failed