MType
- the type of message for the fieldBType
- the type of builder for the fieldIType
- the common interface for the message and the builderpublic class SingleFieldBuilder<MType extends GeneratedMessage,BType extends GeneratedMessage.Builder,IType extends MessageOrBuilder>
extends java.lang.Object
SingleFieldBuilder
implements a structure that a protocol
message uses to hold a single field of another protocol message. It supports
the classical use case of setting an immutable Message
as the value
of the field and is highly optimized around this.
Message.Builder
as the field and deferring conversion of that Builder
to an immutable Message
. In this way, it's possible to maintain
a tree of Builder
's that acts as a fully read/write data
structure.
SingleFieldBuilder
and RepeatedFieldBuilder
classes cache messages that were created so that messages only need to be
created when some change occured in its builder or a builder for one of its
descendants.Constructor and Description |
---|
SingleFieldBuilder(MType message,
com.google.protobuf.GeneratedMessage.BuilderParent parent,
boolean isClean) |
Modifier and Type | Method and Description |
---|---|
MType |
build()
Builds the message and returns it.
|
SingleFieldBuilder<MType,BType,IType> |
clear()
Clears the value of the field.
|
void |
dispose() |
BType |
getBuilder()
Gets a builder for the field.
|
MType |
getMessage()
Get the message for the field.
|
IType |
getMessageOrBuilder()
Gets the base class interface for the field.
|
void |
markDirty()
A builder becomes dirty whenever a field is modified -- including fields
in nested builders -- and becomes clean when build() is called.
|
SingleFieldBuilder<MType,BType,IType> |
mergeFrom(MType value)
Merges the field from another field.
|
SingleFieldBuilder<MType,BType,IType> |
setMessage(MType message)
Sets a message for the field replacing any existing value.
|
public SingleFieldBuilder(MType message, com.google.protobuf.GeneratedMessage.BuilderParent parent, boolean isClean)
public void dispose()
public MType getMessage()
Builder
, it is converted to a Message
by
calling Message.Builder.buildPartial()
on it. If no message has
been set, returns the default instance of the message.public MType build()
public BType getBuilder()
Message.toBuilder()
.public IType getMessageOrBuilder()
public SingleFieldBuilder<MType,BType,IType> setMessage(MType message)
message
- the message to setpublic SingleFieldBuilder<MType,BType,IType> mergeFrom(MType value)
value
- the value to merge frompublic SingleFieldBuilder<MType,BType,IType> clear()
public void markDirty()