Class GeneratedMessageV3.Builder<BuilderT extends GeneratedMessageV3.Builder<BuilderT>>
- All Implemented Interfaces:
Message.Builder,MessageLite.Builder,MessageLiteOrBuilder,MessageOrBuilder,Cloneable
- Direct Known Subclasses:
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.FileDescriptorProto.Builder,DescriptorProtos.FileDescriptorSet.Builder,DescriptorProtos.GeneratedCodeInfo.Annotation.Builder,DescriptorProtos.GeneratedCodeInfo.Builder,DescriptorProtos.MethodDescriptorProto.Builder,DescriptorProtos.OneofDescriptorProto.Builder,DescriptorProtos.ServiceDescriptorProto.Builder,DescriptorProtos.SourceCodeInfo.Builder,DescriptorProtos.SourceCodeInfo.Location.Builder,DescriptorProtos.UninterpretedOption.Builder,DescriptorProtos.UninterpretedOption.NamePart.Builder,GeneratedMessageV3.ExtendableBuilder,PluginProtos.CodeGeneratorRequest.Builder,PluginProtos.CodeGeneratorResponse.Builder,PluginProtos.CodeGeneratorResponse.File.Builder,PluginProtos.Version.Builder
- Enclosing class:
- GeneratedMessageV3
GeneratedMessageV3.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate classImplementation ofGeneratedMessageV3.BuilderParentfor giving to our children.Nested classes/interfaces inherited from class com.google.protobuf.AbstractMessageLite.Builder
AbstractMessageLite.Builder.LimitedInputStream -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate GeneratedMessageV3.BuilderParentprivate booleanprivate ObjectThis field holds either anUnknownFieldSetorUnknownFieldSet.Builder. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedBuilder()protectedBuilder(GeneratedMessageV3.BuilderParent builderParent) -
Method Summary
Modifier and TypeMethodDescriptionaddRepeatedField(Descriptors.FieldDescriptor field, Object value) LikesetRepeatedField, but appends the value as a new element.clear()Called by the initialization and clear code paths to allow subclasses to reset any of their builtin fields back to the initial values.Clears the field.TODO: Clear it when all subclasses have implemented this method.clone()Clones the Builder.(package private) voiddispose()Used to support nested builders and called when this nested builder is no longer used by its parent builder and should release the reference to its parent builder.Returns a collection of all the fields in this message which are set and their corresponding values.private Map<Descriptors.FieldDescriptor,Object> Internal helper which returns a mutable map.Get the message's type's descriptor.Obtains the value of the given field, or the default value if it is not set.Get a nested builder instance for the given field.TODO: Clear it when all subclasses have implemented this method.protected GeneratedMessageV3.BuilderParentGets theGeneratedMessageV3.BuilderParentfor giving to our children.getRepeatedField(Descriptors.FieldDescriptor field, int index) Gets an element of a repeated field.getRepeatedFieldBuilder(Descriptors.FieldDescriptor field, int index) Get a nested builder instance for the given repeated field instance.intGets the number of elements of a repeated field.final UnknownFieldSetGet theUnknownFieldSetfor this message.protected UnknownFieldSet.BuilderbooleanReturns true if the given field is set.booleanTODO: Clear it when all subclasses have implemented this method.protected abstract GeneratedMessageV3.FieldAccessorTableGet the FieldAccessorTable for this type.protected MapFieldinternalGetMapField(int fieldNumber) Deprecated.protected MapFieldReflectionAccessorinternalGetMapFieldReflection(int fieldNumber) Gets the map field with the given field number.protected MapFieldinternalGetMutableMapField(int fieldNumber) Deprecated.protected MapFieldReflectionAccessorinternalGetMutableMapFieldReflection(int fieldNumber) LikeinternalGetMapFieldReflection(int)but return a mutable version.protected booleanisClean()Gets whether invalidations are neededbooleanReturns true if all required fields in the message and all embedded messages are set, false otherwise.protected voidCalled 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) Merge some unknown fields into theUnknownFieldSetfor this message.protected final voidmergeUnknownLengthDelimitedField(int number, ByteString bytes) Called by generated subclasses to add to the unknown field set.protected final voidmergeUnknownVarintField(int number, int value) Called by generated subclasses to add to the unknown field set.Create a builder for messages of the appropriate type for the given field.protected voidonBuilt()Called by the subclass when a message is built.protected final voidCalled when a builder or one of its nested children has changed and any parent should be notified of its invalidation.protected booleanparseUnknownField(CodedInputStream input, ExtensionRegistryLite extensionRegistry, int tag) Called by generated subclasses to parse an unknown field.setField(Descriptors.FieldDescriptor field, Object value) Sets a field to the given value.setRepeatedField(Descriptors.FieldDescriptor field, int index, Object value) Sets an element of a repeated field to the given value.setUnknownFields(UnknownFieldSet unknownFields) Set theUnknownFieldSetfor this message.protected voidprivate BuilderTsetUnknownFieldsInternal(UnknownFieldSet unknownFields) protected BuilderTsetUnknownFieldsProto3(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, mergeFrom, newUninitializedMessageException, toStringMethods inherited from class com.google.protobuf.AbstractMessageLite.Builder
addAll, addAll, mergeDelimitedFrom, mergeDelimitedFrom, mergeFrom, newUninitializedMessageExceptionMethods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface com.google.protobuf.Message.Builder
build, buildPartial, mergeDelimitedFrom, mergeDelimitedFromMethods inherited from interface com.google.protobuf.MessageLite.Builder
mergeFromMethods inherited from interface com.google.protobuf.MessageOrBuilder
getDefaultInstanceForType
-
Field Details
-
builderParent
-
meAsParent
private GeneratedMessageV3.Builder<BuilderT extends GeneratedMessageV3.Builder<BuilderT>>.BuilderParentImpl meAsParent -
isClean
private boolean isClean -
unknownFieldsOrBuilder
This field holds either anUnknownFieldSetorUnknownFieldSet.Builder.We use an object because it should only be one or the other of those things at a time and Object is the only common base. This also saves space.
Conversions are lazy: if
setUnknownFields(com.google.protobuf.UnknownFieldSet)is called, this will containUnknownFieldSet. If unknown fields are merged into this builder, the currentUnknownFieldSetwill be converted to aUnknownFieldSet.Builderand left that way until eithersetUnknownFields(com.google.protobuf.UnknownFieldSet)orMessageLite.Builder.buildPartial()orMessageLite.Builder.build()is called.
-
-
Constructor Details
-
Builder
protected Builder() -
Builder
-
-
Method Details
-
dispose
void dispose()Description copied from class:AbstractMessage.BuilderUsed to support nested builders and called when this nested builder is no longer used by its parent builder and should release the reference to its parent builder.NOTE: Implementations that don't support nested builders don't need to override this method.
- Overrides:
disposein classAbstractMessage.Builder<BuilderT extends GeneratedMessageV3.Builder<BuilderT>>
-
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.- Overrides:
markCleanin classAbstractMessage.Builder<BuilderT extends GeneratedMessageV3.Builder<BuilderT>>
-
isClean
protected boolean isClean()Gets whether invalidations are needed- Returns:
- whether invalidations are needed
-
clone
Description copied from interface:MessageLite.BuilderClones the Builder.- Specified by:
clonein interfaceMessage.Builder- Specified by:
clonein interfaceMessageLite.Builder- Overrides:
clonein classAbstractMessage.Builder<BuilderT extends GeneratedMessageV3.Builder<BuilderT>>- See Also:
-
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:
clearin interfaceMessage.Builder- Specified by:
clearin interfaceMessageLite.Builder- Overrides:
clearin classAbstractMessage.Builder<BuilderT extends GeneratedMessageV3.Builder<BuilderT>>
-
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
Description copied from interface:Message.BuilderGet the message's type's descriptor. SeeMessageOrBuilder.getDescriptorForType(). -
getAllFields
Description copied from interface:MessageOrBuilderReturns 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. -
getAllFieldsMutable
Internal helper which returns a mutable map. -
newBuilderForField
Description copied from interface:Message.BuilderCreate 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
Description copied from interface:Message.BuilderGet 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:
getFieldBuilderin interfaceMessage.Builder- Overrides:
getFieldBuilderin classAbstractMessage.Builder<BuilderT extends GeneratedMessageV3.Builder<BuilderT>>
-
getRepeatedFieldBuilder
Description copied from interface:Message.BuilderGet 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:
getRepeatedFieldBuilderin interfaceMessage.Builder- Overrides:
getRepeatedFieldBuilderin classAbstractMessage.Builder<BuilderT extends GeneratedMessageV3.Builder<BuilderT>>
-
hasOneof
Description copied from class:AbstractMessage.BuilderTODO: Clear it when all subclasses have implemented this method.- Specified by:
hasOneofin interfaceMessageOrBuilder- Overrides:
hasOneofin classAbstractMessage.Builder<BuilderT extends GeneratedMessageV3.Builder<BuilderT>>
-
getOneofFieldDescriptor
Description copied from class:AbstractMessage.BuilderTODO: Clear it when all subclasses have implemented this method.- Specified by:
getOneofFieldDescriptorin interfaceMessageOrBuilder- Overrides:
getOneofFieldDescriptorin classAbstractMessage.Builder<BuilderT extends GeneratedMessageV3.Builder<BuilderT>>
-
hasField
Description copied from interface:MessageOrBuilderReturns 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
Description copied from interface:MessageOrBuilderObtains 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
Description copied from interface:Message.BuilderSets 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
Description copied from interface:Message.BuilderClears the field. This is exactly equivalent to calling the generated "clear" accessor method corresponding to the field. -
clearOneof
Description copied from class:AbstractMessage.BuilderTODO: Clear it when all subclasses have implemented this method.- Specified by:
clearOneofin interfaceMessage.Builder- Overrides:
clearOneofin classAbstractMessage.Builder<BuilderT extends GeneratedMessageV3.Builder<BuilderT>>
-
getRepeatedFieldCount
Description copied from interface:MessageOrBuilderGets the number of elements of a repeated field. This is exactly equivalent to calling the generated "Count" accessor method corresponding to the field. -
getRepeatedField
Description copied from interface:MessageOrBuilderGets 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
Description copied from interface:Message.BuilderSets 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
Description copied from interface:Message.BuilderLikesetRepeatedField, but appends the value as a new element. -
setUnknownFieldsInternal
-
setUnknownFields
Description copied from interface:Message.BuilderSet theUnknownFieldSetfor this message. -
setUnknownFieldsProto3
This method is obsolete, but we must retain it for compatibility with older generated code. -
mergeUnknownFields
Description copied from interface:Message.BuilderMerge some unknown fields into theUnknownFieldSetfor this message.- Specified by:
mergeUnknownFieldsin interfaceMessage.Builder- Overrides:
mergeUnknownFieldsin classAbstractMessage.Builder<BuilderT extends GeneratedMessageV3.Builder<BuilderT>>
-
isInitialized
public boolean isInitialized()Description copied from interface:MessageLiteOrBuilderReturns true if all required fields in the message and all embedded messages are set, false otherwise. -
getUnknownFields
Description copied from interface:MessageOrBuilderGet theUnknownFieldSetfor this message. -
parseUnknownField
protected boolean parseUnknownField(CodedInputStream input, ExtensionRegistryLite extensionRegistry, int tag) throws IOException Called by generated subclasses to parse an unknown field.- Returns:
trueunless the tag is an end-group tag.- Throws:
IOException
-
mergeUnknownLengthDelimitedField
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
- Overrides:
getUnknownFieldSetBuilderin classAbstractMessage.Builder<BuilderT extends GeneratedMessageV3.Builder<BuilderT>>
-
setUnknownFieldSetBuilder
- Overrides:
setUnknownFieldSetBuilderin classAbstractMessage.Builder<BuilderT extends GeneratedMessageV3.Builder<BuilderT>>
-
getParentForChildren
Gets theGeneratedMessageV3.BuilderParentfor 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
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.TODO: Remove, exists for compatibility with generated code. -
internalGetMutableMapFieldReflection
LikeinternalGetMapFieldReflection(int)but return a mutable version. -
internalGetMutableMapField
Deprecated.TODO: Remove, exists for compatibility with generated code.
-