com.google.cloud.dataflow.sdk.coders

## Class MapCoder<K,V>

- java.lang.Object
- - com.google.cloud.dataflow.sdk.coders.StandardCoder<T>
  - - com.google.cloud.dataflow.sdk.coders.MapCoderBase<Map<K,V>>
    - - com.google.cloud.dataflow.sdk.coders.MapCoder<K,V>

Type Parameters:
  `K` - the type of the keys of the KVs being transcoded
  `V` - the type of the values of the KVs being transcoded

All Implemented Interfaces:
  Coder<Map<K,V>>, Serializable

    public class MapCoder<K,V>
    extends MapCoderBase<Map<K,V>>

A `Coder` for `Maps` that encodes them according to provided coders for keys and values.

See Also:
  Serialized Form

### Nested Class Summary

### Nested classes/interfaces inherited from interface com.google.cloud.dataflow.sdk.coders.Coder

`Coder.Context, Coder.NonDeterministicException`

### Method Summary

All Methods Static Methods Instance Methods Concrete Methods
`Map<K,V>` `decode(InputStream inStream, Coder.Context context)` Decodes a value of type `T` from the given input stream in the given context.
`void` `encode(Map<K,V> map, OutputStream outStream, Coder.Context context)` Encodes the given value of type `T` onto the given output stream in the given context.
`List<? extends Coder<?>>` `getCoderArguments()` If this is a `Coder` for a parameterized type, returns the list of `Coder`s being used for each of the parameters, or returns `null` if this cannot be done or this is not a parameterized type.
`static <K,V> List<Object>` `getInstanceComponents(Map<K,V> exampleValue)` Returns the key and value for an arbitrary element of this map, if it is non-empty, otherwise returns `null`.
`Coder<K>` `getKeyCoder()`
`Coder<V>` `getValueCoder()`
`static <K,V> MapCoder<K,V>` `of(Coder<K> keyCoder, Coder<V> valueCoder)` Produces a MapCoder with the given keyCoder and valueCoder.
`static MapCoder<?,?>` `of(List<Coder<?>> components)`
`void` `registerByteSizeObserver(Map<K,V> map, com.google.cloud.dataflow.sdk.util.common.ElementByteSizeObserver observer, Coder.Context context)` Notifies the `ElementByteSizeObserver` about the byte size of the encoded value using this `Coder`.
`void` `verifyDeterministic()` Throw `Coder.NonDeterministicException` if the coding is not deterministic.

### Methods inherited from class com.google.cloud.dataflow.sdk.coders.MapCoderBase

`of`

### Methods inherited from class com.google.cloud.dataflow.sdk.coders.StandardCoder

`asCloudObject, consistentWithEquals, equals, getAllowedEncodings, getComponents, getEncodedElementByteSize, getEncodingId, hashCode, isRegisterByteSizeObserverCheap, structuralValue, toString, verifyDeterministic, verifyDeterministic`

### Methods inherited from class java.lang.Object

`clone, finalize, getClass, notify, notifyAll, wait, wait, wait`

### Method Detail

#### of

    public static <K,V> MapCoder<K,V> of(Coder<K> keyCoder,
                                         Coder<V> valueCoder)

Produces a MapCoder with the given keyCoder and valueCoder.

#### of

    public static MapCoder<?,?> of(List<Coder<?>> components)

#### getInstanceComponents

    public static <K,V> List<Object> getInstanceComponents(Map<K,V> exampleValue)

Returns the key and value for an arbitrary element of this map, if it is non-empty, otherwise returns `null`.

#### getKeyCoder

    public Coder<K> getKeyCoder()

#### getValueCoder

    public Coder<V> getValueCoder()

#### encode

    public void encode(Map<K,V> map,
                       OutputStream outStream,
                       Coder.Context context)
                throws IOException,
                       CoderException

Description copied from interface: `Coder`
Encodes the given value of type `T` onto the given output stream in the given context.

Throws:
  `IOException` - if writing to the `OutputStream` fails for some reason
  `CoderException` - if the value could not be encoded for some reason

#### decode

    public Map<K,V> decode(InputStream inStream,
                           Coder.Context context)
                    throws IOException,
                           CoderException

Description copied from interface: `Coder`
Decodes a value of type `T` from the given input stream in the given context. Returns the decoded value.

Throws:
  `IOException` - if reading from the `InputStream` fails for some reason
  `CoderException` - if the value could not be decoded for some reason

#### getCoderArguments

    public List<? extends Coder<?>> getCoderArguments()

If this is a `Coder` for a parameterized type, returns the list of `Coder`s being used for each of the parameters, or returns `null` if this cannot be done or this is not a parameterized type.

Returns:
  a `List` containing the key coder at index 0 at the and value coder at index 1.

#### verifyDeterministic

    public void verifyDeterministic()
                             throws Coder.NonDeterministicException

Throw `Coder.NonDeterministicException` if the coding is not deterministic.

In order for a `Coder` to be considered deterministic, the following must be true:

- two values that compare as equal (via `Object.equals()` or `Comparable.compareTo()`, if supported) have the same encoding.
- the `Coder` always produces a canonical encoding, which is the same for an instance of an object even if produced on different computers at different times.

Throws:
  `NonDeterministicException` - always. Not all maps have a deterministic encoding. For example, `HashMap` comparison does not depend on element order, so two `HashMap` instances may be equal but produce different encodings.
  `Coder.NonDeterministicException` - if this coder is not deterministic.

#### registerByteSizeObserver

    public void registerByteSizeObserver(Map<K,V> map,
                                         com.google.cloud.dataflow.sdk.util.common.ElementByteSizeObserver observer,
                                         Coder.Context context)
                                  throws Exception

Description copied from class: `StandardCoder`
Notifies the `ElementByteSizeObserver` about the byte size of the encoded value using this `Coder`.

Not intended to be called by user code, but instead by `PipelineRunner` implementations.

For `StandardCoder` subclasses, this notifies `observer` about the byte size of the encoded value using this coder as returned by `StandardCoder.getEncodedElementByteSize(T, com.google.cloud.dataflow.sdk.coders.Coder.Context)`.

Specified by:
  `registerByteSizeObserver` in interface `Coder<Map<K,V>>`
Overrides:
  `registerByteSizeObserver` in class `StandardCoder<Map<K,V>>`
Throws:
  `Exception`