Class GeneratedMessageV3.ExtendableBuilder<MessageType,BuilderType> (3.19.4)

public abstract static class GeneratedMessageV3.ExtendableBuilder<MessageType,BuilderType> extends GeneratedMessageV3.Builder<BuilderType> implements GeneratedMessageV3.ExtendableMessageOrBuilder<MessageType>

Generated message builders for message types that contain extension ranges subclass this.

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 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 ExtendableMessage.

Inheritance

Object > AbstractMessageLite.Builder<MessageType,BuilderType> > AbstractMessage.Builder<BuilderType> > GeneratedMessageV3.Builder > GeneratedMessageV3.ExtendableBuilder<MessageType,BuilderType>

Implements

com.google.protobuf.GeneratedMessageV3.ExtendableMessageOrBuilder<MessageType>

Type Parameters

NameDescription
MessageType
BuilderType

Constructors

ExtendableBuilder()

protected ExtendableBuilder()

ExtendableBuilder(GeneratedMessageV3.BuilderParent parent)

protected ExtendableBuilder(GeneratedMessageV3.BuilderParent parent)
Parameter
NameDescription
parentGeneratedMessageV3.BuilderParent

Methods

<Type>addExtension(Extension<MessageType,List<Type>> extension, Type value)

public final BuilderType <Type>addExtension(Extension<MessageType,List<Type>> extension, Type value)

Append a value to a repeated extension.

Parameters
NameDescription
extensionExtension<MessageType,List<Type>>
valueType
Returns
TypeDescription
BuilderType

<Type>addExtension(ExtensionLite<MessageType,List<Type>> extensionLite, Type value)

public final BuilderType <Type>addExtension(ExtensionLite<MessageType,List<Type>> extensionLite, Type value)

Append a value to a repeated extension.

Parameters
NameDescription
extensionLiteExtensionLite<MessageType,List<Type>>
valueType
Returns
TypeDescription
BuilderType

<Type>addExtension(GeneratedMessage.GeneratedExtension<MessageType,List<Type>> extension, Type value)

public BuilderType <Type>addExtension(GeneratedMessage.GeneratedExtension<MessageType,List<Type>> extension, Type value)

Append a value to a repeated extension.

Parameters
NameDescription
extensionGeneratedExtension<MessageType,List<Type>>
valueType
Returns
TypeDescription
BuilderType

<Type>clearExtension(Extension<MessageType,?> extension)

public final BuilderType <Type>clearExtension(Extension<MessageType,?> extension)

Clear an extension.

Parameter
NameDescription
extensionExtension<MessageType,?>
Returns
TypeDescription
BuilderType

<Type>clearExtension(GeneratedMessage.GeneratedExtension<MessageType,?> extension)

public BuilderType <Type>clearExtension(GeneratedMessage.GeneratedExtension<MessageType,?> extension)

Clear an extension.

Parameter
NameDescription
extensionGeneratedExtension<MessageType,?>
Returns
TypeDescription
BuilderType

<Type>getExtension(Extension<MessageType,Type> extension)

public final Type <Type>getExtension(Extension<MessageType,Type> extension)

Get the value of an extension.

Parameter
NameDescription
extensionExtension<MessageType,Type>
Returns
TypeDescription
Type

<Type>getExtension(Extension<MessageType,List<Type>> extension, int index)

public final Type <Type>getExtension(Extension<MessageType,List<Type>> extension, int index)

Get the value of an extension.

Parameters
NameDescription
extensionExtension<MessageType,List<Type>>
indexint
Returns
TypeDescription
Type

<Type>getExtension(ExtensionLite<MessageType,Type> extensionLite)

public final Type <Type>getExtension(ExtensionLite<MessageType,Type> extensionLite)

Get the value of an extension.

Parameter
NameDescription
extensionLiteExtensionLite<MessageType,Type>
Returns
TypeDescription
Type

<Type>getExtension(ExtensionLite<MessageType,List<Type>> extensionLite, int index)

public final Type <Type>getExtension(ExtensionLite<MessageType,List<Type>> extensionLite, int index)

Get one element of a repeated extension.

Parameters
NameDescription
extensionLiteExtensionLite<MessageType,List<Type>>
indexint
Returns
TypeDescription
Type

<Type>getExtension(GeneratedMessage.GeneratedExtension<MessageType,Type> extension)

public final Type <Type>getExtension(GeneratedMessage.GeneratedExtension<MessageType,Type> extension)

Get the value of an extension.

Parameter
NameDescription
extensionGeneratedExtension<MessageType,Type>
Returns
TypeDescription
Type

<Type>getExtension(GeneratedMessage.GeneratedExtension<MessageType,List<Type>> extension, int index)

public final Type <Type>getExtension(GeneratedMessage.GeneratedExtension<MessageType,List<Type>> extension, int index)

Get the value of an extension.

Parameters
NameDescription
extensionGeneratedExtension<MessageType,List<Type>>
indexint
Returns
TypeDescription
Type

<Type>getExtensionCount(Extension<MessageType,List<Type>> extension)

public final int <Type>getExtensionCount(Extension<MessageType,List<Type>> extension)

Get the number of elements in a repeated extension.

Parameter
NameDescription
extensionExtension<MessageType,List<Type>>
Returns
TypeDescription
int

<Type>getExtensionCount(ExtensionLite<MessageType,List<Type>> extensionLite)

public final int <Type>getExtensionCount(ExtensionLite<MessageType,List<Type>> extensionLite)

Get the number of elements in a repeated extension.

Parameter
NameDescription
extensionLiteExtensionLite<MessageType,List<Type>>
Returns
TypeDescription
int

<Type>getExtensionCount(GeneratedMessage.GeneratedExtension<MessageType,List<Type>> extension)

public final int <Type>getExtensionCount(GeneratedMessage.GeneratedExtension<MessageType,List<Type>> extension)

Get the number of elements in a repeated extension.

Parameter
NameDescription
extensionGeneratedExtension<MessageType,List<Type>>
Returns
TypeDescription
int

<Type>hasExtension(Extension<MessageType,Type> extension)

public final boolean <Type>hasExtension(Extension<MessageType,Type> extension)

Check if a singular extension is present.

Parameter
NameDescription
extensionExtension<MessageType,Type>
Returns
TypeDescription
boolean

<Type>hasExtension(ExtensionLite<MessageType,Type> extensionLite)

public final boolean <Type>hasExtension(ExtensionLite<MessageType,Type> extensionLite)

Check if a singular extension is present.

Parameter
NameDescription
extensionLiteExtensionLite<MessageType,Type>
Returns
TypeDescription
boolean

<Type>hasExtension(GeneratedMessage.GeneratedExtension<MessageType,Type> extension)

public final boolean <Type>hasExtension(GeneratedMessage.GeneratedExtension<MessageType,Type> extension)

Check if a singular extension is present.

Parameter
NameDescription
extensionGeneratedExtension<MessageType,Type>
Returns
TypeDescription
boolean

<Type>setExtension(Extension<MessageType,Type> extension, Type value)

public final BuilderType <Type>setExtension(Extension<MessageType,Type> extension, Type value)

Set the value of an extension.

Parameters
NameDescription
extensionExtension<MessageType,Type>
valueType
Returns
TypeDescription
BuilderType

<Type>setExtension(Extension<MessageType,List<Type>> extension, int index, Type value)

public final BuilderType <Type>setExtension(Extension<MessageType,List<Type>> extension, int index, Type value)

Set the value of one element of a repeated extension.

Parameters
NameDescription
extensionExtension<MessageType,List<Type>>
indexint
valueType
Returns
TypeDescription
BuilderType

<Type>setExtension(ExtensionLite<MessageType,Type> extensionLite, Type value)

public final BuilderType <Type>setExtension(ExtensionLite<MessageType,Type> extensionLite, Type value)

Set the value of an extension.

Parameters
NameDescription
extensionLiteExtensionLite<MessageType,Type>
valueType
Returns
TypeDescription
BuilderType

<Type>setExtension(ExtensionLite<MessageType,List<Type>> extensionLite, int index, Type value)

public final BuilderType <Type>setExtension(ExtensionLite<MessageType,List<Type>> extensionLite, int index, Type value)

Set the value of one element of a repeated extension.

Parameters
NameDescription
extensionLiteExtensionLite<MessageType,List<Type>>
indexint
valueType
Returns
TypeDescription
BuilderType

<Type>setExtension(GeneratedMessage.GeneratedExtension<MessageType,Type> extension, Type value)

public BuilderType <Type>setExtension(GeneratedMessage.GeneratedExtension<MessageType,Type> extension, Type value)

Set the value of an extension.

Parameters
NameDescription
extensionGeneratedExtension<MessageType,Type>
valueType
Returns
TypeDescription
BuilderType

<Type>setExtension(GeneratedMessage.GeneratedExtension<MessageType,List<Type>> extension, int index, Type value)

public BuilderType <Type>setExtension(GeneratedMessage.GeneratedExtension<MessageType,List<Type>> extension, int index, Type value)

Set the value of one element of a repeated extension.

Parameters
NameDescription
extensionGeneratedExtension<MessageType,List<Type>>
indexint
valueType
Returns
TypeDescription
BuilderType

addRepeatedField(Descriptors.FieldDescriptor field, Object value)

public BuilderType addRepeatedField(Descriptors.FieldDescriptor field, Object value)
Parameters
NameDescription
fieldDescriptors.FieldDescriptor
valueObject
Returns
TypeDescription
BuilderType
Overrides

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

clearExtension(ExtensionLite<MessageType,?> extensionLite)

public final BuilderType clearExtension(ExtensionLite<MessageType,?> extensionLite)

Clear an extension.

Parameter
NameDescription
extensionLiteExtensionLite<MessageType,?>
Returns
TypeDescription
BuilderType

clearField(Descriptors.FieldDescriptor field)

public BuilderType clearField(Descriptors.FieldDescriptor field)
Parameter
NameDescription
fieldDescriptors.FieldDescriptor
Returns
TypeDescription
BuilderType
Overrides

extensionsAreInitialized()

protected boolean extensionsAreInitialized()

Called by subclasses to check if all extensions are initialized.

Returns
TypeDescription
boolean

getAllFields()

public Map<Descriptors.FieldDescriptor,Object> getAllFields()

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 calling #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.

Returns
TypeDescription
Map<FieldDescriptor,Object>
Overrides

getField(Descriptors.FieldDescriptor field)

public Object getField(Descriptors.FieldDescriptor field)

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.

Parameter
NameDescription
fieldDescriptors.FieldDescriptor
Returns
TypeDescription
Object
Overrides

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

getRepeatedField(Descriptors.FieldDescriptor field, int index)

public Object getRepeatedField(Descriptors.FieldDescriptor field, int index)

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.

Parameters
NameDescription
fieldDescriptors.FieldDescriptor
indexint
Returns
TypeDescription
Object
Overrides

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)

Gets the number of elements of a repeated field. This is exactly equivalent to calling the generated "Count" accessor method corresponding to the field.

Parameter
NameDescription
fieldDescriptors.FieldDescriptor
Returns
TypeDescription
int
Overrides

hasField(Descriptors.FieldDescriptor field)

public boolean hasField(Descriptors.FieldDescriptor field)

Returns true if the given field is set. This is exactly equivalent to calling the generated "has" accessor method corresponding to the field.

Parameter
NameDescription
fieldDescriptors.FieldDescriptor
Returns
TypeDescription
boolean
Overrides

isInitialized()

public boolean isInitialized()

Returns true if all required fields in the message and all embedded messages are set, false otherwise.

See also: MessageOrBuilder#getInitializationErrorString()

Returns
TypeDescription
boolean
Overrides

mergeExtensionFields(GeneratedMessageV3.ExtendableMessage other)

protected final void mergeExtensionFields(GeneratedMessageV3.ExtendableMessage other)
Parameter
NameDescription
otherExtendableMessage

newBuilderForField(Descriptors.FieldDescriptor field)

public Message.Builder newBuilderForField(Descriptors.FieldDescriptor field)
Parameter
NameDescription
fieldDescriptors.FieldDescriptor
Returns
TypeDescription
Message.Builder
Overrides

setField(Descriptors.FieldDescriptor field, Object value)

public BuilderType setField(Descriptors.FieldDescriptor field, Object value)
Parameters
NameDescription
fieldDescriptors.FieldDescriptor
valueObject
Returns
TypeDescription
BuilderType
Overrides

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
Overrides