public abstract static class GeneratedMessageV3.ExtendableBuilder<MessageType extends GeneratedMessageV3.ExtendableMessage,BuilderType extends GeneratedMessageV3.ExtendableBuilder<MessageType,BuilderType>> extends GeneratedMessageV3.Builder<BuilderType> implements GeneratedMessageV3.ExtendableMessageOrBuilder<MessageType>
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
.
Modifier | Constructor and Description |
---|---|
protected |
ExtendableBuilder() |
protected |
ExtendableBuilder(GeneratedMessageV3.BuilderParent parent) |
Modifier and Type | Method and 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)
Like
setRepeatedField , 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.
|
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(GeneratedMessageV3.ExtendableMessage other) |
Message.Builder |
newBuilderForField(Descriptors.FieldDescriptor field)
Create a builder for messages of the appropriate type for the given field.
|
<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.
|
clearOneof, clone, getDescriptorForType, getFieldBuilder, getOneofFieldDescriptor, getParentForChildren, getRepeatedFieldBuilder, getUnknownFields, hasOneof, internalGetFieldAccessorTable, internalGetMapField, internalGetMutableMapField, isClean, markClean, mergeUnknownFields, onBuilt, onChanged, setUnknownFields, setUnknownFieldsProto3
findInitializationErrors, getInitializationErrorString, internalMergeFrom, mergeDelimitedFrom, mergeDelimitedFrom, mergeFrom, mergeFrom, mergeFrom, mergeFrom, mergeFrom, mergeFrom, mergeFrom, mergeFrom, mergeFrom, mergeFrom, mergeFrom, newUninitializedMessageException, toString
addAll, addAll, mergeFrom, newUninitializedMessageException
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
getDefaultInstanceForType
findInitializationErrors, getDescriptorForType, getInitializationErrorString, getOneofFieldDescriptor, getUnknownFields, hasOneof
build, buildPartial
mergeFrom
protected ExtendableBuilder()
protected ExtendableBuilder(GeneratedMessageV3.BuilderParent parent)
public BuilderType clear()
GeneratedMessageV3.Builder
clear
in interface Message.Builder
clear
in interface MessageLite.Builder
clear
in class GeneratedMessageV3.Builder<BuilderType extends GeneratedMessageV3.ExtendableBuilder<MessageType,BuilderType>>
public final <Type> boolean hasExtension(ExtensionLite<MessageType,Type> extensionLite)
hasExtension
in interface GeneratedMessageV3.ExtendableMessageOrBuilder<MessageType extends GeneratedMessageV3.ExtendableMessage>
public final <Type> int getExtensionCount(ExtensionLite<MessageType,java.util.List<Type>> extensionLite)
getExtensionCount
in interface GeneratedMessageV3.ExtendableMessageOrBuilder<MessageType extends GeneratedMessageV3.ExtendableMessage>
public final <Type> Type getExtension(ExtensionLite<MessageType,Type> extensionLite)
getExtension
in interface GeneratedMessageV3.ExtendableMessageOrBuilder<MessageType extends GeneratedMessageV3.ExtendableMessage>
public final <Type> Type getExtension(ExtensionLite<MessageType,java.util.List<Type>> extensionLite, int index)
getExtension
in interface GeneratedMessageV3.ExtendableMessageOrBuilder<MessageType extends GeneratedMessageV3.ExtendableMessage>
public final <Type> BuilderType setExtension(ExtensionLite<MessageType,Type> extensionLite, Type value)
public final <Type> BuilderType setExtension(ExtensionLite<MessageType,java.util.List<Type>> extensionLite, int index, Type value)
public final <Type> BuilderType addExtension(ExtensionLite<MessageType,java.util.List<Type>> extensionLite, Type value)
public final <Type> BuilderType clearExtension(ExtensionLite<MessageType,?> extensionLite)
public final <Type> boolean hasExtension(Extension<MessageType,Type> extension)
hasExtension
in interface GeneratedMessageV3.ExtendableMessageOrBuilder<MessageType extends GeneratedMessageV3.ExtendableMessage>
public final <Type> boolean hasExtension(GeneratedMessage.GeneratedExtension<MessageType,Type> extension)
hasExtension
in interface GeneratedMessageV3.ExtendableMessageOrBuilder<MessageType extends GeneratedMessageV3.ExtendableMessage>
public final <Type> int getExtensionCount(Extension<MessageType,java.util.List<Type>> extension)
getExtensionCount
in interface GeneratedMessageV3.ExtendableMessageOrBuilder<MessageType extends GeneratedMessageV3.ExtendableMessage>
public final <Type> int getExtensionCount(GeneratedMessage.GeneratedExtension<MessageType,java.util.List<Type>> extension)
getExtensionCount
in interface GeneratedMessageV3.ExtendableMessageOrBuilder<MessageType extends GeneratedMessageV3.ExtendableMessage>
public final <Type> Type getExtension(Extension<MessageType,Type> extension)
getExtension
in interface GeneratedMessageV3.ExtendableMessageOrBuilder<MessageType extends GeneratedMessageV3.ExtendableMessage>
public final <Type> Type getExtension(GeneratedMessage.GeneratedExtension<MessageType,Type> extension)
getExtension
in interface GeneratedMessageV3.ExtendableMessageOrBuilder<MessageType extends GeneratedMessageV3.ExtendableMessage>
public final <Type> Type getExtension(Extension<MessageType,java.util.List<Type>> extension, int index)
getExtension
in interface GeneratedMessageV3.ExtendableMessageOrBuilder<MessageType extends GeneratedMessageV3.ExtendableMessage>
public final <Type> Type getExtension(GeneratedMessage.GeneratedExtension<MessageType,java.util.List<Type>> extension, int index)
getExtension
in interface GeneratedMessageV3.ExtendableMessageOrBuilder<MessageType extends GeneratedMessageV3.ExtendableMessage>
public final <Type> BuilderType setExtension(Extension<MessageType,Type> extension, Type value)
public <Type> BuilderType setExtension(GeneratedMessage.GeneratedExtension<MessageType,Type> extension, Type value)
public final <Type> BuilderType setExtension(Extension<MessageType,java.util.List<Type>> extension, int index, Type value)
public <Type> BuilderType setExtension(GeneratedMessage.GeneratedExtension<MessageType,java.util.List<Type>> extension, int index, Type value)
public final <Type> BuilderType addExtension(Extension<MessageType,java.util.List<Type>> extension, Type value)
public <Type> BuilderType addExtension(GeneratedMessage.GeneratedExtension<MessageType,java.util.List<Type>> extension, Type value)
public final <Type> BuilderType clearExtension(Extension<MessageType,?> extension)
public <Type> BuilderType clearExtension(GeneratedMessage.GeneratedExtension<MessageType,?> extension)
protected boolean extensionsAreInitialized()
public boolean isInitialized()
MessageLiteOrBuilder
isInitialized
in interface MessageLiteOrBuilder
isInitialized
in class GeneratedMessageV3.Builder<BuilderType extends GeneratedMessageV3.ExtendableBuilder<MessageType,BuilderType>>
public java.util.Map<Descriptors.FieldDescriptor,java.lang.Object> getAllFields()
MessageOrBuilder
MessageOrBuilder.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. getAllFields
in interface MessageOrBuilder
getAllFields
in class GeneratedMessageV3.Builder<BuilderType extends GeneratedMessageV3.ExtendableBuilder<MessageType,BuilderType>>
public java.lang.Object getField(Descriptors.FieldDescriptor field)
MessageOrBuilder
getField
in interface MessageOrBuilder
getField
in class GeneratedMessageV3.Builder<BuilderType extends GeneratedMessageV3.ExtendableBuilder<MessageType,BuilderType>>
public int getRepeatedFieldCount(Descriptors.FieldDescriptor field)
MessageOrBuilder
getRepeatedFieldCount
in interface MessageOrBuilder
getRepeatedFieldCount
in class GeneratedMessageV3.Builder<BuilderType extends GeneratedMessageV3.ExtendableBuilder<MessageType,BuilderType>>
public java.lang.Object getRepeatedField(Descriptors.FieldDescriptor field, int index)
MessageOrBuilder
getRepeatedField
in interface MessageOrBuilder
getRepeatedField
in class GeneratedMessageV3.Builder<BuilderType extends GeneratedMessageV3.ExtendableBuilder<MessageType,BuilderType>>
public boolean hasField(Descriptors.FieldDescriptor field)
MessageOrBuilder
hasField
in interface MessageOrBuilder
hasField
in class GeneratedMessageV3.Builder<BuilderType extends GeneratedMessageV3.ExtendableBuilder<MessageType,BuilderType>>
public BuilderType setField(Descriptors.FieldDescriptor field, java.lang.Object value)
Message.Builder
MessageOrBuilder.getField(Descriptors.FieldDescriptor)
would return.setField
in interface Message.Builder
setField
in class GeneratedMessageV3.Builder<BuilderType extends GeneratedMessageV3.ExtendableBuilder<MessageType,BuilderType>>
public BuilderType clearField(Descriptors.FieldDescriptor field)
Message.Builder
clearField
in interface Message.Builder
clearField
in class GeneratedMessageV3.Builder<BuilderType extends GeneratedMessageV3.ExtendableBuilder<MessageType,BuilderType>>
public BuilderType setRepeatedField(Descriptors.FieldDescriptor field, int index, java.lang.Object value)
Message.Builder
MessageOrBuilder.getRepeatedField(Descriptors.FieldDescriptor,int)
would return.setRepeatedField
in interface Message.Builder
setRepeatedField
in class GeneratedMessageV3.Builder<BuilderType extends GeneratedMessageV3.ExtendableBuilder<MessageType,BuilderType>>
public BuilderType addRepeatedField(Descriptors.FieldDescriptor field, java.lang.Object value)
Message.Builder
setRepeatedField
, but appends the value as a new element.addRepeatedField
in interface Message.Builder
addRepeatedField
in class GeneratedMessageV3.Builder<BuilderType extends GeneratedMessageV3.ExtendableBuilder<MessageType,BuilderType>>
public Message.Builder newBuilderForField(Descriptors.FieldDescriptor field)
Message.Builder
Message.Builder.setField(Descriptors.FieldDescriptor, Object)
,
Message.Builder.setRepeatedField(Descriptors.FieldDescriptor, int, Object)
, or
Message.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.
newBuilderForField
in interface Message.Builder
newBuilderForField
in class GeneratedMessageV3.Builder<BuilderType extends GeneratedMessageV3.ExtendableBuilder<MessageType,BuilderType>>
protected final void mergeExtensionFields(GeneratedMessageV3.ExtendableMessage other)
Copyright © 2014–2024 The Apache Software Foundation. All rights reserved.