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

public abstract static class GeneratedMessage.ExtendableBuilder<MessageType,BuilderType> extends GeneratedMessage.Builder<BuilderType> implements GeneratedMessage.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> > GeneratedMessage.Builder > GeneratedMessage.ExtendableBuilder<MessageType,BuilderType>

Implements

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

Type Parameters

NameDescription
MessageType
BuilderType

Constructors

ExtendableBuilder()

protected ExtendableBuilder()

ExtendableBuilder(GeneratedMessage.BuilderParent parent)

protected ExtendableBuilder(GeneratedMessage.BuilderParent parent)
Parameter
NameDescription
parentGeneratedMessage.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(ExtensionLite<MessageType,?> extensionLite)

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

Clear an extension.

Parameter
NameDescription
extensionLiteExtensionLite<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

clearField(Descriptors.FieldDescriptor field)

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

clone()

public BuilderType clone()

Clones the Builder.

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

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

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(GeneratedMessage.ExtendableMessage other)

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

parseUnknownField(CodedInputStream input, UnknownFieldSet.Builder unknownFields, ExtensionRegistryLite extensionRegistry, int tag)

protected boolean parseUnknownField(CodedInputStream input, UnknownFieldSet.Builder unknownFields, ExtensionRegistryLite extensionRegistry, int tag)

Called by subclasses to parse an unknown field or an extension.

Parameters
NameDescription
inputCodedInputStream
unknownFieldsUnknownFieldSet.Builder
extensionRegistryExtensionRegistryLite
tagint
Returns
TypeDescription
boolean

true unless the tag is an end-group tag.

Overrides
Exceptions
TypeDescription
IOException

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