Class GeneratedMessageV3.ExtendableBuilder<MessageType extends GeneratedMessageV3.ExtendableMessage, BuilderType extends GeneratedMessageV3.ExtendableBuilder<MessageType, BuilderType>>
- All Implemented Interfaces:
GeneratedMessageV3.ExtendableMessageOrBuilder<MessageType>, Message.Builder, MessageLite.Builder, MessageLiteOrBuilder, MessageOrBuilder, Cloneable
- Direct Known Subclasses:
DescriptorProtos.EnumOptions.Builder, DescriptorProtos.EnumValueOptions.Builder, DescriptorProtos.ExtensionRangeOptions.Builder, DescriptorProtos.FieldOptions.Builder, DescriptorProtos.FileOptions.Builder, DescriptorProtos.MessageOptions.Builder, DescriptorProtos.MethodOptions.Builder, DescriptorProtos.OneofOptions.Builder, DescriptorProtos.ServiceOptions.Builder
- Enclosing class:
GeneratedMessageV3
This class implements type-safe accessors for extensions. They
implement all the same operations that you can do with normal fields --
e.g. "get", "set", and "add" -- but for extensions. The extensions are
identified using instances of the class GeneratedMessage.GeneratedExtension; the
protocol compiler generates a static instance of this class for every
extension in its input. Through the magic of generics, all is made
type-safe.
For example, imagine you have the .proto file:
option java_class = "MyProto";
message Foo {
extensions 1000 to max;
}
extend Foo {
optional int32 bar;
}
Then you might write code like:
MyProto.Foo foo =
MyProto.Foo.newBuilder()
.setExtension(MyProto.bar, 123)
.build();
See also GeneratedMessageV3.ExtendableMessage.
-
Nested Class Summary
Nested classes/interfaces inherited from class AbstractMessageLite.Builder
AbstractMessageLite.Builder.LimitedInputStream -
Field Summary
FieldsModifier and TypeFieldDescription -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedprotected -
Method Summary
Modifier and TypeMethodDescriptionfinal <Type> BuilderTypeaddExtension(Extension<MessageType, List<Type>> extension, Type value) Append a value to a repeated extension.final <Type> BuilderTypeaddExtension(ExtensionLite<MessageType, List<Type>> extensionLite, Type value) Append a value to a repeated extension.<Type> BuilderTypeaddExtension(GeneratedMessage.GeneratedExtension<MessageType, List<Type>> extension, Type value) Append a value to a repeated extension.addRepeatedField(Descriptors.FieldDescriptor field, Object value) LikesetRepeatedField, but appends the value as a new element.private FieldSet<Descriptors.FieldDescriptor> Called by the build code path to create a copy of the extensions for building the message.clear()Called by the initialization and clear code paths to allow subclasses to reset any of their builtin fields back to the initial values.final <Type> BuilderTypeclearExtension(Extension<MessageType, ?> extension) Clear an extension.final BuilderTypeclearExtension(ExtensionLite<MessageType, ?> extensionLite) Clear an extension.<Type> BuilderTypeclearExtension(GeneratedMessage.GeneratedExtension<MessageType, ?> extension) Clear an extension.Clears the field.private voidprotected booleanCalled by subclasses to check if all extensions are initialized.Returns a collection of all the fields in this message which are set and their corresponding values.final <Type> TypegetExtension(Extension<MessageType, List<Type>> extension, int index) Get the value of an extension.final <Type> TypegetExtension(Extension<MessageType, Type> extension) Get the value of an extension.final <Type> TypegetExtension(ExtensionLite<MessageType, List<Type>> extensionLite, int index) Get one element of a repeated extension.final <Type> TypegetExtension(ExtensionLite<MessageType, Type> extensionLite) Get the value of an extension.final <Type> TypegetExtension(GeneratedMessage.GeneratedExtension<MessageType, List<Type>> extension, int index) Get the value of an extension.final <Type> TypegetExtension(GeneratedMessage.GeneratedExtension<MessageType, Type> extension) Get the value of an extension.final <Type> intgetExtensionCount(Extension<MessageType, List<Type>> extension) Get the number of elements in a repeated extension.final <Type> intgetExtensionCount(ExtensionLite<MessageType, List<Type>> extensionLite) Get the number of elements in a repeated extension.final <Type> intgetExtensionCount(GeneratedMessage.GeneratedExtension<MessageType, List<Type>> extension) Get the number of elements in a repeated extension.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.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 <Type> booleanhasExtension(Extension<MessageType, Type> extension) Check if a singular extension is present.final <Type> booleanhasExtension(ExtensionLite<MessageType, Type> extensionLite) Check if a singular extension is present.final <Type> booleanhasExtension(GeneratedMessage.GeneratedExtension<MessageType, Type> extension) Check if a singular extension is present.booleanReturns true if the given field is set.(package private) voidinternalSetExtensionSet(FieldSet<Descriptors.FieldDescriptor> extensions) booleanReturns true if all required fields in the message and all embedded messages are set, false otherwise.protected final voidCreate a builder for messages of the appropriate type for the given field.protected booleanparseUnknownField(CodedInputStream input, ExtensionRegistryLite extensionRegistry, int tag) Called by generated subclasses to parse an unknown field.final <Type> BuilderTypesetExtension(Extension<MessageType, List<Type>> extension, int index, Type value) Set the value of one element of a repeated extension.final <Type> BuilderTypesetExtension(Extension<MessageType, Type> extension, Type value) Set the value of an extension.final <Type> BuilderTypesetExtension(ExtensionLite<MessageType, List<Type>> extensionLite, int index, Type value) Set the value of one element of a repeated extension.final <Type> BuilderTypesetExtension(ExtensionLite<MessageType, Type> extensionLite, Type value) Set the value of an extension.<Type> BuilderTypesetExtension(GeneratedMessage.GeneratedExtension<MessageType, List<Type>> extension, int index, Type value) Set the value of one element of a repeated extension.<Type> BuilderTypesetExtension(GeneratedMessage.GeneratedExtension<MessageType, Type> extension, Type value) Set the value of an extension.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.private voidprivate voidverifyExtensionContainingType(Extension<MessageType, ?> extension) Methods inherited from class GeneratedMessageV3.Builder
clearOneof, clone, dispose, getDescriptorForType, getOneofFieldDescriptor, getParentForChildren, getUnknownFields, getUnknownFieldSetBuilder, hasOneof, internalGetFieldAccessorTable, internalGetMapField, internalGetMutableMapField, isClean, markClean, mergeUnknownFields, mergeUnknownLengthDelimitedField, mergeUnknownVarintField, onBuilt, onChanged, setUnknownFields, setUnknownFieldSetBuilder, setUnknownFieldsProto3Methods inherited from class AbstractMessage.Builder
findInitializationErrors, getInitializationErrorString, internalMergeFrom, mergeDelimitedFrom, mergeDelimitedFrom, mergeFrom, mergeFrom, mergeFrom, mergeFrom, mergeFrom, mergeFrom, mergeFrom, mergeFrom, mergeFrom, mergeFrom, mergeFrom, mergeFrom, newUninitializedMessageException, toStringMethods inherited from class AbstractMessageLite.Builder
addAll, addAll, mergeFrom, newUninitializedMessageExceptionMethods inherited from class Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface GeneratedMessageV3.ExtendableMessageOrBuilder
getDefaultInstanceForTypeMethods inherited from interface Message.Builder
build, buildPartialMethods inherited from interface MessageLite.Builder
mergeFromMethods inherited from interface MessageOrBuilder
findInitializationErrors, getInitializationErrorString, getOneofFieldDescriptor, getUnknownFields, hasOneof
-
Field Details
-
extensions
-
-
Constructor Details
-
ExtendableBuilder
protected ExtendableBuilder() -
ExtendableBuilder
-
-
Method Details
-
internalSetExtensionSet
-
clear
Description copied from class:GeneratedMessageV3.BuilderCalled 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 classGeneratedMessageV3.Builder<BuilderType extends GeneratedMessageV3.ExtendableBuilder<MessageType, BuilderType>>
-
ensureExtensionsIsMutable
private void ensureExtensionsIsMutable() -
verifyExtensionContainingType
-
hasExtension
Check if a singular extension is present.- Specified by:
hasExtensionin interfaceGeneratedMessageV3.ExtendableMessageOrBuilder<MessageType extends GeneratedMessageV3.ExtendableMessage>
-
getExtensionCount
Get the number of elements in a repeated extension.- Specified by:
getExtensionCountin interfaceGeneratedMessageV3.ExtendableMessageOrBuilder<MessageType extends GeneratedMessageV3.ExtendableMessage>
-
getExtension
Get the value of an extension.- Specified by:
getExtensionin interfaceGeneratedMessageV3.ExtendableMessageOrBuilder<MessageType extends GeneratedMessageV3.ExtendableMessage>
-
getExtension
public final <Type> Type getExtension(ExtensionLite<MessageType, List<Type>> extensionLite, int index) Get one element of a repeated extension.- Specified by:
getExtensionin interfaceGeneratedMessageV3.ExtendableMessageOrBuilder<MessageType extends GeneratedMessageV3.ExtendableMessage>
-
setExtension
public final <Type> BuilderType setExtension(ExtensionLite<MessageType, Type> extensionLite, Type value) Set the value of an extension. -
setExtension
public final <Type> BuilderType setExtension(ExtensionLite<MessageType, List<Type>> extensionLite, int index, Type value) Set the value of one element of a repeated extension. -
addExtension
public final <Type> BuilderType addExtension(ExtensionLite<MessageType, List<Type>> extensionLite, Type value) Append a value to a repeated extension. -
clearExtension
Clear an extension. -
hasExtension
Check if a singular extension is present.- Specified by:
hasExtensionin interfaceGeneratedMessageV3.ExtendableMessageOrBuilder<MessageType extends GeneratedMessageV3.ExtendableMessage>
-
hasExtension
public final <Type> boolean hasExtension(GeneratedMessage.GeneratedExtension<MessageType, Type> extension) Check if a singular extension is present.- Specified by:
hasExtensionin interfaceGeneratedMessageV3.ExtendableMessageOrBuilder<MessageType extends GeneratedMessageV3.ExtendableMessage>
-
getExtensionCount
Get the number of elements in a repeated extension.- Specified by:
getExtensionCountin interfaceGeneratedMessageV3.ExtendableMessageOrBuilder<MessageType extends GeneratedMessageV3.ExtendableMessage>
-
getExtensionCount
public final <Type> int getExtensionCount(GeneratedMessage.GeneratedExtension<MessageType, List<Type>> extension) Get the number of elements in a repeated extension.- Specified by:
getExtensionCountin interfaceGeneratedMessageV3.ExtendableMessageOrBuilder<MessageType extends GeneratedMessageV3.ExtendableMessage>
-
getExtension
Get the value of an extension.- Specified by:
getExtensionin interfaceGeneratedMessageV3.ExtendableMessageOrBuilder<MessageType extends GeneratedMessageV3.ExtendableMessage>
-
getExtension
public final <Type> Type getExtension(GeneratedMessage.GeneratedExtension<MessageType, Type> extension) Get the value of an extension.- Specified by:
getExtensionin interfaceGeneratedMessageV3.ExtendableMessageOrBuilder<MessageType extends GeneratedMessageV3.ExtendableMessage>
-
getExtension
Get the value of an extension.- Specified by:
getExtensionin interfaceGeneratedMessageV3.ExtendableMessageOrBuilder<MessageType extends GeneratedMessageV3.ExtendableMessage>
-
getExtension
public final <Type> Type getExtension(GeneratedMessage.GeneratedExtension<MessageType, List<Type>> extension, int index) Get the value of an extension.- Specified by:
getExtensionin interfaceGeneratedMessageV3.ExtendableMessageOrBuilder<MessageType extends GeneratedMessageV3.ExtendableMessage>
-
setExtension
Set the value of an extension. -
setExtension
public <Type> BuilderType setExtension(GeneratedMessage.GeneratedExtension<MessageType, Type> extension, Type value) Set the value of an extension. -
setExtension
public final <Type> BuilderType setExtension(Extension<MessageType, List<Type>> extension, int index, Type value) Set the value of one element of a repeated extension. -
setExtension
public <Type> BuilderType setExtension(GeneratedMessage.GeneratedExtension<MessageType, List<Type>> extension, int index, Type value) Set the value of one element of a repeated extension. -
addExtension
public final <Type> BuilderType addExtension(Extension<MessageType, List<Type>> extension, Type value) Append a value to a repeated extension. -
addExtension
public <Type> BuilderType addExtension(GeneratedMessage.GeneratedExtension<MessageType, List<Type>> extension, Type value) Append a value to a repeated extension. -
clearExtension
Clear an extension. -
clearExtension
public <Type> BuilderType clearExtension(GeneratedMessage.GeneratedExtension<MessageType, ?> extension) Clear an extension. -
extensionsAreInitialized
protected boolean extensionsAreInitialized()Called by subclasses to check if all extensions are initialized. -
buildExtensions
Called by the build code path to create a copy of the extensions for building the message. -
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.- Specified by:
isInitializedin interfaceMessageLiteOrBuilder- Overrides:
isInitializedin classGeneratedMessageV3.Builder<BuilderType extends GeneratedMessageV3.ExtendableBuilder<MessageType, BuilderType>>
-
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.- Specified by:
getAllFieldsin interfaceMessageOrBuilder- Overrides:
getAllFieldsin classGeneratedMessageV3.Builder<BuilderType extends GeneratedMessageV3.ExtendableBuilder<MessageType, BuilderType>>
-
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.- Specified by:
getFieldin interfaceMessageOrBuilder- Overrides:
getFieldin classGeneratedMessageV3.Builder<BuilderType extends GeneratedMessageV3.ExtendableBuilder<MessageType, BuilderType>>
-
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), 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.- Specified by:
getFieldBuilderin interfaceMessage.Builder- Overrides:
getFieldBuilderin classGeneratedMessageV3.Builder<BuilderType extends GeneratedMessageV3.ExtendableBuilder<MessageType, BuilderType>>
-
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.- Specified by:
getRepeatedFieldCountin interfaceMessageOrBuilder- Overrides:
getRepeatedFieldCountin classGeneratedMessageV3.Builder<BuilderType extends GeneratedMessageV3.ExtendableBuilder<MessageType, BuilderType>>
-
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.- Specified by:
getRepeatedFieldin interfaceMessageOrBuilder- Overrides:
getRepeatedFieldin classGeneratedMessageV3.Builder<BuilderType extends GeneratedMessageV3.ExtendableBuilder<MessageType, BuilderType>>
-
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), 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.- Specified by:
getRepeatedFieldBuilderin interfaceMessage.Builder- Overrides:
getRepeatedFieldBuilderin classGeneratedMessageV3.Builder<BuilderType extends GeneratedMessageV3.ExtendableBuilder<MessageType, BuilderType>>
-
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.- Specified by:
hasFieldin interfaceMessageOrBuilder- Overrides:
hasFieldin classGeneratedMessageV3.Builder<BuilderType extends GeneratedMessageV3.ExtendableBuilder<MessageType, BuilderType>>
-
setField
Description copied from interface:Message.BuilderSets 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.- Specified by:
setFieldin interfaceMessage.Builder- Overrides:
setFieldin classGeneratedMessageV3.Builder<BuilderType extends GeneratedMessageV3.ExtendableBuilder<MessageType, BuilderType>>
-
clearField
Description copied from interface:Message.BuilderClears the field. This is exactly equivalent to calling the generated "clear" accessor method corresponding to the field.- Specified by:
clearFieldin interfaceMessage.Builder- Overrides:
clearFieldin classGeneratedMessageV3.Builder<BuilderType extends GeneratedMessageV3.ExtendableBuilder<MessageType, BuilderType>>
-
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, i.e. the same type thatMessageOrBuilder.getRepeatedField(Descriptors.FieldDescriptor,int)would return.- Specified by:
setRepeatedFieldin interfaceMessage.Builder- Overrides:
setRepeatedFieldin classGeneratedMessageV3.Builder<BuilderType extends GeneratedMessageV3.ExtendableBuilder<MessageType, BuilderType>>
-
addRepeatedField
Description copied from interface:Message.BuilderLikesetRepeatedField, but appends the value as a new element.- Specified by:
addRepeatedFieldin interfaceMessage.Builder- Overrides:
addRepeatedFieldin classGeneratedMessageV3.Builder<BuilderType extends GeneratedMessageV3.ExtendableBuilder<MessageType, BuilderType>>
-
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.- Specified by:
newBuilderForFieldin interfaceMessage.Builder- Overrides:
newBuilderForFieldin classGeneratedMessageV3.Builder<BuilderType extends GeneratedMessageV3.ExtendableBuilder<MessageType, BuilderType>>
-
mergeExtensionFields
-
parseUnknownField
protected boolean parseUnknownField(CodedInputStream input, ExtensionRegistryLite extensionRegistry, int tag) throws IOException Description copied from class:GeneratedMessageV3.BuilderCalled by generated subclasses to parse an unknown field.- Overrides:
parseUnknownFieldin classGeneratedMessageV3.Builder<BuilderType extends GeneratedMessageV3.ExtendableBuilder<MessageType, BuilderType>>- Returns:
trueunless the tag is an end-group tag.- Throws:
IOException
-
verifyContainingType
-