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

Name Description
MessageType
BuilderType

Constructors

ExtendableBuilder()

protected ExtendableBuilder()

ExtendableBuilder(GeneratedMessageV3.BuilderParent parent)

protected ExtendableBuilder(GeneratedMessageV3.BuilderParent parent)
Parameter
Name Description
parent GeneratedMessageV3.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
Name Description
extension Extension<MessageType,List<Type>>
value Type
Returns
Type Description
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
Name Description
extensionLite ExtensionLite<MessageType,List<Type>>
value Type
Returns
Type Description
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
Name Description
extension GeneratedExtension<MessageType,List<Type>>
value Type
Returns
Type Description
BuilderType

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

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

Clear an extension.

Parameter
Name Description
extension Extension<MessageType,?>
Returns
Type Description
BuilderType

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

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

Clear an extension.

Parameter
Name Description
extension GeneratedExtension<MessageType,?>
Returns
Type Description
BuilderType

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

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

Get the value of an extension.

Parameter
Name Description
extension Extension<MessageType,Type>
Returns
Type Description
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
Name Description
extension Extension<MessageType,List<Type>>
index int
Returns
Type Description
Type

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

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

Get the value of an extension.

Parameter
Name Description
extensionLite ExtensionLite<MessageType,Type>
Returns
Type Description
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
Name Description
extensionLite ExtensionLite<MessageType,List<Type>>
index int
Returns
Type Description
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
Name Description
extension GeneratedExtension<MessageType,Type>
Returns
Type Description
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
Name Description
extension GeneratedExtension<MessageType,List<Type>>
index int
Returns
Type Description
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
Name Description
extension Extension<MessageType,List<Type>>
Returns
Type Description
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
Name Description
extensionLite ExtensionLite<MessageType,List<Type>>
Returns
Type Description
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
Name Description
extension GeneratedExtension<MessageType,List<Type>>
Returns
Type Description
int

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

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

Check if a singular extension is present.

Parameter
Name Description
extension Extension<MessageType,Type>
Returns
Type Description
boolean

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

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

Check if a singular extension is present.

Parameter
Name Description
extensionLite ExtensionLite<MessageType,Type>
Returns
Type Description
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
Name Description
extension GeneratedExtension<MessageType,Type>
Returns
Type Description
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
Name Description
extension Extension<MessageType,Type>
value Type
Returns
Type Description
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
Name Description
extension Extension<MessageType,List<Type>>
index int
value Type
Returns
Type Description
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
Name Description
extensionLite ExtensionLite<MessageType,Type>
value Type
Returns
Type Description
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
Name Description
extensionLite ExtensionLite<MessageType,List<Type>>
index int
value Type
Returns
Type Description
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
Name Description
extension GeneratedExtension<MessageType,Type>
value Type
Returns
Type Description
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
Name Description
extension GeneratedExtension<MessageType,List<Type>>
index int
value Type
Returns
Type Description
BuilderType

addRepeatedField(Descriptors.FieldDescriptor field, Object value)

public BuilderType addRepeatedField(Descriptors.FieldDescriptor field, Object value)
Parameters
Name Description
field Descriptors.FieldDescriptor
value Object
Returns
Type Description
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
Type Description
BuilderType
Overrides

clearExtension(ExtensionLite<MessageType,?> extensionLite)

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

Clear an extension.

Parameter
Name Description
extensionLite ExtensionLite<MessageType,?>
Returns
Type Description
BuilderType

clearField(Descriptors.FieldDescriptor field)

public BuilderType clearField(Descriptors.FieldDescriptor field)
Parameter
Name Description
field Descriptors.FieldDescriptor
Returns
Type Description
BuilderType
Overrides

extensionsAreInitialized()

protected boolean extensionsAreInitialized()

Called by subclasses to check if all extensions are initialized.

Returns
Type Description
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
Type Description
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
Name Description
field Descriptors.FieldDescriptor
Returns
Type Description
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
Name Description
field Descriptors.FieldDescriptor
Returns
Type Description
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
Name Description
field Descriptors.FieldDescriptor
index int
Returns
Type Description
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
Name Description
field Descriptors.FieldDescriptor
index int
Returns
Type Description
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
Name Description
field Descriptors.FieldDescriptor
Returns
Type Description
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
Name Description
field Descriptors.FieldDescriptor
Returns
Type Description
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
Type Description
boolean
Overrides

mergeExtensionFields(GeneratedMessageV3.ExtendableMessage other)

protected final void mergeExtensionFields(GeneratedMessageV3.ExtendableMessage other)
Parameter
Name Description
other ExtendableMessage

newBuilderForField(Descriptors.FieldDescriptor field)

public Message.Builder newBuilderForField(Descriptors.FieldDescriptor field)
Parameter
Name Description
field Descriptors.FieldDescriptor
Returns
Type Description
Message.Builder
Overrides

setField(Descriptors.FieldDescriptor field, Object value)

public BuilderType setField(Descriptors.FieldDescriptor field, Object value)
Parameters
Name Description
field Descriptors.FieldDescriptor
value Object
Returns
Type Description
BuilderType
Overrides

setRepeatedField(Descriptors.FieldDescriptor field, int index, Object value)

public BuilderType setRepeatedField(Descriptors.FieldDescriptor field, int index, Object value)
Parameters
Name Description
field Descriptors.FieldDescriptor
index int
value Object
Returns
Type Description
BuilderType
Overrides