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 SingleFieldBuilderV3<MType extends AbstractMessage,BType extends AbstractMessage.Builder,IType extends MessageOrBuilder> extends java.lang.Object implements AbstractMessage.BuilderParent
SingleFieldBuilderV3
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.
SingleFieldBuilderV3
and RepeatedFieldBuilderV3
classes cache messages that were created so that messages only need to be
created when some change occurred in its builder or a builder for one of its
descendants.Modifier and Type | Field and Description |
---|---|
private BType |
builder |
private boolean |
isClean |
private MType |
message |
private AbstractMessage.BuilderParent |
parent |
Constructor and Description |
---|
SingleFieldBuilderV3(MType message,
AbstractMessage.BuilderParent parent,
boolean isClean) |
Modifier and Type | Method and Description |
---|---|
MType |
build()
Builds the message and returns it.
|
SingleFieldBuilderV3<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.
|
SingleFieldBuilderV3<MType,BType,IType> |
mergeFrom(MType value)
Merges the field from another field.
|
private void |
onChanged()
Called when a the builder or one of its nested children has changed
and any parent should be notified of its invalidation.
|
SingleFieldBuilderV3<MType,BType,IType> |
setMessage(MType message)
Sets a message for the field replacing any existing value.
|
private AbstractMessage.BuilderParent parent
private BType extends AbstractMessage.Builder builder
private MType extends AbstractMessage message
private boolean isClean
public SingleFieldBuilderV3(MType message, AbstractMessage.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 SingleFieldBuilderV3<MType,BType,IType> setMessage(MType message)
message
- the message to setpublic SingleFieldBuilderV3<MType,BType,IType> mergeFrom(MType value)
value
- the value to merge frompublic SingleFieldBuilderV3<MType,BType,IType> clear()
private void onChanged()
public void markDirty()
AbstractMessage.BuilderParent
markDirty
in interface AbstractMessage.BuilderParent