# Class RepeatedFieldBuilderV3&lt;MType,BType,IType&gt; (3.19.4)

    public class RepeatedFieldBuilderV3<MType,BType,IType> 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](https://docs.cloud.google.com/java/docs/reference/protobuf/latest/com.google.protobuf.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](https://docs.cloud.google.com/java/docs/reference/protobuf/latest/com.google.protobuf.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.

## Inheritance

[java.lang.Object](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html) \> RepeatedFieldBuilderV3\<MType,BType,IType\>

## Implements

[AbstractMessage.BuilderParent](https://docs.cloud.google.com/java/docs/reference/protobuf/latest/com.google.protobuf.AbstractMessage.BuilderParent)

## Inherited Members

[Object.clone()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#clone--) [Object.equals(Object)](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#equals-java.lang.Object-) [Object.finalize()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#finalize--) [Object.getClass()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#getClass--) [Object.hashCode()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#hashCode--) [Object.notify()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#notify--) [Object.notifyAll()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#notifyAll--) [Object.toString()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#toString--) [Object.wait()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#wait--) [Object.wait(long)](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#wait-long-) [Object.wait(long,int)](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#wait-long-int-)

| ## Type Parameters ||
|---|---|
| **Name** | **Description** |
| `MType` |   |
| `BType` |   |
| `IType` |   |

## Constructors

### RepeatedFieldBuilderV3(List\<MType\> messages, boolean isMessagesListMutable, AbstractMessage.BuilderParent parent, boolean isClean)

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

Constructs a new builder with an empty list of messages.

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `messages` | `https://docs.oracle.com/javase/8/docs/api/java/util/List.html<MType>` the current list of messages |
| `isMessagesListMutable` | `https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html` Whether the messages list is mutable |
| `parent` | `https://docs.cloud.google.com/java/docs/reference/protobuf/latest/com.google.protobuf.AbstractMessage.BuilderParent` a listener to notify of changes |
| `isClean` | `https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html` whether the builder is initially marked clean |

## Methods

### addAllMessages(Iterable\<? extends MType\> values)

    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.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `values` | `https://docs.oracle.com/javase/8/docs/api/java/lang/Iterable.html<? extends MType>` the messages to add |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/java/docs/reference/protobuf/latest/com.google.protobuf.RepeatedFieldBuilderV3<MType,BType,IType>` | the builder |

### addBuilder(MType message)

    public BType addBuilder(MType message)

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

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `message` | `MType` the message to add which is the basis of the builder |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `BType` | the new builder |

### addBuilder(int index, MType message)

    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** ||
|---|---|
| **Name** | **Description** |
| `index` | `https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html` the index at which to insert the builder |
| `message` | `MType` the message to add which is the basis of the builder |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `BType` | the builder |

### addMessage(MType message)

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

Appends the specified element to the end of this list.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `message` | `MType` the message to add |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/java/docs/reference/protobuf/latest/com.google.protobuf.RepeatedFieldBuilderV3<MType,BType,IType>` | the builder |

### addMessage(int index, MType message)

    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** ||
|---|---|
| **Name** | **Description** |
| `index` | `https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html` the index at which to insert the message |
| `message` | `MType` the message to add |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/java/docs/reference/protobuf/latest/com.google.protobuf.RepeatedFieldBuilderV3<MType,BType,IType>` | the builder |

### build()

    public List<MType> build()

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

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/8/docs/api/java/util/List.html<MType>` | an immutable list of messages |

### clear()

    public void clear()

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

### dispose()

    public void dispose()

### getBuilder(int index)

    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](https://docs.cloud.google.com/java/docs/reference/protobuf/latest/com.google.protobuf.Message#com_google_protobuf_Message_toBuilder_).

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `index` | `https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html` the index of the message to get |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `BType` | The builder for that index |

### getBuilderList()

    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** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/8/docs/api/java/util/List.html<BType>` | the builders in the list |

### getCount()

    public int getCount()

Gets the count of items in the list.

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html` | the count of items in the list. |

### getMessage(int index)

    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](https://docs.cloud.google.com/java/docs/reference/protobuf/latest/com.google.protobuf.Message.Builder#com_google_protobuf_Message_Builder_buildPartial_)
on it.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `index` | `https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html` the index of the message to get |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `MType` | the message for the specified index |

### getMessageList()

    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** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/8/docs/api/java/util/List.html<MType>` | the messages in the list |

### getMessageOrBuilder(int index)

    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.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `index` | `https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html` the index of the message to get |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `IType` | the message or builder for the index as the base class interface |

### getMessageOrBuilderList()

    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** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/8/docs/api/java/util/List.html<IType>` | the builders in the list |

### isEmpty()

    public boolean isEmpty()

Gets whether the list is empty.

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html` | whether the list is empty |

### markDirty()

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

### remove(int index)

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

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `index` | `https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html` the index at which to remove the message |

### setMessage(int index, MType message)

    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** ||
|---|---|
| **Name** | **Description** |
| `index` | `https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html` the index to set. |
| `message` | `MType` the message to set |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/java/docs/reference/protobuf/latest/com.google.protobuf.RepeatedFieldBuilderV3<MType,BType,IType>` | the builder |