MType
- the type of message for the fieldBType
- the type of builder for the fieldIType
- the common interface for the message and the builder@Generated(value="proto") public 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.
It also supports the additional use case of setting a 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.
Logically, one can think of a tree of builders as converting the entire tree to messages when
build is called on the root or when any method is called that desires a Message instead of a
Builder. In terms of the implementation, the 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.
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.
|
SingleFieldBuilderV3<MType,BType,IType> |
setMessage(MType message)
Sets a message for the field replacing any existing value.
|
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()
public void markDirty()
AbstractMessage.BuilderParent
To this end, a builder calls markDirty() on its parent whenever it transitions from clean to dirty. The parent must propagate this call to its own parent, unless it was already dirty, in which case the grandparent must necessarily already be dirty as well. The parent can only transition back to "clean" after calling build() on all children.
markDirty
in interface AbstractMessage.BuilderParent
Copyright © 2014–2024 The Apache Software Foundation. All rights reserved.