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 StringindexPropertyprotected ListlistA 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
All Methods Instance Methods Concrete Methods Modifier 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.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.util.List
addAll, contains, containsAll, isEmpty, remove, removeAll, replaceAll, retainAll, sort, spliterator, toArray, toArray
-
-
-
-
Constructor Detail
-
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 Detail
-
isFault
public boolean isFault()
Description copied from interface:ValueHolderReturns true if the internal value is not yet resolved.- Specified by:
isFaultin interfaceValueHolder
-
setValueDirectly
public Object setValueDirectly(Object value) throws CayenneRuntimeException
Description copied from interface:ValueHolderSets ValueHolder vaue without triggering fault resolution.- Specified by:
setValueDirectlyin interfaceValueHolder- Throws:
CayenneRuntimeException
-
setValue
public Object setValue(Object value) throws CayenneRuntimeException
Description copied from interface:ValueHolderSets an object stored by this ValueHolder.- Specified by:
setValuein interfaceValueHolder- 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:ValueHolderReturns an object stored by this ValueHolder.- Specified by:
getValuein interfaceValueHolder- Throws:
CayenneRuntimeException
-
getValueDirectly
public Object getValueDirectly() throws CayenneRuntimeException
Description copied from interface:ValueHolderRetrieves ValueHolder value without triggering fault resolution.- Specified by:
getValueDirectlyin interfaceValueHolder- Throws:
CayenneRuntimeException
-
invalidate
public void invalidate()
Description copied from interface:ValueHolderTurns a ValueHolder into a fault.- Specified by:
invalidatein interfaceValueHolder
-
touch
public void touch()
Changes list state to "dirty" forcing reordering on next access.
-
get
public Object get(int index)
- Specified by:
getin interfaceList- Specified by:
getin classAbstractList
-
size
public int size()
- Specified by:
sizein interfaceCollection- Specified by:
sizein interfaceList- Specified by:
sizein classAbstractCollection
-
set
public Object set(int index, Object element)
- Specified by:
setin interfaceList- Overrides:
setin classAbstractList
-
add
public void add(int index, Object element)- Specified by:
addin interfaceList- Overrides:
addin classAbstractList
-
remove
public Object remove(int index)
- Specified by:
removein interfaceList- Overrides:
removein classAbstractList
-
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.
-
-