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
Modifier and TypeFieldDescriptionprotected String
protected List
A list used for the actual objects storage.Fields inherited from class java.util.AbstractList
modCount
-
Constructor Summary
ConstructorDescriptionIndexPropertyList
(String indexProperty) Creates an empty NumericPropertyOrderedList.IndexPropertyList
(String indexProperty, List objects, boolean sortNeeded) Creates a NumericPropertyOrderedList that decorates another list. -
Method Summary
Modifier and TypeMethodDescriptionvoid
protected int
calculateIndexValue
(int listIndex) Calculates an index value at the specified list index.get
(int index) protected int
getIndexValue
(Object object) getValue()
Returns an object stored by this ValueHolder.Retrieves ValueHolder value without triggering fault resolution.void
Turns a ValueHolder into a fault.boolean
isFault()
Returns true if the internal value is not yet resolved.remove
(int index) protected void
setIndexValue
(Object object, int index) Sets an object stored by this ValueHolder.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.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:ValueHolder
Returns true if the internal value is not yet resolved.- Specified by:
isFault
in interfaceValueHolder
-
setValueDirectly
Description copied from interface:ValueHolder
Sets ValueHolder vaue without triggering fault resolution.- Specified by:
setValueDirectly
in interfaceValueHolder
- Throws:
CayenneRuntimeException
-
setValue
Description copied from interface:ValueHolder
Sets an object stored by this ValueHolder.- Specified by:
setValue
in interfaceValueHolder
- Parameters:
value
- a new value of the ValueHolder.- Returns:
- a previous value saved in the ValueHolder.
- Throws:
CayenneRuntimeException
-
getValue
Description copied from interface:ValueHolder
Returns an object stored by this ValueHolder.- Specified by:
getValue
in interfaceValueHolder
- Throws:
CayenneRuntimeException
-
getValueDirectly
Description copied from interface:ValueHolder
Retrieves ValueHolder value without triggering fault resolution.- Specified by:
getValueDirectly
in interfaceValueHolder
- Throws:
CayenneRuntimeException
-
invalidate
public void invalidate()Description copied from interface:ValueHolder
Turns a ValueHolder into a fault.- Specified by:
invalidate
in interfaceValueHolder
-
touch
public void touch()Changes list state to "dirty" forcing reordering on next access. -
get
- Specified by:
get
in interfaceList
- Specified by:
get
in classAbstractList
-
size
public int size()- Specified by:
size
in interfaceCollection
- Specified by:
size
in interfaceList
- Specified by:
size
in classAbstractCollection
-
set
- Specified by:
set
in interfaceList
- Overrides:
set
in classAbstractList
-
add
- Specified by:
add
in interfaceList
- Overrides:
add
in classAbstractList
-
remove
- Specified by:
remove
in interfaceList
- Overrides:
remove
in 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.
-