Package org.apache.cayenne.util
Class IndexPropertyList
java.lang.Object
java.util.AbstractCollection
java.util.AbstractList
org.apache.cayenne.util.IndexPropertyList
- All Implemented Interfaces:
Serializable,Iterable,Collection,List,SequencedCollection,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:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected Stringprotected ListA list used for the actual objects storage.Fields inherited from class java.util.AbstractList
modCount -
Constructor Summary
ConstructorsConstructorDescriptionIndexPropertyList(String indexProperty) Creates an empty NumericPropertyOrderedList.IndexPropertyList(String indexProperty, List objects, boolean sortNeeded) Creates a NumericPropertyOrderedList that decorates another list. -
Method Summary
Modifier and TypeMethodDescriptionvoidprotected intcalculateIndexValue(int listIndex) Calculates an index value at the specified list index.get(int index) protected intgetIndexValue(Object object) getValue()Returns an object stored by this ValueHolder.Retrieves ValueHolder value without triggering fault resolution.voidTurns a ValueHolder into a fault.booleanisFault()Returns true if the internal value is not yet resolved.remove(int index) protected voidsetIndexValue(Object object, int index) Sets an object stored by this ValueHolder.setValueDirectly(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, subListMethods inherited from class java.util.AbstractCollection
addAll, contains, containsAll, isEmpty, remove, removeAll, retainAll, toArray, toArray, toStringMethods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface java.util.Collection
parallelStream, removeIf, stream, toArrayMethods inherited from interface java.util.List
addAll, addFirst, addLast, contains, containsAll, getFirst, getLast, isEmpty, remove, removeAll, removeFirst, removeLast, replaceAll, retainAll, reversed, sort, spliterator, toArray, toArray
-
Field Details
-
list
A list used for the actual objects storage. -
indexProperty
-
-
Constructor Details
-
IndexPropertyList
Creates an empty NumericPropertyOrderedList. -
IndexPropertyList
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:ValueHolderReturns true if the internal value is not yet resolved.- Specified by:
isFaultin interfaceValueHolder
-
setValueDirectly
Description copied from interface:ValueHolderSets ValueHolder vaue without triggering fault resolution.- Specified by:
setValueDirectlyin interfaceValueHolder- Throws:
CayenneRuntimeException
-
setValue
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
Description copied from interface:ValueHolderReturns an object stored by this ValueHolder.- Specified by:
getValuein interfaceValueHolder- Throws:
CayenneRuntimeException
-
getValueDirectly
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
- 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
- Specified by:
setin interfaceList- Overrides:
setin classAbstractList
-
add
- Specified by:
addin interfaceList- Overrides:
addin classAbstractList
-
remove
- 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
-
setIndexValue
-
shift
protected void shift(int startIndex, int afterIndexValue) -
sort
protected void sort()Sorts internal list.
-