Top Description Inners Fields Constructors Methods
com.google.protobuf

public Class RepeatedFieldBuilderV3<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

RepeatedFieldBuilderV3 implements a structure that a protocol message uses to hold a repeated field of other protocol messages. It supports the classical use case of adding immutable Message's to the repeated field and is highly optimized around this (no extra memory allocations and sharing of immutable arrays).
It also supports the additional use case of adding a Message.Builder to the repeated 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)

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
RepeatedFieldBuilderV3.BuilderExternalList<
the type of message for the field
MType extends AbstractMessage
,
the type of builder for the field
BType extends AbstractMessage.Builder<BuilderType extends AbstractMessage.Builder<BuilderType>>
,
the common interface for the message and the builder
IType extends MessageOrBuilder
>

Provides a live view of the builder as a list of builders.

private static class
RepeatedFieldBuilderV3.MessageExternalList<
the type of message for the field
MType extends AbstractMessage
,
the type of builder for the field
BType extends AbstractMessage.Builder<BuilderType extends AbstractMessage.Builder<BuilderType>>
,
the common interface for the message and the builder
IType extends MessageOrBuilder
>

Provides a live view of the builder as a list of messages.

private static class
RepeatedFieldBuilderV3.MessageOrBuilderExternalList<
the type of message for the field
MType extends AbstractMessage
,
the type of builder for the field
BType extends AbstractMessage.Builder<BuilderType extends AbstractMessage.Builder<BuilderType>>
,
the common interface for the message and the builder
IType extends MessageOrBuilder
>

Provides a live view of the builder as a list of builders.

Field Summary

Modifier and TypeField and Description
private List<SingleFieldBuilderV3<MType, BType, IType>>
private RepeatedFieldBuilderV3.BuilderExternalList<MType, BType, IType>
private RepeatedFieldBuilderV3.MessageExternalList<MType, BType, IType>
private RepeatedFieldBuilderV3.MessageOrBuilderExternalList<MType, BType, IType>
private boolean
private boolean
private List<MType>
private AbstractMessage.BuilderParent

Constructor Summary

AccessConstructor and Description
public
RepeatedFieldBuilderV3(List<MType>
the current list of messages
messages
,
boolean
Whether the messages list is mutable
isMessagesListMutable
,
AbstractMessage.BuilderParent
a listener to notify of changes
parent
,
boolean
whether the builder is initially marked clean
isClean
)

Constructs a new builder with an empty list of messages.

Method Summary

Modifier and TypeMethod and Description
public RepeatedFieldBuilderV3<MType, BType, IType>

Returns:

the builder
addAllMessages
(Iterable<? extends MType>
the messages to add
values
)

Appends all of the messages in the specified collection to the end of this list, in the order that they are returned by the specified collection's iterator.

public BType

Returns:

the new builder
addBuilder
(MType
the message to add which is the basis of the builder
message
)

Appends a new builder to the end of this list and returns the builder.

public BType

Returns:

the builder
addBuilder
(int
the index at which to insert the builder
index
,
MType
the message to add which is the basis of the builder
message
)

Inserts a new builder at the specified position in this list.

public RepeatedFieldBuilderV3<MType, BType, IType>

Returns:

the builder
addMessage
(MType
the message to add
message
)

Appends the specified element to the end of this list.

public RepeatedFieldBuilderV3<MType, BType, IType>

Returns:

the builder
addMessage
(int
the index at which to insert the message
index
,
MType
the message to add
message
)

Inserts the specified message at the specified position in this list.

public List<MType>

Returns:

an immutable list of messages
build
()

Builds the list of messages from the builder and returns them.

public void
clear()

Removes all of the elements from this list.

public void
private void
ensureBuilders()

Ensures that the list of builders is not null.

private void
ensureMutableMessageList()

Ensures that the list of messages is mutable so it can be updated.

public BType

Returns:

The builder for that index
getBuilder
(int
the index of the message to get
index
)

Gets a builder for the specified index.

public List<BType>

Returns:

the builders in the list
getBuilderList
()

Gets a view of the builder as a list of builders.

public int

Returns:

the count of items in the list.
getCount
()

Gets the count of items in the list.

public MType

Returns:

the message for the specified index
getMessage
(int
the index of the message to get
index
)

Get the message at the specified index.

private MType

Returns:

the message for the specified index
getMessage
(int
the index of the message to get
index
,
boolean
this is being called for build so we want to make sure we SingleFieldBuilderV3.build to send dirty invalidations
forBuild
)

Get the message at the specified index.

public List<MType>

Returns:

the messages in the list
getMessageList
()

Gets a view of the builder as a list of messages.

public IType

Returns:

the message or builder for the index as the base class interface
getMessageOrBuilder
(int
the index of the message to get
index
)

Gets the base class interface for the specified index.

public List<IType>

Returns:

the builders in the list
getMessageOrBuilderList
()

Gets a view of the builder as a list of MessageOrBuilders.

private void
incrementModCounts()

Increments the mod counts so that an ConcurrentModificationException can be thrown if calling code tries to modify the builder while its iterating the list.

public boolean

Returns:

whether the list is empty
isEmpty
()

Gets whether the list is empty.

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.
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 void
remove(int
the index at which to remove the message
index
)

Removes the element at the specified position in this list.

public RepeatedFieldBuilderV3<MType, BType, IType>

Returns:

the builder
setMessage
(int
the index to set.
index
,
MType
the message to set
message
)

Sets a message at the specified index replacing the existing item at that index.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

buildersback to summary
private List<SingleFieldBuilderV3<MType, BType, IType>> builders
externalBuilderListback to summary
private RepeatedFieldBuilderV3.BuilderExternalList<MType, BType, IType> externalBuilderList
externalMessageListback to summary
private RepeatedFieldBuilderV3.MessageExternalList<MType, BType, IType> externalMessageList
externalMessageOrBuilderListback to summary
private RepeatedFieldBuilderV3.MessageOrBuilderExternalList<MType, BType, IType> externalMessageOrBuilderList
isCleanback to summary
private boolean isClean
isMessagesListMutableback to summary
private boolean isMessagesListMutable
messagesback to summary
private List<MType> messages
parentback to summary
private AbstractMessage.BuilderParent parent

Constructor Detail

RepeatedFieldBuilderV3back to summary
public RepeatedFieldBuilderV3(List<MType> messages, boolean isMessagesListMutable, AbstractMessage.BuilderParent parent, boolean isClean)

Constructs a new builder with an empty list of messages.

Parameters
messages:List<MType>

the current list of messages

isMessagesListMutable:boolean

Whether the messages list is mutable

parent:AbstractMessage.BuilderParent

a listener to notify of changes

isClean:boolean

whether the builder is initially marked clean

Method Detail

addAllMessagesback to summary
public RepeatedFieldBuilderV3<MType, BType, IType> addAllMessages(Iterable<? extends MType> values)

Appends all of the messages in the specified collection to the end of this list, in the order that they are returned by the specified collection's iterator.

Parameters
values:Iterable<? extends MType>

the messages to add

Returns:RepeatedFieldBuilderV3<MType, BType, IType>

the builder

addBuilderback to summary
public BType addBuilder(MType message)

Appends a new builder to the end of this list and returns the builder.

Parameters
message:MType

the message to add which is the basis of the builder

Returns:BType

the new builder

addBuilderback to summary
public BType addBuilder(int index, MType message)

Inserts a new builder at the specified position in this list. Shifts the element currently at that position (if any) and any subsequent elements to the right (adds one to their indices).

Parameters
index:int

the index at which to insert the builder

message:MType

the message to add which is the basis of the builder

Returns:BType

the builder

addMessageback to summary
public RepeatedFieldBuilderV3<MType, BType, IType> addMessage(MType message)

Appends the specified element to the end of this list.

Parameters
message:MType

the message to add

Returns:RepeatedFieldBuilderV3<MType, BType, IType>

the builder

addMessageback to summary
public RepeatedFieldBuilderV3<MType, BType, IType> addMessage(int index, MType message)

Inserts the specified message at the specified position in this list. Shifts the element currently at that position (if any) and any subsequent elements to the right (adds one to their indices).

Parameters
index:int

the index at which to insert the message

message:MType

the message to add

Returns:RepeatedFieldBuilderV3<MType, BType, IType>

the builder

buildback to summary
public List<MType> build()

Builds the list of messages from the builder and returns them.

Returns:List<MType>

an immutable list of messages

clearback to summary
public void clear()

Removes all of the elements from this list. The list will be empty after this call returns.

disposeback to summary
public void dispose()
ensureBuildersback to summary
private void ensureBuilders()

Ensures that the list of builders is not null. If it's null, the list is created and initialized to be the same size as the messages list with null entries.

ensureMutableMessageListback to summary
private void ensureMutableMessageList()

Ensures that the list of messages is mutable so it can be updated. If it's immutable, a copy is made.

getBuilderback to summary
public BType getBuilder(int index)

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

Parameters
index:int

the index of the message to get

Returns:BType

The builder for that index

getBuilderListback to summary
public List<BType> getBuilderList()

Gets a view of the builder as a list of builders. This returned list is live and will reflect any changes to the underlying builder.

Returns:List<BType>

the builders in the list

getCountback to summary
public int getCount()

Gets the count of items in the list.

Returns:int

the count of items in the list.

getMessageback to summary
public MType getMessage(int index)

Get the message at the specified index. If the message is currently stored as a Builder, it is converted to a Message by calling Message.Builder#buildPartial on it.

Parameters
index:int

the index of the message to get

Returns:MType

the message for the specified index

getMessageback to summary
private MType getMessage(int index, boolean forBuild)

Get the message at the specified index. If the message is currently stored as a Builder, it is converted to a Message by calling Message.Builder#buildPartial on it.

Parameters
index:int

the index of the message to get

forBuild:boolean

this is being called for build so we want to make sure we SingleFieldBuilderV3.build to send dirty invalidations

Returns:MType

the message for the specified index

getMessageListback to summary
public List<MType> getMessageList()

Gets a view of the builder as a list of messages. The returned list is live and will reflect any changes to the underlying builder.

Returns:List<MType>

the messages in the list

getMessageOrBuilderback to summary
public IType getMessageOrBuilder(int index)

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

Parameters
index:int

the index of the message to get

Returns:IType

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

Annotations
@SuppressWarnings:unchecked
getMessageOrBuilderListback to summary
public List<IType> getMessageOrBuilderList()

Gets a view of the builder as a list of MessageOrBuilders. This returned list is live and will reflect any changes to the underlying builder.

Returns:List<IType>

the builders in the list

incrementModCountsback to summary
private void incrementModCounts()

Increments the mod counts so that an ConcurrentModificationException can be thrown if calling code tries to modify the builder while its iterating the list.

isEmptyback to summary
public boolean isEmpty()

Gets whether the list is empty.

Returns:boolean

whether the list is empty

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
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.

removeback to summary
public void remove(int index)

Removes the element at the specified position in this list. Shifts any subsequent elements to the left (subtracts one from their indices). Returns the element that was removed from the list.

Parameters
index:int

the index at which to remove the message

setMessageback to summary
public RepeatedFieldBuilderV3<MType, BType, IType> setMessage(int index, MType message)

Sets a message at the specified index replacing the existing item at that index.

Parameters
index:int

the index to set.

message:MType

the message to set

Returns:RepeatedFieldBuilderV3<MType, BType, IType>

the builder

com.google.protobuf back to summary

private Class RepeatedFieldBuilderV3.BuilderExternalList<MType extends com.google.protobuf.AbstractMessage, BType extends AbstractMessage.Builder<BuilderType extends AbstractMessage.Builder<BuilderType>>, IType extends com.google.protobuf.MessageOrBuilder>

extends AbstractList<BType extends AbstractMessage.Builder<BuilderType extends AbstractMessage.Builder<BuilderType>>>
implements List<BType extends AbstractMessage.Builder<BuilderType extends AbstractMessage.Builder<BuilderType>>>
Class Inheritance
All Implemented Interfaces
java.util.List, java.util.SequencedCollection, java.util.Collection, java.lang.Iterable
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

Provides a live view of the builder as a list of builders.

Field Summary

Modifier and TypeField and Description
pack-priv RepeatedFieldBuilderV3<MType, BType, IType>
Inherited from java.util.AbstractList:
modCount

Constructor Summary

AccessConstructor and Description
pack-priv
BuilderExternalList(RepeatedFieldBuilderV3<MType, BType, IType> builder)

Method Summary

Modifier and TypeMethod and Description
public BType
get(int
index of the element to return
index
)

Implements abstract java.util.AbstractList.get.

Implements java.util.List.get.

Returns the element at the specified position in this list.
pack-priv void
public int
size()

Implements abstract java.util.AbstractCollection.size.

Implements java.util.List.size, java.util.Collection.size.

Returns the number of elements in this list.
Inherited from java.util.AbstractList:
addaddaddAllclearequalshashCodeindexOfiteratorlastIndexOflistIteratorlistIteratorremoveremoveRangesetsubList

Field Detail

builderback to summary
pack-priv RepeatedFieldBuilderV3<MType, BType, IType> builder

Constructor Detail

BuilderExternalListback to summary
pack-priv BuilderExternalList(RepeatedFieldBuilderV3<MType, BType, IType> builder)

Method Detail

getback to summary
public BType get(int index)

Implements abstract java.util.AbstractList.get.

Implements java.util.List.get.

Doc from java.util.List.get.

Returns the element at the specified position in this list.

Parameters
index:int

index of the element to return

Returns:BType

the element at the specified position in this list

Annotations
@Override
incrementModCountback to summary
pack-priv void incrementModCount()
sizeback to summary
public int size()

Implements abstract java.util.AbstractCollection.size.

Implements java.util.List.size, java.util.Collection.size.

Doc from java.util.List.size.

Returns the number of elements in this list. If this list contains more than Integer.MAX_VALUE elements, returns Integer.MAX_VALUE.

Returns:int

the number of elements in this list

Annotations
@Override
com.google.protobuf back to summary

private Class RepeatedFieldBuilderV3.MessageExternalList<MType extends com.google.protobuf.AbstractMessage, BType extends AbstractMessage.Builder<BuilderType extends AbstractMessage.Builder<BuilderType>>, IType extends com.google.protobuf.MessageOrBuilder>

extends AbstractList<MType extends AbstractMessage>
implements List<MType extends AbstractMessage>
Class Inheritance
All Implemented Interfaces
java.util.List, java.util.SequencedCollection, java.util.Collection, java.lang.Iterable
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

Provides a live view of the builder as a list of messages.

Field Summary

Modifier and TypeField and Description
pack-priv RepeatedFieldBuilderV3<MType, BType, IType>
Inherited from java.util.AbstractList:
modCount

Constructor Summary

AccessConstructor and Description
pack-priv
MessageExternalList(RepeatedFieldBuilderV3<MType, BType, IType> builder)

Method Summary

Modifier and TypeMethod and Description
public MType
get(int
index of the element to return
index
)

Implements abstract java.util.AbstractList.get.

Implements java.util.List.get.

Returns the element at the specified position in this list.
pack-priv void
public int
size()

Implements abstract java.util.AbstractCollection.size.

Implements java.util.List.size, java.util.Collection.size.

Returns the number of elements in this list.
Inherited from java.util.AbstractList:
addaddaddAllclearequalshashCodeindexOfiteratorlastIndexOflistIteratorlistIteratorremoveremoveRangesetsubList

Field Detail

builderback to summary
pack-priv RepeatedFieldBuilderV3<MType, BType, IType> builder

Constructor Detail

MessageExternalListback to summary
pack-priv MessageExternalList(RepeatedFieldBuilderV3<MType, BType, IType> builder)

Method Detail

getback to summary
public MType get(int index)

Implements abstract java.util.AbstractList.get.

Implements java.util.List.get.

Doc from java.util.List.get.

Returns the element at the specified position in this list.

Parameters
index:int

index of the element to return

Returns:MType

the element at the specified position in this list

Annotations
@Override
incrementModCountback to summary
pack-priv void incrementModCount()
sizeback to summary
public int size()

Implements abstract java.util.AbstractCollection.size.

Implements java.util.List.size, java.util.Collection.size.

Doc from java.util.List.size.

Returns the number of elements in this list. If this list contains more than Integer.MAX_VALUE elements, returns Integer.MAX_VALUE.

Returns:int

the number of elements in this list

Annotations
@Override
com.google.protobuf back to summary

private Class RepeatedFieldBuilderV3.MessageOrBuilderExternalList<MType extends com.google.protobuf.AbstractMessage, BType extends AbstractMessage.Builder<BuilderType extends AbstractMessage.Builder<BuilderType>>, IType extends com.google.protobuf.MessageOrBuilder>

extends AbstractList<IType extends MessageOrBuilder>
implements List<IType extends MessageOrBuilder>
Class Inheritance
All Implemented Interfaces
java.util.List, java.util.SequencedCollection, java.util.Collection, java.lang.Iterable
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

Provides a live view of the builder as a list of builders.

Field Summary

Modifier and TypeField and Description
pack-priv RepeatedFieldBuilderV3<MType, BType, IType>
Inherited from java.util.AbstractList:
modCount

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
public IType
get(int
index of the element to return
index
)

Implements abstract java.util.AbstractList.get.

Implements java.util.List.get.

Returns the element at the specified position in this list.
pack-priv void
public int
size()

Implements abstract java.util.AbstractCollection.size.

Implements java.util.List.size, java.util.Collection.size.

Returns the number of elements in this list.
Inherited from java.util.AbstractList:
addaddaddAllclearequalshashCodeindexOfiteratorlastIndexOflistIteratorlistIteratorremoveremoveRangesetsubList

Field Detail

builderback to summary
pack-priv RepeatedFieldBuilderV3<MType, BType, IType> builder

Constructor Detail

MessageOrBuilderExternalListback to summary
pack-priv MessageOrBuilderExternalList(RepeatedFieldBuilderV3<MType, BType, IType> builder)

Method Detail

getback to summary
public IType get(int index)

Implements abstract java.util.AbstractList.get.

Implements java.util.List.get.

Doc from java.util.List.get.

Returns the element at the specified position in this list.

Parameters
index:int

index of the element to return

Returns:IType

the element at the specified position in this list

Annotations
@Override
incrementModCountback to summary
pack-priv void incrementModCount()
sizeback to summary
public int size()

Implements abstract java.util.AbstractCollection.size.

Implements java.util.List.size, java.util.Collection.size.

Doc from java.util.List.size.

Returns the number of elements in this list. If this list contains more than Integer.MAX_VALUE elements, returns Integer.MAX_VALUE.

Returns:int

the number of elements in this list

Annotations
@Override