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 SummaryFields Modifier and Type Field Description protected StringindexPropertyprotected ListlistA list used for the actual objects storage.Fields inherited from class java.util.AbstractListmodCount
- 
Constructor SummaryConstructors Constructor Description IndexPropertyList(String indexProperty)Creates an empty NumericPropertyOrderedList.IndexPropertyList(String indexProperty, List objects, boolean sortNeeded)Creates a NumericPropertyOrderedList that decorates another list.
- 
Method SummaryModifier and Type Method Description voidadd(int index, Object element)protected intcalculateIndexValue(int listIndex)Calculates an index value at the specified list index.Objectget(int index)protected intgetIndexValue(Object object)ObjectgetValue()Returns an object stored by this ValueHolder.ObjectgetValueDirectly()Retrieves ValueHolder value without triggering fault resolution.voidinvalidate()Turns a ValueHolder into a fault.booleanisFault()Returns true if the internal value is not yet resolved.Objectremove(int index)Objectset(int index, Object element)protected voidsetIndexValue(Object object, int index)ObjectsetValue(Object value)Sets an object stored by this ValueHolder.ObjectsetValueDirectly(Object value)Sets ValueHolder vaue without triggering fault resolution.protected voidshift(int startIndex, int afterIndexValue)intsize()protected voidsort()Sorts internal list.voidtouch()Changes list state to "dirty" forcing reordering on next access.Methods inherited from class java.util.AbstractListadd, addAll, clear, equals, hashCode, indexOf, iterator, lastIndexOf, listIterator, listIterator, removeRange, subListMethods inherited from class java.util.AbstractCollectionaddAll, contains, containsAll, isEmpty, remove, removeAll, retainAll, toArray, toArray, toStringMethods inherited from class java.lang.Objectclone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface java.util.CollectionparallelStream, removeIf, stream, toArrayMethods inherited from interface java.util.ListaddAll, contains, containsAll, isEmpty, remove, removeAll, replaceAll, retainAll, sort, spliterator, toArray, toArray
- 
Field Details- 
listA list used for the actual objects storage.
- 
indexProperty
 
- 
- 
Constructor Details- 
IndexPropertyListCreates an empty NumericPropertyOrderedList.
- 
IndexPropertyListCreates 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- 
isFaultpublic boolean isFault()Description copied from interface:ValueHolderReturns true if the internal value is not yet resolved.- Specified by:
- isFaultin interface- ValueHolder
 
- 
setValueDirectlyDescription copied from interface:ValueHolderSets ValueHolder vaue without triggering fault resolution.- Specified by:
- setValueDirectlyin interface- ValueHolder
- Throws:
- CayenneRuntimeException
 
- 
setValueDescription copied from interface:ValueHolderSets an object stored by this ValueHolder.- Specified by:
- setValuein interface- ValueHolder
- Parameters:
- value- a new value of the ValueHolder.
- Returns:
- a previous value saved in the ValueHolder.
- Throws:
- CayenneRuntimeException
 
- 
getValueDescription copied from interface:ValueHolderReturns an object stored by this ValueHolder.- Specified by:
- getValuein interface- ValueHolder
- Throws:
- CayenneRuntimeException
 
- 
getValueDirectlyDescription copied from interface:ValueHolderRetrieves ValueHolder value without triggering fault resolution.- Specified by:
- getValueDirectlyin interface- ValueHolder
- Throws:
- CayenneRuntimeException
 
- 
invalidatepublic void invalidate()Description copied from interface:ValueHolderTurns a ValueHolder into a fault.- Specified by:
- invalidatein interface- ValueHolder
 
- 
touchpublic void touch()Changes list state to "dirty" forcing reordering on next access.
- 
get- Specified by:
- getin interface- List
- Specified by:
- getin class- AbstractList
 
- 
sizepublic int size()- Specified by:
- sizein interface- Collection
- Specified by:
- sizein interface- List
- Specified by:
- sizein class- AbstractCollection
 
- 
set- Specified by:
- setin interface- List
- Overrides:
- setin class- AbstractList
 
- 
add- Specified by:
- addin interface- List
- Overrides:
- addin class- AbstractList
 
- 
remove- Specified by:
- removein interface- List
- Overrides:
- removein class- AbstractList
 
- 
calculateIndexValueprotected 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
- 
setIndexValue
- 
shiftprotected void shift(int startIndex, int afterIndexValue)
- 
sortprotected void sort()Sorts internal list.
 
-