Top Description Fields Constructors Methods
com.google.protobuf

public Class SingleFieldBuilderV3<MType extends com.google.protobuf.AbstractMessage, BType extends AbstractMessage.Builder<BuilderType extends AbstractMessage.Builder<BuilderType>>, IType extends com.google.protobuf.MessageOrBuilder>

extends Object
implements BuilderParent
Class Inheritance
All Implemented Interfaces
com.google.protobuf.AbstractMessage.BuilderParent
Type Parameters
<MType>
the type of message for the field
<BType>
the type of builder for the field
<IType>
the common interface for the message and the builder
Static Imports
com.google.protobuf.Internal.checkNotNull

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.

Author
[email protected] (Jon Perlow)

Field Summary

Modifier and TypeField and Description
private BType
private boolean
private MType
private AbstractMessage.BuilderParent

Constructor Summary

AccessConstructor and Description
public
SingleFieldBuilderV3(MType message, AbstractMessage.BuilderParent parent, boolean isClean)

Method Summary

Modifier and TypeMethod and Description
public MType

Returns:

the message
build
()

Builds the message and returns it.

public SingleFieldBuilderV3<MType, BType, IType>

Returns:

the builder
clear
()

Clears the value of the field.

public void
public BType

Returns:

The builder for the field
getBuilder
()

Gets a builder for the field.

public MType

Returns:

the message for the field
getMessage
()

Get the message for the field.

public IType

Returns:

the message or builder for the field as the base class interface
getMessageOrBuilder
()

Gets the base class interface for the field.

public void
markDirty()

Implements com.google.protobuf.AbstractMessage.BuilderParent.markDirty.

A builder becomes dirty whenever a field is modified -- including fields in nested builders -- and becomes clean when build() is called.
public SingleFieldBuilderV3<MType, BType, IType>

Returns:

the builder
mergeFrom
(MType
the value to merge from
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.

public SingleFieldBuilderV3<MType, BType, IType>

Returns:

the builder
setMessage
(MType
the message to set
message
)

Sets a message for the field replacing any existing value.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

builderback to summary
private BType builder
isCleanback to summary
private boolean isClean
messageback to summary
private MType message
parentback to summary
private AbstractMessage.BuilderParent parent

Constructor Detail

SingleFieldBuilderV3back to summary
public SingleFieldBuilderV3(MType message, AbstractMessage.BuilderParent parent, boolean isClean)

Method Detail

buildback to summary
public MType build()

Builds the message and returns it.

Returns:MType

the message

clearback to summary
public SingleFieldBuilderV3<MType, BType, IType> clear()

Clears the value of the field.

Returns:SingleFieldBuilderV3<MType, BType, IType>

the builder

Annotations
@SuppressWarnings:unchecked
disposeback to summary
public void dispose()
getBuilderback to summary
public BType getBuilder()

Gets a builder for the field. If no builder has been created yet, a builder is created on demand by calling Message#toBuilder.

Returns:BType

The builder for the field

Annotations
@SuppressWarnings:unchecked
getMessageback to summary
public MType getMessage()

Get the message for the field. If the message is currently stored as a 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.

Returns:MType

the message for the field

Annotations
@SuppressWarnings:unchecked
getMessageOrBuilderback to summary
public IType getMessageOrBuilder()

Gets the base class interface for the field. This may either be a builder or a message. It will return whatever is more efficient.

Returns:IType

the message or builder for the field as the base class interface

Annotations
@SuppressWarnings:unchecked
markDirtyback to summary
public void markDirty()

Implements com.google.protobuf.AbstractMessage.BuilderParent.markDirty.

Doc from com.google.protobuf.AbstractMessage.BuilderParent.markDirty.

A builder becomes dirty whenever a field is modified -- including fields in nested builders -- and becomes clean when build() is called. Thus, when a builder becomes dirty, all its parents become dirty as well, and when it becomes clean, all its children become clean. The dirtiness state is used to invalidate certain cached values.

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.

Annotations
@Override
mergeFromback to summary
public SingleFieldBuilderV3<MType, BType, IType> mergeFrom(MType value)

Merges the field from another field.

Parameters
value:MType

the value to merge from

Returns:SingleFieldBuilderV3<MType, BType, IType>

the builder

onChangedback to summary
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.

setMessageback to summary
public SingleFieldBuilderV3<MType, BType, IType> setMessage(MType message)

Sets a message for the field replacing any existing value.

Parameters
message:MType

the message to set

Returns:SingleFieldBuilderV3<MType, BType, IType>

the builder