Class GeneratedMessage.Builder<BuilderType>

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

Inheritance

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

Type Parameter

NameDescription
BuilderType

Constructors

Builder()

protected Builder()

Builder(GeneratedMessage.BuilderParent builderParent)

protected Builder(GeneratedMessage.BuilderParent builderParent)
Parameter
NameDescription
builderParentGeneratedMessage.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 GeneratedMessage.BuilderParent getParentForChildren()

Gets the BuilderParent for giving to our children.

Returns
TypeDescription
GeneratedMessage.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 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
TypeDescription
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
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.

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
NameDescription
inputCodedInputStream
unknownFieldsUnknownFieldSet.Builder
extensionRegistryExtensionRegistryLite
tagint
Returns
TypeDescription
boolean

true unless the tag is an end-group tag.

Exceptions
TypeDescription
IOException

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