Class GeneratedMessage.Builder<BuilderType> (3.19.4)

public abstract static class GeneratedMessage.Builder<BuilderType> extends AbstractMessage.Builder<BuilderType>

Inheritance

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

Type Parameter

Name Description
BuilderType

Constructors

Builder()

protected Builder()

Builder(GeneratedMessage.BuilderParent builderParent)

protected Builder(GeneratedMessage.BuilderParent builderParent)
Parameter
Name Description
builderParent GeneratedMessage.BuilderParent

Methods

addRepeatedField(Descriptors.FieldDescriptor field, Object value)

public BuilderType addRepeatedField(Descriptors.FieldDescriptor field, Object value)
Parameters
Name Description
field Descriptors.FieldDescriptor
value Object
Returns
Type Description
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
Type Description
BuilderType
Overrides

clearField(Descriptors.FieldDescriptor field)

public BuilderType clearField(Descriptors.FieldDescriptor field)
Parameter
Name Description
field Descriptors.FieldDescriptor
Returns
Type Description
BuilderType

clearOneof(Descriptors.OneofDescriptor oneof)

public BuilderType clearOneof(Descriptors.OneofDescriptor oneof)

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

Parameter
Name Description
oneof Descriptors.OneofDescriptor
Returns
Type Description
BuilderType
Overrides

clone()

public BuilderType clone()

Clones the Builder.

Returns
Type Description
BuilderType
Overrides

getAllFields()

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

getDescriptorForType()

public Descriptors.Descriptor getDescriptorForType()
Returns
Type Description
Descriptors.Descriptor

getField(Descriptors.FieldDescriptor field)

public Object getField(Descriptors.FieldDescriptor field)
Parameter
Name Description
field Descriptors.FieldDescriptor
Returns
Type Description
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
Name Description
field Descriptors.FieldDescriptor
Returns
Type Description
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
Name Description
oneof Descriptors.OneofDescriptor
Returns
Type Description
Descriptors.FieldDescriptor
Overrides

getParentForChildren()

protected GeneratedMessage.BuilderParent getParentForChildren()

Gets the BuilderParent for giving to our children.

Returns
Type Description
GeneratedMessage.BuilderParent

The builder parent for our children.

getRepeatedField(Descriptors.FieldDescriptor field, int index)

public Object getRepeatedField(Descriptors.FieldDescriptor field, int index)
Parameters
Name Description
field Descriptors.FieldDescriptor
index int
Returns
Type Description
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
Name Description
field Descriptors.FieldDescriptor
index int
Returns
Type Description
Message.Builder
Overrides

getRepeatedFieldCount(Descriptors.FieldDescriptor field)

public int getRepeatedFieldCount(Descriptors.FieldDescriptor field)
Parameter
Name Description
field Descriptors.FieldDescriptor
Returns
Type Description
int

getUnknownFields()

public final UnknownFieldSet getUnknownFields()
Returns
Type Description
UnknownFieldSet

hasField(Descriptors.FieldDescriptor field)

public boolean hasField(Descriptors.FieldDescriptor field)
Parameter
Name Description
field Descriptors.FieldDescriptor
Returns
Type Description
boolean

hasOneof(Descriptors.OneofDescriptor oneof)

public boolean hasOneof(Descriptors.OneofDescriptor oneof)

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

Parameter
Name Description
oneof Descriptors.OneofDescriptor
Returns
Type Description
boolean
Overrides

internalGetFieldAccessorTable()

protected abstract GeneratedMessage.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
Type Description
GeneratedMessage.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
Name Description
fieldNumber int
Returns
Type Description
MapField

internalGetMutableMapField(int fieldNumber)

protected MapField internalGetMutableMapField(int fieldNumber)

Like #internalGetMapField but return a mutable version.

Parameter
Name Description
fieldNumber int
Returns
Type Description
MapField

isClean()

protected boolean isClean()

Gets whether invalidations are needed

Returns
Type Description
boolean

whether invalidations are needed

isInitialized()

public boolean isInitialized()
Returns
Type Description
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
Name Description
unknownFields UnknownFieldSet
Returns
Type Description
BuilderType
Overrides

newBuilderForField(Descriptors.FieldDescriptor field)

public Message.Builder newBuilderForField(Descriptors.FieldDescriptor field)
Parameter
Name Description
field Descriptors.FieldDescriptor
Returns
Type Description
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.

parseUnknownField(CodedInputStream input, UnknownFieldSet.Builder unknownFields, ExtensionRegistryLite extensionRegistry, int tag)

protected boolean parseUnknownField(CodedInputStream input, UnknownFieldSet.Builder unknownFields, ExtensionRegistryLite extensionRegistry, int tag)

Called by subclasses to parse an unknown field.

Parameters
Name Description
input CodedInputStream
unknownFields UnknownFieldSet.Builder
extensionRegistry ExtensionRegistryLite
tag int
Returns
Type Description
boolean

true unless the tag is an end-group tag.

Exceptions
Type Description
IOException

setField(Descriptors.FieldDescriptor field, Object value)

public BuilderType setField(Descriptors.FieldDescriptor field, Object value)
Parameters
Name Description
field Descriptors.FieldDescriptor
value Object
Returns
Type Description
BuilderType

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

public BuilderType setRepeatedField(Descriptors.FieldDescriptor field, int index, Object value)
Parameters
Name Description
field Descriptors.FieldDescriptor
index int
value Object
Returns
Type Description
BuilderType

setUnknownFields(UnknownFieldSet unknownFields)

public BuilderType setUnknownFields(UnknownFieldSet unknownFields)
Parameter
Name Description
unknownFields UnknownFieldSet
Returns
Type Description
BuilderType