public abstract static class GeneratedMessageLite.ExtendableBuilder<MessageType extends GeneratedMessageLite.ExtendableMessage<MessageType,BuilderType>,BuilderType extends GeneratedMessageLite.ExtendableBuilder<MessageType,BuilderType>> extends GeneratedMessageLite.Builder<MessageType,BuilderType> implements GeneratedMessageLite.ExtendableMessageOrBuilder<MessageType,BuilderType>
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 GeneratedMessageLite.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();
instance, isBuilt
Modifier | Constructor and Description |
---|---|
protected |
ExtendableBuilder(MessageType defaultInstance) |
Modifier and Type | Method and Description |
---|---|
<Type> BuilderType |
addExtension(ExtensionLite<MessageType,List<Type>> extension,
Type value)
Append a value to a repeated extension.
|
MessageType |
buildPartial()
Like
MessageLite.Builder.build() , but does not throw an exception if the message is missing required fields. |
<Type> BuilderType |
clearExtension(ExtensionLite<MessageType,?> extension)
Clear an extension.
|
BuilderType |
clone()
Creates and returns a copy of this object.
|
protected void |
copyOnWrite()
Called before any method that would mutate the builder to ensure that it correctly copies any state before
the write happens to preserve immutability guarantees.
|
<Type> Type |
getExtension(ExtensionLite<MessageType,List<Type>> extension,
int index)
Get one element of a repeated extension.
|
<Type> Type |
getExtension(ExtensionLite<MessageType,Type> extension)
Get the value of an extension.
|
<Type> int |
getExtensionCount(ExtensionLite<MessageType,List<Type>> extension)
Get the number of elements in a repeated extension.
|
<Type> boolean |
hasExtension(ExtensionLite<MessageType,Type> extension)
Check if a singular extension is present.
|
<Type> BuilderType |
setExtension(ExtensionLite<MessageType,List<Type>> extension,
int index,
Type value)
Set the value of one element of a repeated extension.
|
<Type> BuilderType |
setExtension(ExtensionLite<MessageType,Type> extension,
Type value)
Set the value of an extension.
|
build, clear, getDefaultInstanceForType, internalMergeFrom, isInitialized, mergeFrom, mergeFrom
addAll, mergeDelimitedFrom, mergeDelimitedFrom, mergeFrom, mergeFrom, mergeFrom, mergeFrom, mergeFrom, mergeFrom, mergeFrom, mergeFrom, mergeFrom, mergeFrom, newUninitializedMessageException
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
getDefaultInstanceForType, isInitialized
protected ExtendableBuilder(MessageType defaultInstance)
public final <Type> BuilderType addExtension(ExtensionLite<MessageType,List<Type>> extension, Type value)
public final MessageType buildPartial()
MessageLite.Builder
MessageLite.Builder.build()
, but does not throw an exception if the message is missing required fields. Instead, a
partial message is returned. Subsequent changes to the Builder will not affect the returned message.buildPartial
in interface MessageLite.Builder
buildPartial
in class GeneratedMessageLite.Builder<MessageType extends GeneratedMessageLite.ExtendableMessage<MessageType,BuilderType>,BuilderType extends GeneratedMessageLite.ExtendableBuilder<MessageType,BuilderType>>
public final <Type> BuilderType clearExtension(ExtensionLite<MessageType,?> extension)
public BuilderType clone()
Object
x
, the expression: will be true, and that the expression:x.clone() != x
will bex.clone().getClass() == x.getClass()
true
, but these are not absolute requirements. While it is
typically the case that: will bex.clone().equals(x)
true
, this is not an absolute requirement.
By convention, the returned object should be obtained by calling super.clone
. If a class
and all of its superclasses (except Object
) obey this convention, it will be the case
that x.clone().getClass() == x.getClass()
.
By convention, the object returned by this method should be independent of this object (which is
being cloned). To achieve this independence, it may be necessary to modify one or more fields of
the object returned by super.clone
before returning it. Typically, this means copying any
mutable objects that comprise the internal "deep structure" of the object being cloned and
replacing the references to these objects with references to the copies. If a class contains only
primitive fields or references to immutable objects, then it is usually the case that no fields
in the object returned by super.clone
need to be modified.
The method clone
for class Object
performs a specific cloning operation. First,
if the class of this object does not implement the interface Cloneable
, then a
CloneNotSupportedException
is thrown. Note that all arrays are considered to implement
the interface Cloneable
and that the return type of the clone
method of an array
type T[]
is T[]
where T is any reference or primitive type. Otherwise, this
method creates a new instance of the class of this object and initializes all its fields with
exactly the contents of the corresponding fields of this object, as if by assignment; the
contents of the fields are not themselves cloned. Thus, this method performs a "shallow copy" of
this object, not a "deep copy" operation.
The class Object
does not itself implement the interface Cloneable
, so calling
the clone
method on an object whose class is Object
will result in throwing an
exception at run time.
clone
in interface MessageLite.Builder
clone
in class GeneratedMessageLite.Builder<MessageType extends GeneratedMessageLite.ExtendableMessage<MessageType,BuilderType>,BuilderType extends GeneratedMessageLite.ExtendableBuilder<MessageType,BuilderType>>
Cloneable
protected void copyOnWrite()
GeneratedMessageLite.Builder
copyOnWrite
in class GeneratedMessageLite.Builder<MessageType extends GeneratedMessageLite.ExtendableMessage<MessageType,BuilderType>,BuilderType extends GeneratedMessageLite.ExtendableBuilder<MessageType,BuilderType>>
public final <Type> Type getExtension(ExtensionLite<MessageType,List<Type>> extension, int index)
getExtension
in interface GeneratedMessageLite.ExtendableMessageOrBuilder<MessageType extends GeneratedMessageLite.ExtendableMessage<MessageType,BuilderType>,BuilderType extends GeneratedMessageLite.ExtendableBuilder<MessageType,BuilderType>>
public final <Type> Type getExtension(ExtensionLite<MessageType,Type> extension)
getExtension
in interface GeneratedMessageLite.ExtendableMessageOrBuilder<MessageType extends GeneratedMessageLite.ExtendableMessage<MessageType,BuilderType>,BuilderType extends GeneratedMessageLite.ExtendableBuilder<MessageType,BuilderType>>
public final <Type> int getExtensionCount(ExtensionLite<MessageType,List<Type>> extension)
getExtensionCount
in interface GeneratedMessageLite.ExtendableMessageOrBuilder<MessageType extends GeneratedMessageLite.ExtendableMessage<MessageType,BuilderType>,BuilderType extends GeneratedMessageLite.ExtendableBuilder<MessageType,BuilderType>>
public final <Type> boolean hasExtension(ExtensionLite<MessageType,Type> extension)
hasExtension
in interface GeneratedMessageLite.ExtendableMessageOrBuilder<MessageType extends GeneratedMessageLite.ExtendableMessage<MessageType,BuilderType>,BuilderType extends GeneratedMessageLite.ExtendableBuilder<MessageType,BuilderType>>
public final <Type> BuilderType setExtension(ExtensionLite<MessageType,List<Type>> extension, int index, Type value)
public final <Type> BuilderType setExtension(ExtensionLite<MessageType,Type> extension, Type value)