public class MapField<K,V> extends java.lang.Object implements MutabilityOracle
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.Modifier and Type | Class and Description |
---|---|
private static interface |
MapField.Converter<K,V> |
private static class |
MapField.ImmutableMessageConverter<K,V> |
private static class |
MapField.MutatabilityAwareMap<K,V>
An internal map that checks for mutability before delegating.
|
private static class |
MapField.StorageMode
Indicates where the data of this map field is currently stored.
|
Modifier and Type | Field and Description |
---|---|
private MapField.Converter<K,V> |
converter |
private boolean |
isMutable |
private java.util.List<Message> |
listData |
private MapField.MutatabilityAwareMap<K,V> |
mapData |
private MapField.StorageMode |
mode |
IMMUTABLE
Modifier | Constructor and Description |
---|---|
private |
MapField(MapEntry<K,V> defaultEntry,
MapField.StorageMode mode,
java.util.Map<K,V> mapData) |
private |
MapField(MapField.Converter<K,V> converter,
MapField.StorageMode mode,
java.util.Map<K,V> mapData) |
Modifier and Type | Method and Description |
---|---|
void |
clear() |
private Message |
convertKeyAndValueToMessage(K key,
V value) |
private MapField.MutatabilityAwareMap<K,V> |
convertListToMap(java.util.List<Message> listData) |
private java.util.List<Message> |
convertMapToList(MapField.MutatabilityAwareMap<K,V> mapData) |
private void |
convertMessageToKeyAndValue(Message message,
java.util.Map<K,V> map) |
MapField<K,V> |
copy()
Returns a deep copy of this MapField.
|
static <K,V> MapField<K,V> |
emptyMapField(MapEntry<K,V> defaultEntry)
Returns an immutable empty MapField.
|
void |
ensureMutable()
Throws an
UnsupportedOperationException if not mutable. |
boolean |
equals(java.lang.Object object) |
(package private) java.util.List<Message> |
getList()
Gets the content of this MapField as a read-only List.
|
java.util.Map<K,V> |
getMap()
Returns the content of this MapField as a read-only Map.
|
(package private) Message |
getMapEntryMessageDefaultInstance()
Gets the default instance of the message stored in the list view of this
map field.
|
(package private) java.util.List<Message> |
getMutableList()
Gets a mutable List view of this MapField.
|
java.util.Map<K,V> |
getMutableMap()
Gets a mutable Map view of this MapField.
|
int |
hashCode() |
boolean |
isMutable()
Returns whether this field can be modified.
|
void |
makeImmutable()
Makes this list immutable.
|
void |
mergeFrom(MapField<K,V> other) |
static <K,V> MapField<K,V> |
newMapField(MapEntry<K,V> defaultEntry)
Creates a new mutable empty MapField.
|
private volatile boolean isMutable
private volatile MapField.StorageMode mode
private MapField.MutatabilityAwareMap<K,V> mapData
private java.util.List<Message> listData
private final MapField.Converter<K,V> converter
private MapField(MapField.Converter<K,V> converter, MapField.StorageMode mode, java.util.Map<K,V> mapData)
public static <K,V> MapField<K,V> emptyMapField(MapEntry<K,V> defaultEntry)
public static <K,V> MapField<K,V> newMapField(MapEntry<K,V> defaultEntry)
private void convertMessageToKeyAndValue(Message message, java.util.Map<K,V> map)
private java.util.List<Message> convertMapToList(MapField.MutatabilityAwareMap<K,V> mapData)
private MapField.MutatabilityAwareMap<K,V> convertListToMap(java.util.List<Message> listData)
public void clear()
public boolean equals(java.lang.Object object)
equals
in class java.lang.Object
public int hashCode()
hashCode
in class java.lang.Object
java.util.List<Message> getList()
java.util.List<Message> getMutableList()
Message getMapEntryMessageDefaultInstance()
public void makeImmutable()
UnsupportedOperationException
.public boolean isMutable()
public void ensureMutable()
MutabilityOracle
UnsupportedOperationException
if not mutable.ensureMutable
in interface MutabilityOracle