Package com._1c.g5.v8.dt.common.search
Class Cursor<TElement,TKey>
java.lang.Object
com._1c.g5.v8.dt.common.search.Cursor<TElement,TKey>
- Type Parameters:
TElement
- type of collection elementsTKey
- type of key used for hashing elements position
- All Implemented Interfaces:
ICursor<TElement>
- Direct Known Subclasses:
BorderedCursor
Represents an abstract generic navigation cursor over input with fast access to any element position of collection.
When reposition to specific element is needed, hash function is used. If
TElement
can be hashed
it is enough to pass Function.identity()
.-
Field Summary
FieldsModifier and TypeFieldDescriptionHash function for fast element position retrieval.Base input.Map containing elements.protected int
Position of current element. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionboolean
canRepositionTo
(TElement element) Checks if the cursor can be repositioned to element, i.e. is present in collection.current()
Gets current element at cursor position.boolean
hasNext()
Checks for the availability to move cursor to the next element.boolean
Checks for the availability to move cursor to the previous element.void
Initializes by the specified list of elements.next()
Moves cursor to the next element.previous()
Moves cursor to the previous element.int
repositionBy
(Predicate<TElement> condition) Repositions to element by according to the specific condition.int
repositionTo
(TElement element) Repositions to specific element.void
Repositions to the begining of data.void
Repositions to the end of data.
-
Field Details
-
input
Base input. -
mapElementToPosition
Map containing elements. -
hashRetriever
Hash function for fast element position retrieval. -
position
protected int positionPosition of current element.
-
-
Constructor Details
-
Cursor
Creates instance of cursor with given hash function for fast access to elements of collection.- Parameters:
hashRetriever
- ID function to access the related element from collection viahashRetriever
return value, cannot benull
-
-
Method Details
-
init
Description copied from interface:ICursor
Initializes by the specified list of elements. -
current
Description copied from interface:ICursor
Gets current element at cursor position. -
hasNext
public boolean hasNext()Description copied from interface:ICursor
Checks for the availability to move cursor to the next element. -
next
Description copied from interface:ICursor
Moves cursor to the next element. -
hasPrevious
public boolean hasPrevious()Description copied from interface:ICursor
Checks for the availability to move cursor to the previous element.- Specified by:
hasPrevious
in interfaceICursor<TElement>
- Returns:
true
if has previous element for the cursor; otherwise,false
-
previous
Description copied from interface:ICursor
Moves cursor to the previous element. -
repositionToTheBeginning
public void repositionToTheBeginning()Description copied from interface:ICursor
Repositions to the begining of data.- Specified by:
repositionToTheBeginning
in interfaceICursor<TElement>
-
repositionTo
Description copied from interface:ICursor
Repositions to specific element.- Specified by:
repositionTo
in interfaceICursor<TElement>
- Parameters:
element
- the element to which to reposition, can not benull
-
repositionBy
Description copied from interface:ICursor
Repositions to element by according to the specific condition.- Specified by:
repositionBy
in interfaceICursor<TElement>
- Parameters:
condition
- the condition for repositioning, can not benull
-
repositionToTheEnd
public void repositionToTheEnd()Description copied from interface:ICursor
Repositions to the end of data.- Specified by:
repositionToTheEnd
in interfaceICursor<TElement>
-
canRepositionTo
Description copied from interface:ICursor
Checks if the cursor can be repositioned to element, i.e. is present in collection.- Specified by:
canRepositionTo
in interfaceICursor<TElement>
- Parameters:
element
- the element to check ability to reposition, can not benull
- Returns:
true
if cursor can be repositioned to element,false
otherwise
-