Package com.google.protobuf
Class GeneratedMessage.ExtendableBuilder<MessageType extends GeneratedMessage.ExtendableMessage,BuilderType extends GeneratedMessage.ExtendableBuilder<MessageType,BuilderType>>
- java.lang.Object
-
- com.google.protobuf.AbstractMessageLite.Builder
-
- com.google.protobuf.AbstractMessage.Builder<BuilderType>
-
- com.google.protobuf.GeneratedMessage.Builder<BuilderType>
-
- com.google.protobuf.GeneratedMessage.ExtendableBuilder<MessageType,BuilderType>
-
- All Implemented Interfaces:
GeneratedMessage.ExtendableMessageOrBuilder<MessageType>
,Message.Builder
,MessageLite.Builder
,MessageLiteOrBuilder
,MessageOrBuilder
,java.lang.Cloneable
- Enclosing class:
- GeneratedMessage
public abstract static class GeneratedMessage.ExtendableBuilder<MessageType extends GeneratedMessage.ExtendableMessage,BuilderType extends 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
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
GeneratedMessage.ExtendableMessage
.
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
ExtendableBuilder()
protected
ExtendableBuilder(GeneratedMessage.BuilderParent parent)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description <Type> BuilderType
addExtension(Extension<MessageType,java.util.List<Type>> extension, Type value)
Append a value to a repeated extension.<Type> BuilderType
addExtension(ExtensionLite<MessageType,java.util.List<Type>> extensionLite, Type value)
Append a value to a repeated extension.<Type> BuilderType
addExtension(GeneratedMessage.GeneratedExtension<MessageType,java.util.List<Type>> extension, Type value)
Append a value to a repeated extension.BuilderType
addRepeatedField(Descriptors.FieldDescriptor field, java.lang.Object value)
LikesetRepeatedField
, but appends the value as a new element.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.<Type> BuilderType
clearExtension(Extension<MessageType,?> extension)
Clear an extension.<Type> BuilderType
clearExtension(ExtensionLite<MessageType,?> extensionLite)
Clear an extension.<Type> BuilderType
clearExtension(GeneratedMessage.GeneratedExtension<MessageType,?> extension)
Clear an extension.BuilderType
clearField(Descriptors.FieldDescriptor field)
Clears the field.BuilderType
clone()
Clones the Builder.protected boolean
extensionsAreInitialized()
Called by subclasses to check if all extensions are initialized.java.util.Map<Descriptors.FieldDescriptor,java.lang.Object>
getAllFields()
Returns a collection of all the fields in this message which are set and their corresponding values.<Type> Type
getExtension(Extension<MessageType,java.util.List<Type>> extension, int index)
Get the value of an extension.<Type> Type
getExtension(Extension<MessageType,Type> extension)
Get the value of an extension.<Type> Type
getExtension(ExtensionLite<MessageType,java.util.List<Type>> extensionLite, int index)
Get one element of a repeated extension.<Type> Type
getExtension(ExtensionLite<MessageType,Type> extensionLite)
Get the value of an extension.<Type> Type
getExtension(GeneratedMessage.GeneratedExtension<MessageType,java.util.List<Type>> extension, int index)
Get the value of an extension.<Type> Type
getExtension(GeneratedMessage.GeneratedExtension<MessageType,Type> extension)
Get the value of an extension.<Type> int
getExtensionCount(Extension<MessageType,java.util.List<Type>> extension)
Get the number of elements in a repeated extension.<Type> int
getExtensionCount(ExtensionLite<MessageType,java.util.List<Type>> extensionLite)
Get the number of elements in a repeated extension.<Type> int
getExtensionCount(GeneratedMessage.GeneratedExtension<MessageType,java.util.List<Type>> extension)
Get the number of elements in a repeated extension.java.lang.Object
getField(Descriptors.FieldDescriptor field)
Obtains the value of the given field, or the default value if it is not set.java.lang.Object
getRepeatedField(Descriptors.FieldDescriptor field, int index)
Gets an element of a repeated field.int
getRepeatedFieldCount(Descriptors.FieldDescriptor field)
Gets the number of elements of a repeated field.<Type> boolean
hasExtension(Extension<MessageType,Type> extension)
Check if a singular extension is present.<Type> boolean
hasExtension(ExtensionLite<MessageType,Type> extensionLite)
Check if a singular extension is present.<Type> boolean
hasExtension(GeneratedMessage.GeneratedExtension<MessageType,Type> extension)
Check if a singular extension is present.boolean
hasField(Descriptors.FieldDescriptor field)
Returns true if the given field is set.boolean
isInitialized()
Returns true if all required fields in the message and all embedded messages are set, false otherwise.protected void
mergeExtensionFields(GeneratedMessage.ExtendableMessage other)
protected boolean
parseUnknownField(CodedInputStream input, UnknownFieldSet.Builder unknownFields, ExtensionRegistryLite extensionRegistry, int tag)
Called by subclasses to parse an unknown field or an extension.<Type> BuilderType
setExtension(Extension<MessageType,java.util.List<Type>> extension, int index, Type value)
Set the value of one element of a repeated extension.<Type> BuilderType
setExtension(Extension<MessageType,Type> extension, Type value)
Set the value of an extension.<Type> BuilderType
setExtension(ExtensionLite<MessageType,java.util.List<Type>> extensionLite, int index, Type value)
Set the value of one element of a repeated extension.<Type> BuilderType
setExtension(ExtensionLite<MessageType,Type> extensionLite, Type value)
Set the value of an extension.<Type> BuilderType
setExtension(GeneratedMessage.GeneratedExtension<MessageType,java.util.List<Type>> extension, int index, Type value)
Set the value of one element of a repeated extension.<Type> BuilderType
setExtension(GeneratedMessage.GeneratedExtension<MessageType,Type> extension, Type value)
Set the value of an extension.BuilderType
setField(Descriptors.FieldDescriptor field, java.lang.Object value)
Sets a field to the given value.BuilderType
setRepeatedField(Descriptors.FieldDescriptor field, int index, java.lang.Object value)
Sets an element of a repeated field to the given value.-
Methods inherited from class com.google.protobuf.GeneratedMessage.Builder
clearOneof, getDescriptorForType, getFieldBuilder, getOneofFieldDescriptor, getParentForChildren, getRepeatedFieldBuilder, getUnknownFields, hasOneof, internalGetFieldAccessorTable, internalGetMapField, internalGetMutableMapField, isClean, markClean, mergeUnknownFields, newBuilderForField, onBuilt, onChanged, setUnknownFields
-
Methods inherited from class com.google.protobuf.AbstractMessage.Builder
findInitializationErrors, getInitializationErrorString, getUnknownFieldSetBuilder, internalMergeFrom, mergeFrom, mergeFrom, mergeFrom, mergeFrom, mergeFrom, mergeFrom, mergeFrom, mergeFrom, mergeFrom, mergeFrom, mergeFrom, newUninitializedMessageException, setUnknownFieldSetBuilder, toString
-
Methods inherited from class com.google.protobuf.AbstractMessageLite.Builder
addAll, addAll, mergeDelimitedFrom, mergeDelimitedFrom, mergeFrom, newUninitializedMessageException
-
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface com.google.protobuf.GeneratedMessage.ExtendableMessageOrBuilder
getDefaultInstanceForType
-
Methods inherited from interface com.google.protobuf.Message.Builder
build, buildPartial, mergeDelimitedFrom, mergeDelimitedFrom
-
Methods inherited from interface com.google.protobuf.MessageLite.Builder
mergeFrom
-
Methods inherited from interface com.google.protobuf.MessageOrBuilder
findInitializationErrors, getInitializationErrorString, getOneofFieldDescriptor, getUnknownFields, hasOneof
-
-
-
-
Constructor Detail
-
ExtendableBuilder
protected ExtendableBuilder()
-
ExtendableBuilder
protected ExtendableBuilder(GeneratedMessage.BuilderParent parent)
-
-
Method Detail
-
clear
public BuilderType clear()
Description copied from class:GeneratedMessage.Builder
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 classGeneratedMessage.Builder<BuilderType extends GeneratedMessage.ExtendableBuilder<MessageType,BuilderType>>
-
clone
public BuilderType clone()
Description copied from interface:MessageLite.Builder
Clones the Builder.- Specified by:
clone
in interfaceMessage.Builder
- Specified by:
clone
in interfaceMessageLite.Builder
- Overrides:
clone
in classGeneratedMessage.Builder<BuilderType extends GeneratedMessage.ExtendableBuilder<MessageType,BuilderType>>
- See Also:
Object.clone()
-
hasExtension
public final <Type> boolean hasExtension(ExtensionLite<MessageType,Type> extensionLite)
Check if a singular extension is present.- Specified by:
hasExtension
in interfaceGeneratedMessage.ExtendableMessageOrBuilder<MessageType extends GeneratedMessage.ExtendableMessage>
-
getExtensionCount
public final <Type> int getExtensionCount(ExtensionLite<MessageType,java.util.List<Type>> extensionLite)
Get the number of elements in a repeated extension.- Specified by:
getExtensionCount
in interfaceGeneratedMessage.ExtendableMessageOrBuilder<MessageType extends GeneratedMessage.ExtendableMessage>
-
getExtension
public final <Type> Type getExtension(ExtensionLite<MessageType,Type> extensionLite)
Get the value of an extension.- Specified by:
getExtension
in interfaceGeneratedMessage.ExtendableMessageOrBuilder<MessageType extends GeneratedMessage.ExtendableMessage>
-
getExtension
public final <Type> Type getExtension(ExtensionLite<MessageType,java.util.List<Type>> extensionLite, int index)
Get one element of a repeated extension.- Specified by:
getExtension
in interfaceGeneratedMessage.ExtendableMessageOrBuilder<MessageType extends GeneratedMessage.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,java.util.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,java.util.List<Type>> extensionLite, Type value)
Append a value to a repeated extension.
-
clearExtension
public final <Type> BuilderType clearExtension(ExtensionLite<MessageType,?> extensionLite)
Clear an extension.
-
hasExtension
public final <Type> boolean hasExtension(Extension<MessageType,Type> extension)
Check if a singular extension is present.- Specified by:
hasExtension
in interfaceGeneratedMessage.ExtendableMessageOrBuilder<MessageType extends GeneratedMessage.ExtendableMessage>
-
hasExtension
public final <Type> boolean hasExtension(GeneratedMessage.GeneratedExtension<MessageType,Type> extension)
Check if a singular extension is present.- Specified by:
hasExtension
in interfaceGeneratedMessage.ExtendableMessageOrBuilder<MessageType extends GeneratedMessage.ExtendableMessage>
-
getExtensionCount
public final <Type> int getExtensionCount(Extension<MessageType,java.util.List<Type>> extension)
Get the number of elements in a repeated extension.- Specified by:
getExtensionCount
in interfaceGeneratedMessage.ExtendableMessageOrBuilder<MessageType extends GeneratedMessage.ExtendableMessage>
-
getExtensionCount
public final <Type> int getExtensionCount(GeneratedMessage.GeneratedExtension<MessageType,java.util.List<Type>> extension)
Get the number of elements in a repeated extension.- Specified by:
getExtensionCount
in interfaceGeneratedMessage.ExtendableMessageOrBuilder<MessageType extends GeneratedMessage.ExtendableMessage>
-
getExtension
public final <Type> Type getExtension(Extension<MessageType,Type> extension)
Get the value of an extension.- Specified by:
getExtension
in interfaceGeneratedMessage.ExtendableMessageOrBuilder<MessageType extends GeneratedMessage.ExtendableMessage>
-
getExtension
public final <Type> Type getExtension(GeneratedMessage.GeneratedExtension<MessageType,Type> extension)
Get the value of an extension.- Specified by:
getExtension
in interfaceGeneratedMessage.ExtendableMessageOrBuilder<MessageType extends GeneratedMessage.ExtendableMessage>
-
getExtension
public final <Type> Type getExtension(Extension<MessageType,java.util.List<Type>> extension, int index)
Get the value of an extension.- Specified by:
getExtension
in interfaceGeneratedMessage.ExtendableMessageOrBuilder<MessageType extends GeneratedMessage.ExtendableMessage>
-
getExtension
public final <Type> Type getExtension(GeneratedMessage.GeneratedExtension<MessageType,java.util.List<Type>> extension, int index)
Get the value of an extension.- Specified by:
getExtension
in interfaceGeneratedMessage.ExtendableMessageOrBuilder<MessageType extends GeneratedMessage.ExtendableMessage>
-
setExtension
public final <Type> BuilderType setExtension(Extension<MessageType,Type> extension, Type value)
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,java.util.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,java.util.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,java.util.List<Type>> extension, Type value)
Append a value to a repeated extension.
-
addExtension
public <Type> BuilderType addExtension(GeneratedMessage.GeneratedExtension<MessageType,java.util.List<Type>> extension, Type value)
Append a value to a repeated extension.
-
clearExtension
public final <Type> BuilderType clearExtension(Extension<MessageType,?> extension)
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.
-
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.- Specified by:
isInitialized
in interfaceMessageLiteOrBuilder
- Overrides:
isInitialized
in classGeneratedMessage.Builder<BuilderType extends GeneratedMessage.ExtendableBuilder<MessageType,BuilderType>>
-
parseUnknownField
protected boolean parseUnknownField(CodedInputStream input, UnknownFieldSet.Builder unknownFields, ExtensionRegistryLite extensionRegistry, int tag) throws java.io.IOException
Called by subclasses to parse an unknown field or an extension.- Overrides:
parseUnknownField
in classGeneratedMessage.Builder<BuilderType extends GeneratedMessage.ExtendableBuilder<MessageType,BuilderType>>
- Returns:
true
unless the tag is an end-group tag.- Throws:
java.io.IOException
-
getAllFields
public java.util.Map<Descriptors.FieldDescriptor,java.lang.Object> 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.- Specified by:
getAllFields
in interfaceMessageOrBuilder
- Overrides:
getAllFields
in classGeneratedMessage.Builder<BuilderType extends GeneratedMessage.ExtendableBuilder<MessageType,BuilderType>>
-
getField
public java.lang.Object getField(Descriptors.FieldDescriptor field)
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.- Specified by:
getField
in interfaceMessageOrBuilder
- Overrides:
getField
in classGeneratedMessage.Builder<BuilderType extends GeneratedMessage.ExtendableBuilder<MessageType,BuilderType>>
-
getRepeatedFieldCount
public int getRepeatedFieldCount(Descriptors.FieldDescriptor field)
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.- Specified by:
getRepeatedFieldCount
in interfaceMessageOrBuilder
- Overrides:
getRepeatedFieldCount
in classGeneratedMessage.Builder<BuilderType extends GeneratedMessage.ExtendableBuilder<MessageType,BuilderType>>
-
getRepeatedField
public java.lang.Object getRepeatedField(Descriptors.FieldDescriptor field, int index)
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.- Specified by:
getRepeatedField
in interfaceMessageOrBuilder
- Overrides:
getRepeatedField
in classGeneratedMessage.Builder<BuilderType extends GeneratedMessage.ExtendableBuilder<MessageType,BuilderType>>
-
hasField
public boolean hasField(Descriptors.FieldDescriptor field)
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. The return value of hasField() is semantically meaningful only for fields where field.hasPresence() == true.- Specified by:
hasField
in interfaceMessageOrBuilder
- Overrides:
hasField
in classGeneratedMessage.Builder<BuilderType extends GeneratedMessage.ExtendableBuilder<MessageType,BuilderType>>
-
setField
public BuilderType setField(Descriptors.FieldDescriptor field, java.lang.Object value)
Description copied from interface:Message.Builder
Sets a field to the given value. The value must be of the correct type for this field, that is, the same type thatMessageOrBuilder.getField(Descriptors.FieldDescriptor)
returns.- Specified by:
setField
in interfaceMessage.Builder
- Overrides:
setField
in classGeneratedMessage.Builder<BuilderType extends GeneratedMessage.ExtendableBuilder<MessageType,BuilderType>>
-
clearField
public BuilderType clearField(Descriptors.FieldDescriptor field)
Description copied from interface:Message.Builder
Clears the field. This is exactly equivalent to calling the generated "clear" accessor method corresponding to the field.- Specified by:
clearField
in interfaceMessage.Builder
- Overrides:
clearField
in classGeneratedMessage.Builder<BuilderType extends GeneratedMessage.ExtendableBuilder<MessageType,BuilderType>>
-
setRepeatedField
public BuilderType setRepeatedField(Descriptors.FieldDescriptor field, int index, java.lang.Object value)
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; that is, the same type thatMessageOrBuilder.getRepeatedField(Descriptors.FieldDescriptor,int)
returns.- Specified by:
setRepeatedField
in interfaceMessage.Builder
- Overrides:
setRepeatedField
in classGeneratedMessage.Builder<BuilderType extends GeneratedMessage.ExtendableBuilder<MessageType,BuilderType>>
-
addRepeatedField
public BuilderType addRepeatedField(Descriptors.FieldDescriptor field, java.lang.Object value)
Description copied from interface:Message.Builder
LikesetRepeatedField
, but appends the value as a new element.- Specified by:
addRepeatedField
in interfaceMessage.Builder
- Overrides:
addRepeatedField
in classGeneratedMessage.Builder<BuilderType extends GeneratedMessage.ExtendableBuilder<MessageType,BuilderType>>
-
mergeExtensionFields
protected final void mergeExtensionFields(GeneratedMessage.ExtendableMessage other)
-
-