Package org.apache.cayenne.util

## Class PersistentObjectList<E>

- java.lang.Object
- - org.apache.cayenne.util.RelationshipFault<E>
  - - org.apache.cayenne.util.PersistentObjectList<E>

- All Implemented Interfaces:
    `Serializable`, `Iterable<E>`, `Collection<E>`, `List<E>`, `PersistentObjectCollection<E>`, `ValueHolder<List<E>>`
  Direct Known Subclasses:
    `ToManyList`

      public class PersistentObjectList<E>
      extends RelationshipFault<E>
      implements List<E>, ValueHolder<List<E>>, PersistentObjectCollection<E>

  A list of persistent objects lazily resolved on the first access.
  Since:
    1.2
  See Also:
    Serialized Form

- - ### Field Summary

    Fields
    Modifier and Type | Field | Description
    --- | --- | ---
    `protected LinkedList<E>` | `addedToUnresolved` |
    `protected List<E>` | `objectList` |
    `protected LinkedList<E>` | `removedFromUnresolved` |

    - ### Fields inherited from class org.apache.cayenne.util.RelationshipFault

      `relationshipName, relationshipOwner`

  - ### Constructor Summary

    Constructors
    Constructor | Description
    --- | ---
    `PersistentObjectList​(Persistent relationshipOwner, String relationshipName)` | Creates PersistentObjectList initializing it with list owner persistent object and relationship name that this list maps to.

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method | Description
    --- | --- | ---
    `void` | `add​(int index, E o)` |
    `boolean` | `add​(E o)` |
    `boolean` | `addAll​(int index, Collection<? extends E> c)` |
    `boolean` | `addAll​(Collection<? extends E> c)` |
    `void` | `addDirectly​(E target)` | Adds an object without triggering an event
    `protected boolean` | `addLocal​(E object)` |
    `void` | `clear()` |
    `protected void` | `clearLocalChanges()` |
    `boolean` | `contains​(Object o)` |
    `boolean` | `containsAll​(Collection c)` |
    `boolean` | `equals​(Object o)` |
    `E` | `get​(int index)` |
    `List<E>` | `getValue()` | Returns an object stored by this ValueHolder.
    `List<E>` | `getValueDirectly()` | Retrieves ValueHolder value without triggering fault resolution.
    `int` | `hashCode()` |
    `int` | `indexOf​(Object o)` |
    `void` | `invalidate()` | Turns itself into a fault, thus forcing a refresh on the next access.
    `boolean` | `isEmpty()` |
    `boolean` | `isFault()` | Returns whether this list is not yet resolved and requires a fetch.
    `Iterator<E>` | `iterator()` |
    `int` | `lastIndexOf​(Object o)` |
    `ListIterator<E>` | `listIterator()` |
    `ListIterator<E>` | `listIterator​(int index)` |
    `protected void` | `mergeLocalChanges​(List<E> fetchedList)` |
    `protected void` | `postprocessAdd​(E addedObject)` |
    `protected void` | `postprocessAdd​(Collection<? extends E> collection)` |
    `protected void` | `postprocessRemove​(E removedObject)` |
    `protected void` | `postprocessRemove​(Collection<? extends E> collection)` |
    `E` | `remove​(int index)` |
    `boolean` | `remove​(Object o)` |
    `boolean` | `removeAll​(Collection<?> c)` |
    `void` | `removeDirectly​(E target)` | Removes an object without triggering an event
    `protected boolean` | `removeLocal​(E object)` |
    `protected List<E>` | `resolvedObjectList()` | Returns internal objects list resolving it if needed.
    `boolean` | `retainAll​(Collection<?> c)` |
    `E` | `set​(int index, E o)` |
    `void` | `setObjectList​(List<E> objectList)` |
    `List<E>` | `setValue​(List<E> value)` | Sets an object stored by this ValueHolder.
    `List<E>` | `setValueDirectly​(List<E> value)` | Sets ValueHolder vaue without triggering fault resolution.
    `protected boolean` | `shouldAddToRemovedFromUnresolvedList​(E object)` |
    `int` | `size()` |
    `List<E>` | `subList​(int fromIndex, int toIndex)` |
    `Object[]` | `toArray()` |
    `<T> T[]` | `toArray​(T[] a)` |
    `String` | `toString()` |

    - ### Methods inherited from class org.apache.cayenne.util.RelationshipFault

      `getRelationshipName, getRelationshipOwner, isTransientParent, isUncommittedParent, resolveFromDB, updateReverse`

    - ### Methods inherited from class java.lang.Object

      `clone, finalize, getClass, notify, notifyAll, wait, wait, wait`

    - ### Methods inherited from interface java.util.Collection

      `parallelStream, removeIf, stream, toArray`

    - ### Methods inherited from interface java.lang.Iterable

      `forEach`

    - ### Methods inherited from interface java.util.List

      `replaceAll, sort, spliterator`

- - ### Field Detail

    - #### objectList

          protected List<E> objectList

    - #### addedToUnresolved

          protected LinkedList<E> addedToUnresolved

    - #### removedFromUnresolved

          protected LinkedList<E> removedFromUnresolved

  - ### Constructor Detail

    - #### PersistentObjectList

          public PersistentObjectList​(Persistent relationshipOwner,
                                      String relationshipName)

      Creates PersistentObjectList initializing it with list owner persistent object and relationship name that this list maps to.
      Parameters:
        `relationshipOwner` - persistent object that owns this list.
        `relationshipName` - a query used to resolve the list

  - ### Method Detail

    - #### isFault

          public boolean isFault()

      Returns whether this list is not yet resolved and requires a fetch.
      Specified by:
        `isFault` in interface `ValueHolder<E>`

    - #### invalidate

          public void invalidate()

      Turns itself into a fault, thus forcing a refresh on the next access.
      Specified by:
        `invalidate` in interface `ValueHolder<E>`

    - #### setValueDirectly

          public List<E> setValueDirectly​(List<E> value)
                                   throws CayenneRuntimeException

      Description copied from interface: `ValueHolder`
      Sets ValueHolder vaue without triggering fault resolution.
      Specified by:
        `setValueDirectly` in interface `ValueHolder<E>`
      Throws:
        `CayenneRuntimeException`

    - #### getValue

          public List<E> getValue()
                           throws CayenneRuntimeException

      Description copied from interface: `ValueHolder`
      Returns an object stored by this ValueHolder.
      Specified by:
        `getValue` in interface `ValueHolder<E>`
      Throws:
        `CayenneRuntimeException`

    - #### getValueDirectly

          public List<E> getValueDirectly()
                                   throws CayenneRuntimeException

      Description copied from interface: `ValueHolder`
      Retrieves ValueHolder value without triggering fault resolution.
      Specified by:
        `getValueDirectly` in interface `ValueHolder<E>`
      Throws:
        `CayenneRuntimeException`

    - #### setValue

          public List<E> setValue​(List<E> value)
                           throws CayenneRuntimeException

      Description copied from interface: `ValueHolder`
      Sets an object stored by this ValueHolder.
      Specified by:
        `setValue` in interface `ValueHolder<E>`
      Parameters:
        `value` - a new value of the ValueHolder.
      Returns:
        a previous value saved in the ValueHolder.
      Throws:
        `CayenneRuntimeException`

    - #### setObjectList

          public void setObjectList​(List<E> objectList)

    - #### add

          public boolean add​(E o)

      Specified by:
        `add` in interface `Collection<E>`
      Specified by:
        `add` in interface `List<E>`

    - #### add

          public void add​(int index,
                          E o)

      Specified by:
        `add` in interface `List<E>`

    - #### addAll

          public boolean addAll​(Collection<? extends E> c)

      Specified by:
        `addAll` in interface `Collection<E>`
      Specified by:
        `addAll` in interface `List<E>`

    - #### addAll

          public boolean addAll​(int index,
                                Collection<? extends E> c)

      Specified by:
        `addAll` in interface `List<E>`

    - #### clear

          public void clear()

      Specified by:
        `clear` in interface `Collection<E>`
      Specified by:
        `clear` in interface `List<E>`

    - #### contains

          public boolean contains​(Object o)

      Specified by:
        `contains` in interface `Collection<E>`
      Specified by:
        `contains` in interface `List<E>`

    - #### containsAll

          public boolean containsAll​(Collection c)

      Specified by:
        `containsAll` in interface `Collection<E>`
      Specified by:
        `containsAll` in interface `List<E>`

    - #### equals

          public boolean equals​(Object o)

      Specified by:
        `equals` in interface `Collection<E>`
      Specified by:
        `equals` in interface `List<E>`
      Overrides:
        `equals` in class `Object`

    - #### hashCode

          public int hashCode()

      Specified by:
        `hashCode` in interface `Collection<E>`
      Specified by:
        `hashCode` in interface `List<E>`
      Overrides:
        `hashCode` in class `Object`

    - #### get

          public E get​(int index)

      Specified by:
        `get` in interface `List<E>`

    - #### indexOf

          public int indexOf​(Object o)

      Specified by:
        `indexOf` in interface `List<E>`

    - #### isEmpty

          public boolean isEmpty()

      Specified by:
        `isEmpty` in interface `Collection<E>`
      Specified by:
        `isEmpty` in interface `List<E>`

    - #### iterator

          public Iterator<E> iterator()

      Specified by:
        `iterator` in interface `Collection<E>`
      Specified by:
        `iterator` in interface `Iterable<E>`
      Specified by:
        `iterator` in interface `List<E>`

    - #### lastIndexOf

          public int lastIndexOf​(Object o)

      Specified by:
        `lastIndexOf` in interface `List<E>`

    - #### listIterator

          public ListIterator<E> listIterator()

      Specified by:
        `listIterator` in interface `List<E>`

    - #### listIterator

          public ListIterator<E> listIterator​(int index)

      Specified by:
        `listIterator` in interface `List<E>`

    - #### remove

          public E remove​(int index)

      Specified by:
        `remove` in interface `List<E>`

    - #### remove

          public boolean remove​(Object o)

      Specified by:
        `remove` in interface `Collection<E>`
      Specified by:
        `remove` in interface `List<E>`

    - #### removeAll

          public boolean removeAll​(Collection<?> c)

      Specified by:
        `removeAll` in interface `Collection<E>`
      Specified by:
        `removeAll` in interface `List<E>`

    - #### retainAll

          public boolean retainAll​(Collection<?> c)

      Specified by:
        `retainAll` in interface `Collection<E>`
      Specified by:
        `retainAll` in interface `List<E>`

    - #### set

          public E set​(int index,
                       E o)

      Specified by:
        `set` in interface `List<E>`

    - #### size

          public int size()

      Specified by:
        `size` in interface `Collection<E>`
      Specified by:
        `size` in interface `List<E>`

    - #### subList

          public List<E> subList​(int fromIndex,
                                 int toIndex)

      Specified by:
        `subList` in interface `List<E>`

    - #### toArray

          public Object[] toArray()

      Specified by:
        `toArray` in interface `Collection<E>`
      Specified by:
        `toArray` in interface `List<E>`

    - #### toArray

          public <T> T[] toArray​(T[] a)

      Specified by:
        `toArray` in interface `Collection<E>`
      Specified by:
        `toArray` in interface `List<E>`

    - #### resolvedObjectList

          protected List<E> resolvedObjectList()

      Returns internal objects list resolving it if needed.

    - #### clearLocalChanges

          protected void clearLocalChanges()

    - #### mergeLocalChanges

          protected void mergeLocalChanges​(List<E> fetchedList)

      Specified by:
        `mergeLocalChanges` in class `RelationshipFault<E>`

    - #### addLocal

          protected boolean addLocal​(E object)

    - #### removeLocal

          protected boolean removeLocal​(E object)

    - #### shouldAddToRemovedFromUnresolvedList

          protected boolean shouldAddToRemovedFromUnresolvedList​(E object)

      Returns:
        whether object should be added to `removedFromUnresolved` during removal

    - #### postprocessAdd

          protected void postprocessAdd​(Collection<? extends E> collection)

    - #### postprocessRemove

          protected void postprocessRemove​(Collection<? extends E> collection)

    - #### postprocessAdd

          protected void postprocessAdd​(E addedObject)

    - #### postprocessRemove

          protected void postprocessRemove​(E removedObject)

    - #### toString

          public String toString()

      Overrides:
        `toString` in class `Object`

    - #### addDirectly

          public void addDirectly​(E target)

      Description copied from interface: `PersistentObjectCollection`
      Adds an object without triggering an event
      Specified by:
        `addDirectly` in interface `PersistentObjectCollection<E>`

    - #### removeDirectly

          public void removeDirectly​(E target)

      Description copied from interface: `PersistentObjectCollection`
      Removes an object without triggering an event
      Specified by:
        `removeDirectly` in interface `PersistentObjectCollection<E>`