Package org.apache.cayenne.util

# Class IndexPropertyList

java.lang.Object
java.util.AbstractCollection<E>
java.util.AbstractList
org.apache.cayenne.util.IndexPropertyList

All Implemented Interfaces:
  `Serializable`, `Iterable`, `Collection`, `List`, `ValueHolder`

public class IndexPropertyList extends AbstractList implements ValueHolder
A List implementation that would maintain its internal ordering based on some object numeric "index" property. When objects are added to the list at a certain index, an "index" property is modified to reflect list order, when objects are removed, their index property is set to the negative number.

For performance reasons this implementation does not guarantee that there is no gaps in the integer ordering sequence (i.e. generally `object.getIndexProperty() != list.indexOf(object)`). However it guarantees the right ordering based on index property.

Since:
  1.2
See Also:
  - Serialized Form

- ## Field Summary

  Fields
  Modifier and Type
  Field
  Description
  `protected String`
  `indexProperty`
  `protected List`
  `list`
  A list used for the actual objects storage.

  ### Fields inherited from class java.util.AbstractList

  `modCount`

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `IndexPropertyList(String indexProperty)`
  Creates an empty NumericPropertyOrderedList.
  `IndexPropertyList(String indexProperty, List objects, boolean sortNeeded)`
  Creates a NumericPropertyOrderedList that decorates another list.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `void`
  `add(int index, Object element)`
  `protected int`
  `calculateIndexValue(int listIndex)`
  Calculates an index value at the specified list index.
  `Object`
  `get(int index)`
  `protected int`
  `getIndexValue(Object object)`
  `Object`
  `getValue()`
  Returns an object stored by this ValueHolder.
  `Object`
  `getValueDirectly()`
  Retrieves ValueHolder value without triggering fault resolution.
  `void`
  `invalidate()`
  Turns a ValueHolder into a fault.
  `boolean`
  `isFault()`
  Returns true if the internal value is not yet resolved.
  `Object`
  `remove(int index)`
  `Object`
  `set(int index, Object element)`
  `protected void`
  `setIndexValue(Object object, int index)`
  `Object`
  `setValue(Object value)`
  Sets an object stored by this ValueHolder.
  `Object`
  `setValueDirectly(Object value)`
  Sets ValueHolder vaue without triggering fault resolution.
  `protected void`
  `shift(int startIndex, int afterIndexValue)`
  `int`
  `size()`
  `protected void`
  `sort()`
  Sorts internal list.
  `void`
  `touch()`
  Changes list state to "dirty" forcing reordering on next access.

  ### Methods inherited from class java.util.AbstractList

  `add, addAll, clear, equals, hashCode, indexOf, iterator, lastIndexOf, listIterator, listIterator, removeRange, subList`

  ### Methods inherited from class java.util.AbstractCollection

  `addAll, contains, containsAll, isEmpty, remove, removeAll, retainAll, toArray, toArray, toString`

  ### 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

  `addAll, contains, containsAll, isEmpty, remove, removeAll, replaceAll, retainAll, sort, spliterator, toArray, toArray`

- ## Field Details

  - ### list

    protected List list
    A list used for the actual objects storage.

  - ### indexProperty

    protected String indexProperty

- ## Constructor Details

  - ### IndexPropertyList

    public IndexPropertyList(String indexProperty)
    Creates an empty NumericPropertyOrderedList.

  - ### IndexPropertyList

    public IndexPropertyList(String indexProperty, List objects, boolean sortNeeded)
    Creates a NumericPropertyOrderedList that decorates another list. If the list is not known to be properly sorted, caller must set sortNeeded to true. This will result in sorting the original list on first access attempt.

- ## Method Details

  - ### isFault

    public boolean isFault()
    Description copied from interface: `ValueHolder`
    Returns true if the internal value is not yet resolved.
    Specified by:
      `isFault` in interface `ValueHolder`

  - ### setValueDirectly

    public Object setValueDirectly(Object value) throws CayenneRuntimeException
    Description copied from interface: `ValueHolder`
    Sets ValueHolder vaue without triggering fault resolution.
    Specified by:
      `setValueDirectly` in interface `ValueHolder`
    Throws:
      `CayenneRuntimeException`

  - ### setValue

    public Object setValue(Object value) throws CayenneRuntimeException
    Description copied from interface: `ValueHolder`
    Sets an object stored by this ValueHolder.
    Specified by:
      `setValue` in interface `ValueHolder`
    Parameters:
      `value` - a new value of the ValueHolder.
    Returns:
      a previous value saved in the ValueHolder.
    Throws:
      `CayenneRuntimeException`

  - ### getValue

    public Object getValue() throws CayenneRuntimeException
    Description copied from interface: `ValueHolder`
    Returns an object stored by this ValueHolder.
    Specified by:
      `getValue` in interface `ValueHolder`
    Throws:
      `CayenneRuntimeException`

  - ### getValueDirectly

    public Object getValueDirectly() throws CayenneRuntimeException
    Description copied from interface: `ValueHolder`
    Retrieves ValueHolder value without triggering fault resolution.
    Specified by:
      `getValueDirectly` in interface `ValueHolder`
    Throws:
      `CayenneRuntimeException`

  - ### invalidate

    public void invalidate()
    Description copied from interface: `ValueHolder`
    Turns a ValueHolder into a fault.
    Specified by:
      `invalidate` in interface `ValueHolder`

  - ### touch

    public void touch()
    Changes list state to "dirty" forcing reordering on next access.

  - ### get

    public Object get(int index)
    Specified by:
      `get` in interface `List`
    Specified by:
      `get` in class `AbstractList`

  - ### size

    public int size()
    Specified by:
      `size` in interface `Collection`
    Specified by:
      `size` in interface `List`
    Specified by:
      `size` in class `AbstractCollection`

  - ### set

    public Object set(int index, Object element)
    Specified by:
      `set` in interface `List`
    Overrides:
      `set` in class `AbstractList`

  - ### add

    public void add(int index, Object element)
    Specified by:
      `add` in interface `List`
    Overrides:
      `add` in class `AbstractList`

  - ### remove

    public Object remove(int index)
    Specified by:
      `remove` in interface `List`
    Overrides:
      `remove` in class `AbstractList`

  - ### calculateIndexValue

    protected int calculateIndexValue(int listIndex)
    Calculates an index value at the specified list index. Note that using this value may require a shift of the objects following this index.

  - ### getIndexValue

    protected int getIndexValue(Object object)

  - ### setIndexValue

    protected void setIndexValue(Object object, int index)

  - ### shift

    protected void shift(int startIndex, int afterIndexValue)

  - ### sort

    protected void sort()
    Sorts internal list.