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
public class RepeatedFieldBuilder<MType extends GeneratedMessageextends Object ,BType extends GeneratedMessage .Builder ,IType extends MessageOrBuilder > implements GeneratedMessage .BuilderParent
RepeatedFieldBuilder 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.
SingleFieldBuilder and
RepeatedFieldBuilder classes cache messages that were created so that messages only need to be created when some change occured in its builder or a builder for one of its descendants.
| Constructor and Description |
|---|
RepeatedFieldBuilder(List
Constructs a new builder with an empty list of messages.
|
| Modifier and Type | Method and Description |
|---|---|
RepeatedFieldBuilder |
addAllMessages(Iterable
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.
|
RepeatedFieldBuilder |
addMessage(int index, MType message)
Inserts the specified message at the specified position in this list.
|
RepeatedFieldBuilder |
addMessage(MType message)
Appends the specified element to the end of this list.
|
List |
build()
Builds the list of messages from the builder and returns them.
|
void |
clear()
Removes all of the elements from this list.
|
void |
dispose()
|
BType |
getBuilder(int index)
Gets a builder for the specified index.
|
List |
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.
|
List |
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.
|
List |
getMessageOrBuilderList()
Gets a view of the builder as a list of MessageOrBuilders.
|
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.
|
void |
remove(int index)
Removes the element at the specified position in this list.
|
RepeatedFieldBuilder |
setMessage(int index, MType message)
Sets a message at the specified index replacing the existing item at that index.
|
public RepeatedFieldBuilder(List<MType> messages, boolean isMessagesListMutable, GeneratedMessage .BuilderParent parent, boolean isClean)
messages - the current list of messages
isMessagesListMutable - Whether the messages list is mutable
parent - a listener to notify of changes
isClean - whether the builder is initially marked clean
public void dispose()
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 get
public BType getBuilder(int index)
Message.toBuilder() .
index - the index of the message to get
public IType getMessageOrBuilder(int index)
index - the index of the message to get
public RepeatedFieldBuilder<MType ,BType ,IType> setMessage(int index, MType message)
index - the index to set.
message - the message to set
public RepeatedFieldBuilder<MType ,BType ,IType> addMessage(MType message)
message - the message to add
public RepeatedFieldBuilder<MType ,BType ,IType> addMessage(int index, MType message)
index - the index at which to insert the message
message - the message to add
public RepeatedFieldBuilder<MType ,BType ,IType> addAllMessages(Iterable <? extends MType> values)
values - the messages to add
public BType addBuilder(MType message)
message - the message to add which is the basis of the builder
public BType addBuilder(int index, MType message)
index - the index at which to insert the builder
message - the message to add which is the basis of the builder
public void remove(int index)
index - the index at which to remove the message
public void clear()
public List<MType> build()
public List<MType> getMessageList()
public List<BType> getBuilderList()
public List<IType> getMessageOrBuilderList()
public void markDirty()
GeneratedMessage.BuilderParent