Package com.google.protobuf
Class RepeatedFieldBuilder<MType extends GeneratedMessage,BType extends GeneratedMessage.Builder,IType extends MessageOrBuilder>
- java.lang.Object
- 
- com.google.protobuf.RepeatedFieldBuilder<MType,BType,IType>
 
- 
- 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
 - All Implemented Interfaces:
- AbstractMessage.BuilderParent,- GeneratedMessage.BuilderParent
 
 public class RepeatedFieldBuilder<MType extends GeneratedMessage,BType extends GeneratedMessage.Builder,IType extends MessageOrBuilder> extends java.lang.Object implements GeneratedMessage.BuilderParent RepeatedFieldBuilderimplements a structure that a protocol message uses to hold a repeated field of other protocol messages. It supports the classical use case of adding immutableMessage'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 aMessage.Builderto the repeated field and deferring conversion of thatBuilderto an immutableMessage. In this way, it's possible to maintain a tree ofBuilder'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, theSingleFieldBuilderandRepeatedFieldBuilderclasses 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 SummaryConstructors Constructor Description RepeatedFieldBuilder(java.util.List<MType> messages, boolean isMessagesListMutable, GeneratedMessage.BuilderParent parent, boolean isClean)Constructs a new builder with an empty list of messages.
 - 
Method SummaryAll Methods Instance Methods Concrete Methods Modifier and Type Method 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.BTypeaddBuilder(int index, MType message)Inserts a new builder at the specified position in this list.BTypeaddBuilder(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.voidclear()Removes all of the elements from this list.voiddispose()BTypegetBuilder(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.intgetCount()Gets the count of items in the list.MTypegetMessage(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.ITypegetMessageOrBuilder(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.booleanisEmpty()Gets whether the list is empty.voidmarkDirty()A builder becomes dirty whenever a field is modified -- including fields in nested builders -- and becomes clean when build() is called.voidremove(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.
 
- 
- 
- 
Constructor Detail- 
RepeatedFieldBuilderpublic RepeatedFieldBuilder(java.util.List<MType> messages, boolean isMessagesListMutable, GeneratedMessage.BuilderParent parent, boolean isClean) Constructs a new builder with an empty list of messages.- Parameters:
- 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
 
 
- 
 - 
Method Detail- 
disposepublic void dispose() 
 - 
getCountpublic int getCount() Gets the count of items in the list.- Returns:
- the count of items in the list.
 
 - 
isEmptypublic boolean isEmpty() Gets whether the list is empty.- Returns:
- whether the list is empty
 
 - 
getMessagepublic MType getMessage(int index) Get the message at the specified index. If the message is currently stored as aBuilder, it is converted to aMessageby callingMessage.Builder.buildPartial()on it.- Parameters:
- index- the index of the message to get
- Returns:
- the message for the specified index
 
 - 
getBuilderpublic 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 callingMessage.toBuilder().- Parameters:
- index- the index of the message to get
- Returns:
- The builder for that index
 
 - 
getMessageOrBuilderpublic 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- the index of the message to get
- Returns:
- the message or builder for the index as the base class interface
 
 - 
setMessagepublic RepeatedFieldBuilder<MType,BType,IType> setMessage(int index, MType message) Sets a message at the specified index replacing the existing item at that index.- Parameters:
- index- the index to set.
- message- the message to set
- Returns:
- the builder
 
 - 
addMessagepublic RepeatedFieldBuilder<MType,BType,IType> addMessage(MType message) Appends the specified element to the end of this list.- Parameters:
- message- the message to add
- Returns:
- the builder
 
 - 
addMessagepublic RepeatedFieldBuilder<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- the index at which to insert the message
- message- the message to add
- Returns:
- the builder
 
 - 
addAllMessagespublic 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.- Parameters:
- values- the messages to add
- Returns:
- the builder
 
 - 
addBuilderpublic BType addBuilder(MType message) Appends a new builder to the end of this list and returns the builder.- Parameters:
- message- the message to add which is the basis of the builder
- Returns:
- the new builder
 
 - 
addBuilderpublic 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- the index at which to insert the builder
- message- the message to add which is the basis of the builder
- Returns:
- the builder
 
 - 
removepublic 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).- Parameters:
- index- the index at which to remove the message
 
 - 
clearpublic void clear() Removes all of the elements from this list. The list will be empty after this call returns.
 - 
buildpublic java.util.List<MType> build() Builds the list of messages from the builder and returns them.- Returns:
- an immutable list of messages
 
 - 
getMessageListpublic java.util.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:
- the messages in the list
 
 - 
getBuilderListpublic java.util.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:
- the builders in the list
 
 - 
getMessageOrBuilderListpublic java.util.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:
- the builders in the list
 
 - 
markDirtypublic void markDirty() Description copied from interface:AbstractMessage.BuilderParentA 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. - Specified by:
- markDirtyin interface- AbstractMessage.BuilderParent
 
 
- 
 
-