Class Cursor<TElement,TKey>

java.lang.Object
com._1c.g5.v8.dt.common.search.Cursor<TElement,TKey>
Type Parameters:
TElement - type of collection elements
TKey - type of key used for hashing elements position
All Implemented Interfaces:
ICursor<TElement>
Direct Known Subclasses:
BorderedCursor

public abstract class Cursor<TElement,TKey> extends Object implements ICursor<TElement>
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 Details

    • input

      protected List<TElement> input
      Base input.
    • mapElementToPosition

      protected Map<TKey,Integer> mapElementToPosition
      Map containing elements.
    • hashRetriever

      protected Function<TElement,TKey> hashRetriever
      Hash function for fast element position retrieval.
    • position

      protected int position
      Position of current element.
  • Constructor Details

    • Cursor

      protected Cursor(Function<TElement,TKey> hashRetriever)
      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 via hashRetriever return value, cannot be null
  • Method Details

    • init

      public void init(List<TElement> input)
      Description copied from interface: ICursor
      Initializes by the specified list of elements.
      Specified by:
      init in interface ICursor<TElement>
      Parameters:
      input - the list of elements, can not be null
    • current

      public TElement current()
      Description copied from interface: ICursor
      Gets current element at cursor position.
      Specified by:
      current in interface ICursor<TElement>
      Returns:
      the current element; null after initialization
    • hasNext

      public boolean hasNext()
      Description copied from interface: ICursor
      Checks for the availability to move cursor to the next element.
      Specified by:
      hasNext in interface ICursor<TElement>
      Returns:
      true if has previous element for the cursor; otherwise, false
    • next

      public TElement next()
      Description copied from interface: ICursor
      Moves cursor to the next element.
      Specified by:
      next in interface ICursor<TElement>
      Returns:
      the next element
      See Also:
    • hasPrevious

      public boolean hasPrevious()
      Description copied from interface: ICursor
      Checks for the availability to move cursor to the previous element.
      Specified by:
      hasPrevious in interface ICursor<TElement>
      Returns:
      true if has previous element for the cursor; otherwise, false
    • previous

      public TElement previous()
      Description copied from interface: ICursor
      Moves cursor to the previous element.
      Specified by:
      previous in interface ICursor<TElement>
      Returns:
      the previous element
      See Also:
    • repositionToTheBeginning

      public void repositionToTheBeginning()
      Description copied from interface: ICursor
      Repositions to the begining of data.
      Specified by:
      repositionToTheBeginning in interface ICursor<TElement>
    • repositionTo

      public int repositionTo(TElement element)
      Description copied from interface: ICursor
      Repositions to specific element.
      Specified by:
      repositionTo in interface ICursor<TElement>
      Parameters:
      element - the element to which to reposition, can not be null
    • repositionBy

      public int repositionBy(Predicate<TElement> condition)
      Description copied from interface: ICursor
      Repositions to element by according to the specific condition.
      Specified by:
      repositionBy in interface ICursor<TElement>
      Parameters:
      condition - the condition for repositioning, can not be null
    • repositionToTheEnd

      public void repositionToTheEnd()
      Description copied from interface: ICursor
      Repositions to the end of data.
      Specified by:
      repositionToTheEnd in interface ICursor<TElement>
    • canRepositionTo

      public boolean canRepositionTo(TElement element)
      Description copied from interface: ICursor
      Checks if the cursor can be repositioned to element, i.e. is present in collection.
      Specified by:
      canRepositionTo in interface ICursor<TElement>
      Parameters:
      element - the element to check ability to reposition, can not be null
      Returns:
      true if cursor can be repositioned to element, false otherwise