Package com.google.protobuf
Class GeneratedMessage.Builder<BuilderType extends GeneratedMessage.Builder>
java.lang.Object
com.google.protobuf.AbstractMessageLite.Builder<BuilderType>
com.google.protobuf.AbstractMessage.Builder<BuilderType>
com.google.protobuf.GeneratedMessage.Builder<BuilderType>
- All Implemented Interfaces:
Message.Builder
,MessageLite.Builder
,MessageLiteOrBuilder
,MessageOrBuilder
,Cloneable
- Direct Known Subclasses:
DescriptorProtos.DescriptorProto.Builder
,DescriptorProtos.DescriptorProto.ExtensionRange.Builder
,DescriptorProtos.EnumDescriptorProto.Builder
,DescriptorProtos.EnumValueDescriptorProto.Builder
,DescriptorProtos.FieldDescriptorProto.Builder
,DescriptorProtos.FileDescriptorProto.Builder
,DescriptorProtos.FileDescriptorSet.Builder
,DescriptorProtos.MethodDescriptorProto.Builder
,DescriptorProtos.OneofDescriptorProto.Builder
,DescriptorProtos.ServiceDescriptorProto.Builder
,DescriptorProtos.SourceCodeInfo.Builder
,DescriptorProtos.SourceCodeInfo.Location.Builder
,DescriptorProtos.UninterpretedOption.Builder
,DescriptorProtos.UninterpretedOption.NamePart.Builder
,GeneratedMessage.ExtendableBuilder
- Enclosing class:
- GeneratedMessage
public abstract static class GeneratedMessage.Builder<BuilderType extends GeneratedMessage.Builder>
extends AbstractMessage.Builder<BuilderType>
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
Builder()
protected
Builder
(GeneratedMessage.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(jieluo): Clear it when all subclasses have implemented this method.clone()
Clones the Builder.Returns a collection of all the fields in this message which are set and their corresponding values.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(jieluo): Clear it when all subclasses have implemented this method.protected GeneratedMessage.BuilderParent
Gets theGeneratedMessage.BuilderParent
for giving to our children.getRepeatedField
(Descriptors.FieldDescriptor field, int index) Gets an element of a repeated field.int
Gets the number of elements of a repeated field.final UnknownFieldSet
Get theUnknownFieldSet
for this message.boolean
Returns true if the given field is set.boolean
TODO(jieluo): Clear it when all subclasses have implemented this method.protected abstract GeneratedMessage.FieldAccessorTable
Get the FieldAccessorTable for this type.protected boolean
isClean()
Gets whether invalidations are neededboolean
Returns true if all required fields in the message and all embedded messages are set, false otherwise.protected void
Called by the subclass or a builder to notify us that a message was built and may be cached and therefore invalidations are needed.final BuilderType
mergeUnknownFields
(UnknownFieldSet unknownFields) Merge some unknown fields into theUnknownFieldSet
for this message.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 final void
Called when a the builder or one of its nested children has changed and any parent should be notified of its invalidation.protected boolean
parseUnknownField
(CodedInputStream input, UnknownFieldSet.Builder unknownFields, ExtensionRegistryLite extensionRegistry, int tag) Called by 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.final BuilderType
setUnknownFields
(UnknownFieldSet unknownFields) Set theUnknownFieldSet
for this message.Methods inherited from class com.google.protobuf.AbstractMessage.Builder
findInitializationErrors, getInitializationErrorString, mergeDelimitedFrom, mergeDelimitedFrom, mergeFrom, mergeFrom, mergeFrom, mergeFrom, mergeFrom, mergeFrom, mergeFrom, mergeFrom, mergeFrom, mergeFrom, mergeFrom, newUninitializedMessageException, toString
Methods inherited from class com.google.protobuf.AbstractMessageLite.Builder
addAll, 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
Methods inherited from interface com.google.protobuf.MessageOrBuilder
getDefaultInstanceForType
-
Constructor Details
-
Builder
protected Builder() -
Builder
-
-
Method Details
-
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
Description copied from interface:MessageLite.Builder
Clones the Builder.- Specified by:
clone
in interfaceMessage.Builder
- Specified by:
clone
in interfaceMessageLite.Builder
- Specified by:
clone
in classAbstractMessage.Builder<BuilderType extends GeneratedMessage.Builder>
- 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:
clear
in interfaceMessage.Builder
- Specified by:
clear
in interfaceMessageLite.Builder
- Overrides:
clear
in classAbstractMessage.Builder<BuilderType extends GeneratedMessage.Builder>
-
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.Builder
Get the message's type's descriptor. SeeMessageOrBuilder.getDescriptorForType()
. -
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
Description copied from interface:Message.Builder
Create a Builder for messages of the appropriate type for the given field. Messages built with this can then be passed to setField(), setRepeatedField(), or addRepeatedField(). -
getFieldBuilder
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), 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
UnsupportedException
.- Specified by:
getFieldBuilder
in interfaceMessage.Builder
- Overrides:
getFieldBuilder
in classAbstractMessage.Builder<BuilderType extends GeneratedMessage.Builder>
-
hasOneof
Description copied from class:AbstractMessage.Builder
TODO(jieluo): Clear it when all subclasses have implemented this method.- Specified by:
hasOneof
in interfaceMessageOrBuilder
- Overrides:
hasOneof
in classAbstractMessage.Builder<BuilderType extends GeneratedMessage.Builder>
-
getOneofFieldDescriptor
Description copied from class:AbstractMessage.Builder
TODO(jieluo): Clear it when all subclasses have implemented this method.- Specified by:
getOneofFieldDescriptor
in interfaceMessageOrBuilder
- Overrides:
getOneofFieldDescriptor
in classAbstractMessage.Builder<BuilderType extends GeneratedMessage.Builder>
-
hasField
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. -
getField
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
Description copied from interface:Message.Builder
Sets a field to the given value. The value must be of the correct type for this field, i.e. the same type thatMessageOrBuilder.getField(Descriptors.FieldDescriptor)
would return. -
clearField
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
Description copied from class:AbstractMessage.Builder
TODO(jieluo): Clear it when all subclasses have implemented this method.- Specified by:
clearOneof
in interfaceMessage.Builder
- Overrides:
clearOneof
in classAbstractMessage.Builder<BuilderType extends GeneratedMessage.Builder>
-
getRepeatedFieldCount
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
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
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, i.e. the same type thatMessageOrBuilder.getRepeatedField(Descriptors.FieldDescriptor,int)
would return. -
addRepeatedField
Description copied from interface:Message.Builder
LikesetRepeatedField
, but appends the value as a new element. -
setUnknownFields
Description copied from interface:Message.Builder
Set theUnknownFieldSet
for this message. -
mergeUnknownFields
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<BuilderType extends GeneratedMessage.Builder>
-
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
Description copied from interface:MessageOrBuilder
Get theUnknownFieldSet
for this message. -
parseUnknownField
protected boolean parseUnknownField(CodedInputStream input, UnknownFieldSet.Builder unknownFields, ExtensionRegistryLite extensionRegistry, int tag) throws IOException Called by subclasses to parse an unknown field.- Returns:
true
unless the tag is an end-group tag.- Throws:
IOException
-
getParentForChildren
Gets theGeneratedMessage.BuilderParent
for giving to our children.- Returns:
- The builder parent for our children.
-
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.
-