Package com.google.protobuf
Class MapField<K,V>
java.lang.Object
com.google.protobuf.MapFieldReflectionAccessor
com.google.protobuf.MapField<K,V>
- All Implemented Interfaces:
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.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static interfaceprivate static class(package private) static classAn internal map that checks for mutability before delegating.private static enumIndicates where the data of this map field is currently stored. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final MapField.Converter<K,V> private booleanprivate MapField.MutabilityAwareMap<K,V> private MapField.StorageModeFields inherited from interface com.google.protobuf.MutabilityOracle
IMMUTABLE -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidclear()private MessageconvertKeyAndValueToMessage(K key, V value) private MapField.MutabilityAwareMap<K,V> convertListToMap(List<Message> listData) convertMapToList(MapField.MutabilityAwareMap<K, V> mapData) private voidconvertMessageToKeyAndValue(Message message, Map<K, V> map) copy()Returns a deep copy of this MapField.static <K,V> MapField<K, V> emptyMapField(MapEntry<K, V> defaultEntry) Returns an immutable empty MapField.voidThrows anUnsupportedOperationExceptionif not mutable.booleangetList()Gets the content of this MapField as a read-only List.getMap()Returns the content of this MapField as a read-only Map.(package private) MessageGets the default instance of the message stored in the list view of this map field.Gets a mutable List view of this MapField.Gets a mutable Map view of this MapField.inthashCode()booleanReturns whether this field can be modified.voidMakes this list immutable.voidstatic <K,V> MapField<K, V> newMapField(MapEntry<K, V> defaultEntry) Creates a new mutable empty MapField.
-
Field Details
-
isMutable
private volatile boolean isMutable -
mode
-
mapData
-
listData
-
converter
-
-
Constructor Details
-
MapField
-
MapField
-
-
Method Details
-
emptyMapField
Returns an immutable empty MapField. -
newMapField
Creates a new mutable empty MapField. -
convertKeyAndValueToMessage
-
convertMessageToKeyAndValue
-
convertMapToList
-
convertListToMap
-
getMap
Returns the content of this MapField as a read-only Map. -
getMutableMap
Gets a mutable Map view of this MapField. -
mergeFrom
-
clear
public void clear() -
equals
-
hashCode
public int hashCode() -
copy
Returns a deep copy of this MapField. -
getList
Gets the content of this MapField as a read-only List.- Specified by:
getListin classMapFieldReflectionAccessor
-
getMutableList
Gets a mutable List view of this MapField.- Specified by:
getMutableListin classMapFieldReflectionAccessor
-
getMapEntryMessageDefaultInstance
Message getMapEntryMessageDefaultInstance()Gets the default instance of the message stored in the list view of this map field.- Specified by:
getMapEntryMessageDefaultInstancein classMapFieldReflectionAccessor
-
makeImmutable
public void makeImmutable()Makes this list immutable. All subsequent modifications will throw anUnsupportedOperationException. -
isMutable
public boolean isMutable()Returns whether this field can be modified. -
ensureMutable
public void ensureMutable()Description copied from interface:MutabilityOracleThrows anUnsupportedOperationExceptionif not mutable.- Specified by:
ensureMutablein interfaceMutabilityOracle
-