Class GeneratedMessageV3.Builder<BuilderType>

Stay organized with collections Save and categorize content based on your preferences.
public abstract static class GeneratedMessageV3.Builder<BuilderType> extends AbstractMessage.Builder<BuilderType>

Inheritance

Object > AbstractMessageLite.Builder<MessageType,BuilderType> > AbstractMessage.Builder > GeneratedMessageV3.Builder<BuilderType>

Type Parameter

NameDescription
BuilderType

Constructors

Builder()

protected Builder()

Builder(GeneratedMessageV3.BuilderParent builderParent)

protected Builder(GeneratedMessageV3.BuilderParent builderParent)
Parameter
NameDescription
builderParentGeneratedMessageV3.BuilderParent

Methods

addRepeatedField(Descriptors.FieldDescriptor field, Object value)

public BuilderType addRepeatedField(Descriptors.FieldDescriptor field, Object value)
Parameters
NameDescription
fieldDescriptors.FieldDescriptor
valueObject
Returns
TypeDescription
BuilderType

clear()

public BuilderType clear()

Called by the initialization and clear code paths to allow subclasses to reset any of their builtin fields back to the initial values.

Returns
TypeDescription
BuilderType
Overrides

clearField(Descriptors.FieldDescriptor field)

public BuilderType clearField(Descriptors.FieldDescriptor field)
Parameter
NameDescription
fieldDescriptors.FieldDescriptor
Returns
TypeDescription
BuilderType

clearOneof(Descriptors.OneofDescriptor oneof)

public BuilderType clearOneof(Descriptors.OneofDescriptor oneof)

TODO(jieluo): Clear it when all subclasses have implemented this method.

Parameter
NameDescription
oneofDescriptors.OneofDescriptor
Returns
TypeDescription
BuilderType
Overrides

clone()

public BuilderType clone()

Clones the Builder.

Returns
TypeDescription
BuilderType
Overrides

getAllFields()

public Map<Descriptors.FieldDescriptor,Object> getAllFields()
Returns
TypeDescription
Map<FieldDescriptor,Object>

getDescriptorForType()

public Descriptors.Descriptor getDescriptorForType()
Returns
TypeDescription
Descriptors.Descriptor

getField(Descriptors.FieldDescriptor field)

public Object getField(Descriptors.FieldDescriptor field)
Parameter
NameDescription
fieldDescriptors.FieldDescriptor
Returns
TypeDescription
Object

getFieldBuilder(Descriptors.FieldDescriptor field)

public Message.Builder getFieldBuilder(Descriptors.FieldDescriptor field)

Get a nested builder instance for the given field.

Normally, we hold a reference to the immutable message object for the message type field. Some implementations(the generated message builders), however, can also hold a reference to the builder object (a nested builder) for the field.

If the field is already backed up by a nested builder, the nested builder will be returned. Otherwise, a new field builder will be created and returned. The original message field (if exist) will be merged into the field builder, which will then be nested into its parent builder.

NOTE: implementations that do not support nested builders will throw UnsupportedOperationException.

Parameter
NameDescription
fieldDescriptors.FieldDescriptor
Returns
TypeDescription
Message.Builder
Overrides

getOneofFieldDescriptor(Descriptors.OneofDescriptor oneof)

public Descriptors.FieldDescriptor getOneofFieldDescriptor(Descriptors.OneofDescriptor oneof)

TODO(jieluo): Clear it when all subclasses have implemented this method.

Parameter
NameDescription
oneofDescriptors.OneofDescriptor
Returns
TypeDescription
Descriptors.FieldDescriptor
Overrides

getParentForChildren()

protected GeneratedMessageV3.BuilderParent getParentForChildren()

Gets the BuilderParent for giving to our children.

Returns
TypeDescription
GeneratedMessageV3.BuilderParent

The builder parent for our children.

getRepeatedField(Descriptors.FieldDescriptor field, int index)

public Object getRepeatedField(Descriptors.FieldDescriptor field, int index)
Parameters
NameDescription
fieldDescriptors.FieldDescriptor
indexint
Returns
TypeDescription
Object

getRepeatedFieldBuilder(Descriptors.FieldDescriptor field, int index)

public Message.Builder getRepeatedFieldBuilder(Descriptors.FieldDescriptor field, int index)

Get a nested builder instance for the given repeated field instance.

Normally, we hold a reference to the immutable message object for the message type field. Some implementations(the generated message builders), however, can also hold a reference to the builder object (a nested builder) for the field.

If the field is already backed up by a nested builder, the nested builder will be returned. Otherwise, a new field builder will be created and returned. The original message field (if exist) will be merged into the field builder, which will then be nested into its parent builder.

NOTE: implementations that do not support nested builders will throw UnsupportedOperationException.

Parameters
NameDescription
fieldDescriptors.FieldDescriptor
indexint
Returns
TypeDescription
Message.Builder
Overrides

getRepeatedFieldCount(Descriptors.FieldDescriptor field)

public int getRepeatedFieldCount(Descriptors.FieldDescriptor field)
Parameter
NameDescription
fieldDescriptors.FieldDescriptor
Returns
TypeDescription
int

getUnknownFields()

public final UnknownFieldSet getUnknownFields()
Returns
TypeDescription
UnknownFieldSet

hasField(Descriptors.FieldDescriptor field)

public boolean hasField(Descriptors.FieldDescriptor field)
Parameter
NameDescription
fieldDescriptors.FieldDescriptor
Returns
TypeDescription
boolean

hasOneof(Descriptors.OneofDescriptor oneof)

public boolean hasOneof(Descriptors.OneofDescriptor oneof)

TODO(jieluo): Clear it when all subclasses have implemented this method.

Parameter
NameDescription
oneofDescriptors.OneofDescriptor
Returns
TypeDescription
boolean
Overrides

internalGetFieldAccessorTable()

protected abstract GeneratedMessageV3.FieldAccessorTable internalGetFieldAccessorTable()

Get the FieldAccessorTable for this type. We can't have the message class pass this in to the constructor because of bootstrapping trouble with DescriptorProtos.

Returns
TypeDescription
GeneratedMessageV3.FieldAccessorTable

internalGetMapField(int fieldNumber)

protected MapField internalGetMapField(int fieldNumber)

Gets the map field with the given field number. This method should be overridden in the generated message class if the message contains map fields.

Unlike other field types, reflection support for map fields can't be implemented based on generated public API because we need to access a map field as a list in reflection API but the generated API only allows us to access it as a map. This method returns the underlying map field directly and thus enables us to access the map field as a list.

Parameter
NameDescription
fieldNumberint
Returns
TypeDescription
MapField

internalGetMutableMapField(int fieldNumber)

protected MapField internalGetMutableMapField(int fieldNumber)

Like #internalGetMapField but return a mutable version.

Parameter
NameDescription
fieldNumberint
Returns
TypeDescription
MapField

isClean()

protected boolean isClean()

Gets whether invalidations are needed

Returns
TypeDescription
boolean

whether invalidations are needed

isInitialized()

public boolean isInitialized()
Returns
TypeDescription
boolean

markClean()

protected void markClean()

Called by the subclass or a builder to notify us that a message was built and may be cached and therefore invalidations are needed.

mergeUnknownFields(UnknownFieldSet unknownFields)

public BuilderType mergeUnknownFields(UnknownFieldSet unknownFields)

Merge some unknown fields into the UnknownFieldSet for this message.

Parameter
NameDescription
unknownFieldsUnknownFieldSet
Returns
TypeDescription
BuilderType
Overrides

newBuilderForField(Descriptors.FieldDescriptor field)

public Message.Builder newBuilderForField(Descriptors.FieldDescriptor field)
Parameter
NameDescription
fieldDescriptors.FieldDescriptor
Returns
TypeDescription
Message.Builder

onBuilt()

protected void onBuilt()

Called by the subclass when a message is built.

onChanged()

protected final void onChanged()

Called when a the builder or one of its nested children has changed and any parent should be notified of its invalidation.

setField(Descriptors.FieldDescriptor field, Object value)

public BuilderType setField(Descriptors.FieldDescriptor field, Object value)
Parameters
NameDescription
fieldDescriptors.FieldDescriptor
valueObject
Returns
TypeDescription
BuilderType

setRepeatedField(Descriptors.FieldDescriptor field, int index, Object value)

public BuilderType setRepeatedField(Descriptors.FieldDescriptor field, int index, Object value)
Parameters
NameDescription
fieldDescriptors.FieldDescriptor
indexint
valueObject
Returns
TypeDescription
BuilderType

setUnknownFields(UnknownFieldSet unknownFields)

public BuilderType setUnknownFields(UnknownFieldSet unknownFields)
Parameter
NameDescription
unknownFieldsUnknownFieldSet
Returns
TypeDescription
BuilderType

setUnknownFieldsProto3(UnknownFieldSet unknownFields)

protected BuilderType setUnknownFieldsProto3(UnknownFieldSet unknownFields)

This method is obsolete, but we must retain it for compatibility with older generated code.

Parameter
NameDescription
unknownFieldsUnknownFieldSet
Returns
TypeDescription
BuilderType