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 RepeatedFieldBuilderV3<MType extends AbstractMessage,BType extends AbstractMessage.Builder,IType extends MessageOrBuilder> extends java.lang.Object implements AbstractMessage.BuilderParent
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).
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.
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 | Class and Description |
---|---|
private static class |
RepeatedFieldBuilderV3.BuilderExternalList<MType extends AbstractMessage,BType extends AbstractMessage.Builder,IType extends MessageOrBuilder>
Provides a live view of the builder as a list of builders.
|
private static class |
RepeatedFieldBuilderV3.MessageExternalList<MType extends AbstractMessage,BType extends AbstractMessage.Builder,IType extends MessageOrBuilder>
Provides a live view of the builder as a list of messages.
|
private static class |
RepeatedFieldBuilderV3.MessageOrBuilderExternalList<MType extends AbstractMessage,BType extends AbstractMessage.Builder,IType extends MessageOrBuilder>
Provides a live view of the builder as a list of builders.
|
Modifier and Type | Field and Description |
---|---|
private java.util.List<SingleFieldBuilderV3<MType,BType,IType>> |
builders |
private RepeatedFieldBuilderV3.BuilderExternalList<MType,BType,IType> |
externalBuilderList |
private RepeatedFieldBuilderV3.MessageExternalList<MType,BType,IType> |
externalMessageList |
private RepeatedFieldBuilderV3.MessageOrBuilderExternalList<MType,BType,IType> |
externalMessageOrBuilderList |
private boolean |
isClean |
private boolean |
isMessagesListMutable |
private java.util.List<MType> |
messages |
private AbstractMessage.BuilderParent |
parent |
Constructor and Description |
---|
RepeatedFieldBuilderV3(java.util.List<MType> messages,
boolean isMessagesListMutable,
AbstractMessage.BuilderParent parent,
boolean isClean)
Constructs a new builder with an empty list of messages.
|
Modifier and Type | Method and Description |
---|---|
RepeatedFieldBuilderV3<MType,BType,IType> |
addAllMessages(java.lang.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.
|
BType |
addBuilder(int index,
MType message)
Inserts a new builder at the specified position in this list.
|
BType |
addBuilder(MType message)
Appends a new builder to the end of this list and returns the builder.
|
RepeatedFieldBuilderV3<MType,BType,IType> |
addMessage(int index,
MType message)
Inserts the specified message at the specified position in this list.
|
RepeatedFieldBuilderV3<MType,BType,IType> |
addMessage(MType message)
Appends the specified element to the end of this list.
|
java.util.List<MType> |
build()
Builds the list of messages from the builder and returns them.
|
void |
clear()
Removes all of the elements from this list.
|
void |
dispose() |
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.
|
BType |
getBuilder(int index)
Gets a builder for the specified index.
|
java.util.List<BType> |
getBuilderList()
Gets a view of the builder as a list of builders.
|
int |
getCount()
Gets the count of items in the list.
|
MType |
getMessage(int index)
Get the message at the specified index.
|
private MType |
getMessage(int index,
boolean forBuild)
Get the message at the specified index.
|
java.util.List<MType> |
getMessageList()
Gets a view of the builder as a list of messages.
|
IType |
getMessageOrBuilder(int index)
Gets the base class interface for the specified index.
|
java.util.List<IType> |
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.
|
boolean |
isEmpty()
Gets whether the list is empty.
|
void |
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.
|
void |
remove(int index)
Removes the element at the specified position in this list.
|
RepeatedFieldBuilderV3<MType,BType,IType> |
setMessage(int index,
MType message)
Sets a message at the specified index replacing the existing item at
that index.
|
private AbstractMessage.BuilderParent parent
private java.util.List<MType extends AbstractMessage> messages
private boolean isMessagesListMutable
private java.util.List<SingleFieldBuilderV3<MType extends AbstractMessage,BType extends AbstractMessage.Builder,IType extends MessageOrBuilder>> builders
private boolean isClean
private RepeatedFieldBuilderV3.MessageExternalList<MType extends AbstractMessage,BType extends AbstractMessage.Builder,IType extends MessageOrBuilder> externalMessageList
private RepeatedFieldBuilderV3.BuilderExternalList<MType extends AbstractMessage,BType extends AbstractMessage.Builder,IType extends MessageOrBuilder> externalBuilderList
private RepeatedFieldBuilderV3.MessageOrBuilderExternalList<MType extends AbstractMessage,BType extends AbstractMessage.Builder,IType extends MessageOrBuilder> externalMessageOrBuilderList
public RepeatedFieldBuilderV3(java.util.List<MType> messages, boolean isMessagesListMutable, AbstractMessage.BuilderParent parent, boolean isClean)
messages
- the current list of messagesisMessagesListMutable
- Whether the messages list is mutableparent
- a listener to notify of changesisClean
- whether the builder is initially marked cleanpublic void dispose()
private void ensureMutableMessageList()
private void ensureBuilders()
public int getCount()
public boolean isEmpty()
public MType getMessage(int index)
Builder
, it is converted to a Message
by
calling Message.Builder.buildPartial()
on it.index
- the index of the message to getprivate MType getMessage(int index, boolean forBuild)
Builder
, it is converted to a Message
by
calling Message.Builder.buildPartial()
on it.index
- the index of the message to getforBuild
- this is being called for build so we want to make sure
we SingleFieldBuilderV3.build to send dirty invalidationspublic BType getBuilder(int index)
Message.toBuilder()
.index
- the index of the message to getpublic IType getMessageOrBuilder(int index)
index
- the index of the message to getpublic RepeatedFieldBuilderV3<MType,BType,IType> setMessage(int index, MType message)
index
- the index to set.message
- the message to setpublic RepeatedFieldBuilderV3<MType,BType,IType> addMessage(MType message)
message
- the message to addpublic RepeatedFieldBuilderV3<MType,BType,IType> addMessage(int index, MType message)
index
- the index at which to insert the messagemessage
- the message to addpublic RepeatedFieldBuilderV3<MType,BType,IType> addAllMessages(java.lang.Iterable<? extends MType> values)
values
- the messages to addpublic BType addBuilder(MType message)
message
- the message to add which is the basis of the builderpublic BType addBuilder(int index, MType message)
index
- the index at which to insert the buildermessage
- the message to add which is the basis of the builderpublic void remove(int index)
index
- the index at which to remove the messagepublic void clear()
public java.util.List<MType> build()
public java.util.List<MType> getMessageList()
public java.util.List<BType> getBuilderList()
public java.util.List<IType> getMessageOrBuilderList()
private void onChanged()
public void markDirty()
AbstractMessage.BuilderParent
markDirty
in interface AbstractMessage.BuilderParent
private void incrementModCounts()