Class MapField<K,V> (3.19.4)

public class MapField<K,V> implements MutabilityOracle

Internal representation of map fields in generated messages.

This class supports accessing the map field as a Map to be used in generated API and also supports accessing the field as a List to be used in reflection API. It keeps track of where the data is currently stored and do necessary conversions between map and list.

This class is a protobuf implementation detail. Users shouldn't use this class directly.

THREAD-SAFETY NOTE: Read-only access is thread-safe. Users can call getMap() and getList() concurrently in multiple threads. If write-access is needed, all access must be synchronized.

Inheritance

Object > MapField<K,V>

Implements

com.google.protobuf.MutabilityOracle

Type Parameters

Name Description
K
V

Static Methods

<K,V>emptyMapField(MapEntry<K,V> defaultEntry)

public static MapField<K,V> <K,V>emptyMapField(MapEntry<K,V> defaultEntry)

Returns an immutable empty MapField.

Parameter
Name Description
defaultEntry MapEntry<K,V>
Returns
Type Description
MapField<K,V>

<K,V>newMapField(MapEntry<K,V> defaultEntry)

public static MapField<K,V> <K,V>newMapField(MapEntry<K,V> defaultEntry)

Creates a new mutable empty MapField.

Parameter
Name Description
defaultEntry MapEntry<K,V>
Returns
Type Description
MapField<K,V>

Methods

clear()

public void clear()

copy()

public MapField<K,V> copy()

Returns a deep copy of this MapField.

Returns
Type Description
MapField<K,V>

ensureMutable()

public void ensureMutable()

Throws an UnsupportedOperationException if not mutable.

equals(Object object)

public boolean equals(Object object)
Parameter
Name Description
object Object
Returns
Type Description
boolean
Overrides

getMap()

public Map<K,V> getMap()

Returns the content of this MapField as a read-only Map.

Returns
Type Description
Map<K,V>

getMutableMap()

public Map<K,V> getMutableMap()

Gets a mutable Map view of this MapField.

Returns
Type Description
Map<K,V>

hashCode()

public int hashCode()
Returns
Type Description
int
Overrides

isMutable()

public boolean isMutable()

Returns whether this field can be modified.

Returns
Type Description
boolean

makeImmutable()

public void makeImmutable()

Makes this list immutable. All subsequent modifications will throw an UnsupportedOperationException.

mergeFrom(MapField<K,V> other)

public void mergeFrom(MapField<K,V> other)
Parameter
Name Description
other MapField<K,V>