Class GeneratedMessage.Builder<BuilderT extends GeneratedMessage.Builder<BuilderT>>
- java.lang.Object
-
- com.google.protobuf.AbstractMessageLite.Builder
-
- com.google.protobuf.AbstractMessage.Builder<BuilderT>
-
- com.google.protobuf.GeneratedMessage.Builder<BuilderT>
-
- All Implemented Interfaces:
Message.Builder
,MessageLite.Builder
,MessageLiteOrBuilder
,MessageOrBuilder
,java.lang.Cloneable
- Direct Known Subclasses:
Any.Builder
,Api.Builder
,BoolValue.Builder
,BytesValue.Builder
,DescriptorProtos.DescriptorProto.Builder
,DescriptorProtos.DescriptorProto.ExtensionRange.Builder
,DescriptorProtos.DescriptorProto.ReservedRange.Builder
,DescriptorProtos.EnumDescriptorProto.Builder
,DescriptorProtos.EnumDescriptorProto.EnumReservedRange.Builder
,DescriptorProtos.EnumValueDescriptorProto.Builder
,DescriptorProtos.ExtensionRangeOptions.Declaration.Builder
,DescriptorProtos.FeatureSetDefaults.Builder
,DescriptorProtos.FeatureSetDefaults.FeatureSetEditionDefault.Builder
,DescriptorProtos.FieldDescriptorProto.Builder
,DescriptorProtos.FieldOptions.EditionDefault.Builder
,DescriptorProtos.FieldOptions.FeatureSupport.Builder
,DescriptorProtos.FileDescriptorProto.Builder
,DescriptorProtos.GeneratedCodeInfo.Annotation.Builder
,DescriptorProtos.GeneratedCodeInfo.Builder
,DescriptorProtos.MethodDescriptorProto.Builder
,DescriptorProtos.OneofDescriptorProto.Builder
,DescriptorProtos.ServiceDescriptorProto.Builder
,DescriptorProtos.SourceCodeInfo.Location.Builder
,DescriptorProtos.UninterpretedOption.Builder
,DescriptorProtos.UninterpretedOption.NamePart.Builder
,DoubleValue.Builder
,Duration.Builder
,Empty.Builder
,Enum.Builder
,EnumValue.Builder
,Field.Builder
,FieldMask.Builder
,FloatValue.Builder
,GeneratedMessage.ExtendableBuilder
,Int32Value.Builder
,Int64Value.Builder
,JavaFeaturesProto.JavaFeatures.Builder
,ListValue.Builder
,Method.Builder
,Mixin.Builder
,Option.Builder
,PluginProtos.CodeGeneratorRequest.Builder
,PluginProtos.CodeGeneratorResponse.Builder
,PluginProtos.CodeGeneratorResponse.File.Builder
,PluginProtos.Version.Builder
,SourceContext.Builder
,StringValue.Builder
,Struct.Builder
,Timestamp.Builder
,Type.Builder
,UInt32Value.Builder
,UInt64Value.Builder
,Value.Builder
- Enclosing class:
- GeneratedMessage
public abstract static class GeneratedMessage.Builder<BuilderT extends GeneratedMessage.Builder<BuilderT>> extends AbstractMessage.Builder<BuilderT>
Builder class forGeneratedMessage
.
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
Builder()
protected
Builder(AbstractMessage.BuilderParent builderParent)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Deprecated Methods Modifier and Type Method Description BuilderT
addRepeatedField(Descriptors.FieldDescriptor field, java.lang.Object value)
LikesetRepeatedField
, but appends the value as a new element.BuilderT
clear()
Called by the initialization and clear code paths to allow subclasses to reset any of their builtin fields back to the initial values.BuilderT
clearField(Descriptors.FieldDescriptor field)
Clears the field.BuilderT
clearOneof(Descriptors.OneofDescriptor oneof)
TODO: Clear it when all subclasses have implemented this method.BuilderT
clone()
Clones the Builder.java.util.Map<Descriptors.FieldDescriptor,java.lang.Object>
getAllFields()
Returns a collection of all the fields in this message which are set and their corresponding values.Descriptors.Descriptor
getDescriptorForType()
Get the message's type's descriptor.java.lang.Object
getField(Descriptors.FieldDescriptor field)
Obtains the value of the given field, or the default value if it is not set.Message.Builder
getFieldBuilder(Descriptors.FieldDescriptor field)
Get a nested builder instance for the given field.Descriptors.FieldDescriptor
getOneofFieldDescriptor(Descriptors.OneofDescriptor oneof)
TODO: Clear it when all subclasses have implemented this method.protected AbstractMessage.BuilderParent
getParentForChildren()
Gets theAbstractMessage.BuilderParent
for giving to our children.java.lang.Object
getRepeatedField(Descriptors.FieldDescriptor field, int index)
Gets an element of a repeated field.Message.Builder
getRepeatedFieldBuilder(Descriptors.FieldDescriptor field, int index)
Get a nested builder instance for the given repeated field instance.int
getRepeatedFieldCount(Descriptors.FieldDescriptor field)
Gets the number of elements of a repeated field.UnknownFieldSet
getUnknownFields()
Get theUnknownFieldSet
for this message.protected UnknownFieldSet.Builder
getUnknownFieldSetBuilder()
boolean
hasField(Descriptors.FieldDescriptor field)
Returns true if the given field is set.boolean
hasOneof(Descriptors.OneofDescriptor oneof)
TODO: Clear it when all subclasses have implemented this method.protected abstract GeneratedMessage.FieldAccessorTable
internalGetFieldAccessorTable()
Get the FieldAccessorTable for this type.protected MapField
internalGetMapField(int fieldNumber)
Deprecated.protected MapFieldReflectionAccessor
internalGetMapFieldReflection(int fieldNumber)
Gets the map field with the given field number.protected MapField
internalGetMutableMapField(int fieldNumber)
Deprecated.protected MapFieldReflectionAccessor
internalGetMutableMapFieldReflection(int fieldNumber)
LikeinternalGetMapFieldReflection(int)
but return a mutable version.protected boolean
isClean()
Gets whether invalidations are neededboolean
isInitialized()
Returns true if all required fields in the message and all embedded messages are set, false otherwise.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.BuilderT
mergeUnknownFields(UnknownFieldSet unknownFields)
Merge some unknown fields into theUnknownFieldSet
for this message.protected void
mergeUnknownLengthDelimitedField(int number, ByteString bytes)
Called by generated subclasses to add to the unknown field set.protected void
mergeUnknownVarintField(int number, int value)
Called by generated subclasses to add to the unknown field set.Message.Builder
newBuilderForField(Descriptors.FieldDescriptor field)
Create a builder for messages of the appropriate type for the given field.protected void
onBuilt()
Called by the subclass when a message is built.protected void
onChanged()
Called when a builder or one of its nested children has changed and any parent should be notified of its invalidation.protected boolean
parseUnknownField(CodedInputStream input, ExtensionRegistryLite extensionRegistry, int tag)
Called by generated subclasses to parse an unknown field.BuilderT
setField(Descriptors.FieldDescriptor field, java.lang.Object value)
Sets a field to the given value.BuilderT
setRepeatedField(Descriptors.FieldDescriptor field, int index, java.lang.Object value)
Sets an element of a repeated field to the given value.BuilderT
setUnknownFields(UnknownFieldSet unknownFields)
Set theUnknownFieldSet
for this message.protected void
setUnknownFieldSetBuilder(UnknownFieldSet.Builder builder)
protected BuilderT
setUnknownFieldsProto3(UnknownFieldSet unknownFields)
This method is obsolete, but we must retain it for compatibility with older generated code.-
Methods inherited from class com.google.protobuf.AbstractMessage.Builder
findInitializationErrors, getInitializationErrorString, internalMergeFrom, mergeFrom, mergeFrom, mergeFrom, mergeFrom, mergeFrom, mergeFrom, mergeFrom, mergeFrom, mergeFrom, mergeFrom, mergeFrom, newUninitializedMessageException, toString
-
Methods inherited from class com.google.protobuf.AbstractMessageLite.Builder
addAll, addAll, mergeDelimitedFrom, mergeDelimitedFrom, mergeFrom, newUninitializedMessageException
-
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface com.google.protobuf.Message.Builder
build, buildPartial, mergeDelimitedFrom, mergeDelimitedFrom
-
Methods inherited from interface com.google.protobuf.MessageLite.Builder
mergeFrom
-
Methods inherited from interface com.google.protobuf.MessageOrBuilder
getDefaultInstanceForType
-
-
-
-
Constructor Detail
-
Builder
protected Builder()
-
Builder
protected Builder(AbstractMessage.BuilderParent builderParent)
-
-
Method Detail
-
onBuilt
protected void onBuilt()
Called by the subclass when a message is built.
-
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.
-
isClean
protected boolean isClean()
Gets whether invalidations are needed- Returns:
- whether invalidations are needed
-
clone
public BuilderT clone()
Description copied from interface:MessageLite.Builder
Clones the Builder.- Specified by:
clone
in interfaceMessage.Builder
- Specified by:
clone
in interfaceMessageLite.Builder
- Overrides:
clone
in classAbstractMessage.Builder<BuilderT extends GeneratedMessage.Builder<BuilderT>>
- See Also:
Object.clone()
-
clear
public BuilderT clear()
Called by the initialization and clear code paths to allow subclasses to reset any of their builtin fields back to the initial values.- Specified by:
clear
in interfaceMessage.Builder
- Specified by:
clear
in interfaceMessageLite.Builder
- Overrides:
clear
in classAbstractMessage.Builder<BuilderT extends GeneratedMessage.Builder<BuilderT>>
-
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.
-
getDescriptorForType
public Descriptors.Descriptor getDescriptorForType()
Description copied from interface:Message.Builder
Get the message's type's descriptor. SeeMessageOrBuilder.getDescriptorForType()
.
-
getAllFields
public java.util.Map<Descriptors.FieldDescriptor,java.lang.Object> getAllFields()
Description copied from interface:MessageOrBuilder
Returns a collection of all the fields in this message which are set and their corresponding values. A singular ("required" or "optional") field is set iff hasField() returns true for that field. A "repeated" field is set iff getRepeatedFieldCount() is greater than zero. The values are exactly what would be returned by callingMessageOrBuilder.getField(Descriptors.FieldDescriptor)
for each field. The map is guaranteed to be a sorted map, so iterating over it will return fields in order by field number.
If this is for a builder, the returned map may or may not reflect future changes to the builder. Either way, the returned map is itself unmodifiable.
-
newBuilderForField
public Message.Builder newBuilderForField(Descriptors.FieldDescriptor field)
Description copied from interface:Message.Builder
Create a builder for messages of the appropriate type for the given field. The builder is NOT nested in the current builder. However, messages built with the builder can then be passed to theMessage.Builder.setField(Descriptors.FieldDescriptor, Object)
,Message.Builder.setRepeatedField(Descriptors.FieldDescriptor, int, Object)
, orMessage.Builder.addRepeatedField(Descriptors.FieldDescriptor, Object)
method of the current builder.To obtain a builder nested in the current builder, use
Message.Builder.getFieldBuilder(Descriptors.FieldDescriptor)
instead.
-
getFieldBuilder
public Message.Builder getFieldBuilder(Descriptors.FieldDescriptor field)
Description copied from interface:Message.Builder
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) 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 is returned. Otherwise, a new field builder is created and returned. The original message field (if one exists) is merged into the field builder, which is then nested into its parent builder.
- Specified by:
getFieldBuilder
in interfaceMessage.Builder
- Overrides:
getFieldBuilder
in classAbstractMessage.Builder<BuilderT extends GeneratedMessage.Builder<BuilderT>>
-
getRepeatedFieldBuilder
public Message.Builder getRepeatedFieldBuilder(Descriptors.FieldDescriptor field, int index)
Description copied from interface:Message.Builder
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) 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 is returned. Otherwise, a new field builder is created and returned. The original message field (if one exists) is merged into the field builder, which is then nested into its parent builder.
- Specified by:
getRepeatedFieldBuilder
in interfaceMessage.Builder
- Overrides:
getRepeatedFieldBuilder
in classAbstractMessage.Builder<BuilderT extends GeneratedMessage.Builder<BuilderT>>
-
hasOneof
public boolean hasOneof(Descriptors.OneofDescriptor oneof)
Description copied from class:AbstractMessage.Builder
TODO: Clear it when all subclasses have implemented this method.- Specified by:
hasOneof
in interfaceMessageOrBuilder
- Overrides:
hasOneof
in classAbstractMessage.Builder<BuilderT extends GeneratedMessage.Builder<BuilderT>>
-
getOneofFieldDescriptor
public Descriptors.FieldDescriptor getOneofFieldDescriptor(Descriptors.OneofDescriptor oneof)
Description copied from class:AbstractMessage.Builder
TODO: Clear it when all subclasses have implemented this method.- Specified by:
getOneofFieldDescriptor
in interfaceMessageOrBuilder
- Overrides:
getOneofFieldDescriptor
in classAbstractMessage.Builder<BuilderT extends GeneratedMessage.Builder<BuilderT>>
-
hasField
public boolean hasField(Descriptors.FieldDescriptor field)
Description copied from interface:MessageOrBuilder
Returns true if the given field is set. This is exactly equivalent to calling the generated "has" accessor method corresponding to the field. The return value of hasField() is semantically meaningful only for fields where field.hasPresence() == true.
-
getField
public java.lang.Object getField(Descriptors.FieldDescriptor field)
Description copied from interface:MessageOrBuilder
Obtains the value of the given field, or the default value if it is not set. For primitive fields, the boxed primitive value is returned. For enum fields, the EnumValueDescriptor for the value is returned. For embedded message fields, the sub-message is returned. For repeated fields, a java.util.List is returned.
-
setField
public BuilderT setField(Descriptors.FieldDescriptor field, java.lang.Object value)
Description copied from interface:Message.Builder
Sets a field to the given value. The value must be of the correct type for this field, that is, the same type thatMessageOrBuilder.getField(Descriptors.FieldDescriptor)
returns.
-
clearField
public BuilderT clearField(Descriptors.FieldDescriptor field)
Description copied from interface:Message.Builder
Clears the field. This is exactly equivalent to calling the generated "clear" accessor method corresponding to the field.
-
clearOneof
public BuilderT clearOneof(Descriptors.OneofDescriptor oneof)
Description copied from class:AbstractMessage.Builder
TODO: Clear it when all subclasses have implemented this method.- Specified by:
clearOneof
in interfaceMessage.Builder
- Overrides:
clearOneof
in classAbstractMessage.Builder<BuilderT extends GeneratedMessage.Builder<BuilderT>>
-
getRepeatedFieldCount
public int getRepeatedFieldCount(Descriptors.FieldDescriptor field)
Description copied from interface:MessageOrBuilder
Gets the number of elements of a repeated field. This is exactly equivalent to calling the generated "Count" accessor method corresponding to the field.
-
getRepeatedField
public java.lang.Object getRepeatedField(Descriptors.FieldDescriptor field, int index)
Description copied from interface:MessageOrBuilder
Gets an element of a repeated field. For primitive fields, the boxed primitive value is returned. For enum fields, the EnumValueDescriptor for the value is returned. For embedded message fields, the sub-message is returned.
-
setRepeatedField
public BuilderT setRepeatedField(Descriptors.FieldDescriptor field, int index, java.lang.Object value)
Description copied from interface:Message.Builder
Sets an element of a repeated field to the given value. The value must be of the correct type for this field; that is, the same type thatMessageOrBuilder.getRepeatedField(Descriptors.FieldDescriptor,int)
returns.
-
addRepeatedField
public BuilderT addRepeatedField(Descriptors.FieldDescriptor field, java.lang.Object value)
Description copied from interface:Message.Builder
LikesetRepeatedField
, but appends the value as a new element.
-
setUnknownFields
public BuilderT setUnknownFields(UnknownFieldSet unknownFields)
Description copied from interface:Message.Builder
Set theUnknownFieldSet
for this message.
-
setUnknownFieldsProto3
protected BuilderT setUnknownFieldsProto3(UnknownFieldSet unknownFields)
This method is obsolete, but we must retain it for compatibility with older generated code.
-
mergeUnknownFields
public BuilderT mergeUnknownFields(UnknownFieldSet unknownFields)
Description copied from interface:Message.Builder
Merge some unknown fields into theUnknownFieldSet
for this message.- Specified by:
mergeUnknownFields
in interfaceMessage.Builder
- Overrides:
mergeUnknownFields
in classAbstractMessage.Builder<BuilderT extends GeneratedMessage.Builder<BuilderT>>
-
isInitialized
public boolean isInitialized()
Description copied from interface:MessageLiteOrBuilder
Returns true if all required fields in the message and all embedded messages are set, false otherwise.
-
getUnknownFields
public final UnknownFieldSet getUnknownFields()
Description copied from interface:MessageOrBuilder
Get theUnknownFieldSet
for this message.
-
parseUnknownField
protected boolean parseUnknownField(CodedInputStream input, ExtensionRegistryLite extensionRegistry, int tag) throws java.io.IOException
Called by generated subclasses to parse an unknown field.- Returns:
true
unless the tag is an end-group tag.- Throws:
java.io.IOException
-
mergeUnknownLengthDelimitedField
protected final void mergeUnknownLengthDelimitedField(int number, ByteString bytes)
Called by generated subclasses to add to the unknown field set.
-
mergeUnknownVarintField
protected final void mergeUnknownVarintField(int number, int value)
Called by generated subclasses to add to the unknown field set.
-
getUnknownFieldSetBuilder
protected UnknownFieldSet.Builder getUnknownFieldSetBuilder()
- Overrides:
getUnknownFieldSetBuilder
in classAbstractMessage.Builder<BuilderT extends GeneratedMessage.Builder<BuilderT>>
-
setUnknownFieldSetBuilder
protected void setUnknownFieldSetBuilder(UnknownFieldSet.Builder builder)
- Overrides:
setUnknownFieldSetBuilder
in classAbstractMessage.Builder<BuilderT extends GeneratedMessage.Builder<BuilderT>>
-
getParentForChildren
protected AbstractMessage.BuilderParent getParentForChildren()
Gets theAbstractMessage.BuilderParent
for giving to our children.- Returns:
- The builder parent for our children.
-
onChanged
protected final void onChanged()
Called when a builder or one of its nested children has changed and any parent should be notified of its invalidation.
-
internalGetMapFieldReflection
protected MapFieldReflectionAccessor internalGetMapFieldReflection(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.
-
internalGetMapField
@Deprecated protected MapField internalGetMapField(int fieldNumber)
Deprecated.TODO: Remove, exists for compatibility with generated code.
-
internalGetMutableMapFieldReflection
protected MapFieldReflectionAccessor internalGetMutableMapFieldReflection(int fieldNumber)
LikeinternalGetMapFieldReflection(int)
but return a mutable version.
-
internalGetMutableMapField
@Deprecated protected MapField internalGetMutableMapField(int fieldNumber)
Deprecated.TODO: Remove, exists for compatibility with generated code.
-
-