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 RepeatedFieldBuilder<MType extends GeneratedMessage,BType extends GeneratedMessage.Builder,IType extends MessageOrBuilder> extends java.lang.Object 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 occurred in its builder or a builder for one of its descendants.Constructor and Description |
---|
RepeatedFieldBuilder(java.util.List<MType> messages,
boolean isMessagesListMutable,
GeneratedMessage.BuilderParent parent,
boolean isClean)
Constructs a new builder with an empty list of messages.
|
Modifier and Type | Method and Description |
---|---|
RepeatedFieldBuilder<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.
|
RepeatedFieldBuilder<MType,BType,IType> |
addMessage(int index,
MType message)
Inserts the specified message at the specified position in this list.
|
RepeatedFieldBuilder<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() |
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.
|
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.
|
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<MType,BType,IType> |
setMessage(int index,
MType message)
Sets a message at the specified index replacing the existing item at that index.
|
public RepeatedFieldBuilder(java.util.List<MType> messages, boolean isMessagesListMutable, GeneratedMessage.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()
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 getpublic 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 RepeatedFieldBuilder<MType,BType,IType> setMessage(int index, MType message)
index
- the index to set.message
- the message to setpublic RepeatedFieldBuilder<MType,BType,IType> addMessage(MType message)
message
- the message to addpublic RepeatedFieldBuilder<MType,BType,IType> addMessage(int index, MType message)
index
- the index at which to insert the messagemessage
- the message to addpublic RepeatedFieldBuilder<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()
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.