Search backwards from this position for the first non-null value.
@param iTargetPosition The position to retrieve this bookmark from.
@return index of non-null value or -1 if all lower values are null.
507199
private int lowestNonNullIndex(int iTargetPosition)
    {
        Object bookmark = null;
        int iBookmarkIndex = iTargetPosition;
        while (bookmark == null)
        {
            int iArrayIndex = m_gridList.listToArrayIndex(iBookmarkIndex);
            iBookmarkIndex =  m_gridList.arrayToListIndex(iArrayIndex);   // Lowest valid bookmark
            bookmark = m_gridList.elementAt(iBookmarkIndex);
            if (bookmark == null)
            {
                if (iBookmarkIndex == 0)
                    return -1;  // None found
                iBookmarkIndex--;
                if (m_gridBuffer != null)
                    bookmark = m_gridBuffer.elementAt(iBookmarkIndex);  // Check to see if it's in this list
            }
        }
        return iBookmarkIndex;  // Valid bookmark, return it.
    }
366952
public int readNextToTarget(int iTargetPosition, int iRelPosition) throws DBException
    {
        int iRecordStatus = DBConstants.RECORD_NORMAL;
        boolean bMore = true;
        ResultSet resultSet = (ResultSet)this.getResultSet();
        while (m_iRow < iTargetPosition)
        {   // Spin until you get to the row or hit EOF
            try   {
                bMore = resultSet.next();
                if (!bMore)
                {
                    m_iEOFRow = m_iRow;   // Last physical row = this row - 1.
                    break;  // Hit EOF
                }
                m_iRow++; // Current row
            } catch (SQLException e)    {
                DBException dbEx = this.getDatabase().convertError(e);
                int iErrorCode = dbEx.getErrorCode();
                if ((iRelPosition == DBConstants.FIRST_RECORD) || ((iRelPosition == DBConstants.LAST_RECORD)))
                    if (iErrorCode == DBConstants.INVALID_RECORD)
                        return (DBConstants.RECORD_INVALID | DBConstants.RECORD_AT_BOF | DBConstants.RECORD_AT_EOF);    // Move first - no records
                throw dbEx;
            }
        }
        if ((m_iRow == -1) || (iTargetPosition == -1))
            iRecordStatus |= DBConstants.RECORD_INVALID | DBConstants.RECORD_AT_BOF;
        if (!bMore)
        {
            iRecordStatus |= DBConstants.RECORD_AT_EOF;
            int iEOFRow = m_iEOFRow;   // Save for a sec
            this.setResultSet(null, DBConstants.SQL_SELECT_TYPE);  // Can't use anymore
            m_iEOFRow = iEOFRow;       // I do know the EOF
        }
        return iRecordStatus;
    }
430414
private boolean goToNextStartPosition() throws IOException {
    int basicStartPositionMin;
    int basicStartPositionMax;
    int basicEndPosition;
    int basicEndPositionMin;
    int basicEndPositionMax;
    if (docId == -1 || docId == NO_MORE_DOCS) {
      throw new IOException("no document");
    } else {
      if (lastCollectedStartPosition < NO_MORE_POSITIONS
          && (collectedPositions.isEmpty()
              || (collectedPositions.firstKey() >= (lastCollectedStartPosition
                  - query.maximumLeft)))) {
        // collect new positions
        while ((lastCollectedStartPosition = subSpans
            .nextStartPosition()) != NO_MORE_POSITIONS) {
          basicEndPosition = subSpans.endPosition();
          basicStartPositionMin = Math.max(minPosition,
              lastCollectedStartPosition - query.maximumLeft);
          basicStartPositionMax = lastCollectedStartPosition
              - query.minimumLeft;
          basicEndPositionMin = basicEndPosition + query.minimumRight;
          basicEndPositionMax = Math.min(maxPosition + 1,
              basicEndPosition + query.maximumRight);
          for (int cLeft = basicStartPositionMin; cLeft <= basicStartPositionMax; cLeft++) {
            for (int cRight = basicEndPositionMin; cRight <= basicEndPositionMax; cRight++) {
              if (!collectedPositions.containsKey(cLeft)) {
                collectedPositions.put(cLeft, new ArrayList<Integer>());
              }
              collectedPositions.get(cLeft).add(cRight);
            }
          }
          if (!collectedPositions.isEmpty() && (collectedPositions
              .firstKey() < (lastCollectedStartPosition - query.maximumLeft))) {
            break;
          }
        }
      }
      if (collectedPositions.isEmpty()) {
        return false;
      } else {
        startPosition = collectedPositions.firstKey();
        endPosition = collectedPositions.get(startPosition).remove(0);
        if (collectedPositions.get(startPosition).isEmpty()) {
          collectedPositions.remove(startPosition);
        }
        return true;
      }
    }
  }
925714
public Optional<CellPosition> getPosition(final Object targetObj) {
        ArgUtils.notNull(targetObj, "targetObj");
        
        return positionGetter.map(getter -> getter.get(targetObj)).orElse(Optional.empty());
    }
896131
public int getEndPosition(Tree node) {
    JCCompilationUnit compilationUnit = (JCCompilationUnit) getPath().getCompilationUnit();
    if (compilationUnit.endPositions == null) {
      return -1;
    }
    return ((JCTree) node).getEndPosition(compilationUnit.endPositions);
  }
515126
public Integer getEnd() {
    if (mtasPositionType.equals(POSITION_RANGE)
        || mtasPositionType.equals(POSITION_SET)) {
      return mtasPositionEnd;
    } else if (mtasPositionType.equals(POSITION_SINGLE)) {
      return mtasPositionStart;
    } else {
      return null;
    }
  }
301292
protected long getAbsolutePosition(final long[] iFilePosition) {
    long position = 0;
    for (int i = 0; i < iFilePosition[0]; ++i) {
      position += fileMaxSize;
    }
    return position + iFilePosition[1];
  }
1098084
public synchronized List<Message> getFromRange(final int startPosition, final int endPosition) {
        // cache this here, so all parts of the method operate on the same data
        final int firstMessageId = this.getFirstPosition();
        // input validation
        if ((startPosition < MessageStore.INITIAL_MESSAGE_POSITION)
                || (endPosition < MessageStore.INITIAL_MESSAGE_POSITION)) {
            throw new IllegalArgumentException("Message position cannot be negative.");
        } else if ((firstMessageId >= MessageStore.INITIAL_MESSAGE_POSITION) && (startPosition < firstMessageId)) {
            throw new IllegalArgumentException("Message at position " + startPosition
                    + " had already been discarded. First available message position is " + firstMessageId + ".");
        } else if (endPosition <= startPosition) {
            throw new IllegalArgumentException("Ending position must be larger than starting message position.");
        } else if (endPosition > this.getNextPosition()) {
            throw new IllegalArgumentException("Range end cannot be greater than the next message position.");
        }
        // and properly synchronized range retrieval
        return Collections.unmodifiableList(new LinkedList<>(this.store.subMap(startPosition, endPosition)
                .values()));
    }
117317
public void addElement(int iTargetPosition, Object bookmark)
    {
        if (iTargetPosition >= m_iRecordListMax)
            this.growAccessList(iTargetPosition);
        if (iTargetPosition >= m_iRecordListEnd)
            m_iRecordListEnd = iTargetPosition + 1;   // New logical end
        if (!this.validRecordIndex(iTargetPosition))
            return;     // This one doesn't belong in this list
    
        int iArrayIndex = this.listToArrayIndex(iTargetPosition);
        m_aRecords[iArrayIndex] = bookmark;
    }
763172
@Nullable
    private String getItemKey(int position) {
        if (mMap != null) {
            return new ArrayList<>(mMap.entrySet()).get(position).getKey();
        } else if (mJsonArray != null) {
            return String.valueOf(position);
        }
        return null;
    }
838114
public ParameterBinding getBindingFor(int position) {

        for (ParameterBinding binding : bindings) {
            if (binding.hasPosition(position)) {
                return binding;
            }
        }

        throw new IllegalArgumentException(String.format("No parameter binding found for position %s!", position));
    }
330505
public boolean inBufferList(int iTargetPosition)
    {
        boolean bInBufferList = ((iTargetPosition >= m_iCurrentRecordStart) && (iTargetPosition < m_iCurrentRecordEnd));
        if (bInBufferList)
            if (m_aCurrentRecord[this.bufferToArrayIndex(iTargetPosition)] == gEmptyCell)
                bInBufferList = false;
        return bInBufferList;
    }
718975
public Long getRelativePosition(Long position) {
		long relativePosition = 0L;
		for (Location location : locations) {
			if (location instanceof RemoteLocation) {
				relativePosition += location.getLength();
			} else {
				if (position < location.getBeginPosition()
						|| position > location.getEndPosition()) {
					relativePosition += location.getLength();
				} else {
					if (location.isComplement()) {
						relativePosition += (location.getEndPosition()
								- position + 1);
					} else {
						relativePosition += (position
								- location.getBeginPosition() + 1);
					}
					if (isComplement()) {
						relativePosition = getLength() - relativePosition + 1;
					}
					return relativePosition;
				}
			}
		}
		return null;
	}
1077846
private int binarySearch(int position) {
		int[] minSeqIndex = getMinSequenceIndex();
		int[] maxSeqIndex = getMaxSequenceIndex();

		int low = 0;
		int high = minSeqIndex.length - 1;
		while (low <= high) {
			//Go to the mid point in the array
			int mid = (low + high) >>> 1;

			//Get the max position represented by this Sequence
			int midMinPosition = minSeqIndex[mid];
			int midMaxPosition = maxSeqIndex[mid];

			//if current position is greater than the current bounds then
			//increase search space
			if (midMinPosition < position && midMaxPosition < position) {
				low = mid + 1;
			} //if current position is less than current bounds then decrease
			//search space
			else if (midMinPosition > position && midMaxPosition > position) {
				high = mid - 1;
			} else {
				return mid;
			}
		}
		throw new IndexOutOfBoundsException("Given position " + position + " does not map into this Sequence");
	}
386552
private int findBacktrackPosition(final int position) {
        int currentPosition = position;

        // check against stack size after the instruction was executed
        while (stackSizes.get(currentPosition).getRight() > 0) {
            currentPosition++;
        }

        return currentPosition;
    }
1104913
public Object elementAt(int iTargetPosition)
    {
        Record record = null;
        Object bookmark = null;
        if (m_iEndOfFileIndex != UNKNOWN_POSITION) if (iTargetPosition >= m_iEndOfFileIndex)
            return null;    // Past/At EOF
        if (!m_gridBuffer.inBufferList(iTargetPosition))
        {
            bookmark = m_gridList.elementAt(iTargetPosition);
            if (bookmark != null)
                return bookmark;    // In grid list, return it!
            // Find the next lower item in the list
            int iLowestNonNullIndex = this.lowestNonNullIndex(iTargetPosition);
            if (iLowestNonNullIndex != -1)
            {
                bookmark = m_gridList.elementAt(iLowestNonNullIndex);
                if (bookmark == null)
                    bookmark = m_gridBuffer.elementAt(iLowestNonNullIndex);
            }
            
            boolean bFindTargetUsingCurrentQuery = false;
            if (bookmark == null)
                bFindTargetUsingCurrentQuery = true;
            else
            {
                if (iTargetPosition == m_iPhysicalFilePosition + 1)
                    if (m_bIsSequentialQueryValid)
                        bFindTargetUsingCurrentQuery = true;
            }

            if (!bFindTargetUsingCurrentQuery)
            { // This record is not in the grid list, because the granularity is too great
                // Read the record before it, and move forward.
                // Move to > bookmark, and move next until you hit this target.
                this.getNextTable().setDataRecord((DataRecord)bookmark);
                record = this.getRecord();
                if (m_behCompare != null)
                    record.removeListener(m_behCompare, true);
                m_behCompare = new SubCurrentFilter(true, false);
                m_behCompare.setMasterSlaveFlag(RecordOwner.MASTER | RecordOwner.SLAVE);    // Should run in either space
                record.addListener(m_behCompare);
                this.getNextTable().close();
                this.getRecord().setOpenMode(this.getRecord().getOpenMode() | DBConstants.OPEN_SUPPRESS_MESSAGES);   // Don't send an "AFTER_REQUERY_TYPE" message
                try   {
                    m_iPhysicalFilePosition = iLowestNonNullIndex - 1;
                    m_bIsSequentialQueryValid = true;
                    record = (Record)this.move(+1);
                    m_iPhysicalFilePosition = iLowestNonNullIndex;
                } catch (DBException e)   {
                    record = null;
                } finally {
                    this.getRecord().setOpenMode(this.getRecord().getOpenMode() & ~DBConstants.OPEN_SUPPRESS_MESSAGES);
                }
                if (record == null) if (m_behCompare != null)
                {
                    this.getRecord().removeListener(m_behCompare, true);
                    m_behCompare = null;
                }
            }

            try   {
                int iCurrentPosition = m_iPhysicalFilePosition;
                if (iCurrentPosition == -1)
                {
                    for (iCurrentPosition = 0; ; iCurrentPosition++)
                    {       // Find the first non-deleted record
                        if ((!m_gridBuffer.inBufferList(iCurrentPosition))
                            || (m_gridBuffer.elementAt(iCurrentPosition) != null))
                                break;
                    }
                    record = (Record)this.move(DBConstants.FIRST_RECORD);
                    if (record != null)
                    {
                        if (iCurrentPosition != 0)
                        {
                            bookmark = m_gridList.elementAt(0);
                            if (bookmark == null)
                                bookmark = m_gridBuffer.elementAt(0);
                            m_gridBuffer.addElement(0, null, m_gridList);   // Set this as deleted again
                            m_gridBuffer.addElement(iCurrentPosition, bookmark, m_gridList);   // Set this in the right logical position
                            m_iPhysicalFilePosition = iCurrentPosition;
                        }
                    }
                    else
                    {
                        iTargetPosition = 0;    // Make sure current position = 0!
                        m_iEndOfFileIndex = 0;  // EOF + 1
                    }
                }
                int iMoveRelative = iTargetPosition - iCurrentPosition;
                if (iMoveRelative < 0)
                    record = (Record)this.move(iMoveRelative);
                else
                {
                    while (iMoveRelative > 0)
                    {
                        if ((m_gridBuffer.inBufferList(m_iPhysicalFilePosition + 1))
                            && (m_gridBuffer.elementAt(m_iPhysicalFilePosition + 1) == null))
                        {
                            m_iPhysicalFilePosition++;  // This record shows deleted, don't fill with a record.
                        }
                        else
                        {
                            record = (Record)this.move(+1);
                            if (record == null)
                                break;
                        }
                        iMoveRelative--;
                    }
                }
                m_bIsSequentialQueryValid = true; // The query is in force, you may use move(+1) next time (instead of starting a new query)
            } catch (DBException ex)    {
                ex.printStackTrace();
                record = null;
            }
            m_iPhysicalFilePosition = iTargetPosition;
            if (m_behCompare != null)
            {
                this.getRecord().removeListener(m_behCompare, true);
                m_behCompare = null;
            }
            if (record == null)
                return null;
        }
        if (m_gridBuffer.inBufferList(iTargetPosition))
            bookmark = m_gridBuffer.elementAt(iTargetPosition);
        else
            bookmark = m_gridList.elementAt(iTargetPosition);
        return bookmark;
    }
561136
public ScreenLocation getNextLocation(short position, short setNewAnchor)
    {
        if (position == ScreenConstants.FIRST_LOCATION)
            position = ScreenConstants.FIRST_INPUT_LOCATION;
        if (position == ScreenConstants.NEXT_LOGICAL)
            position = ScreenConstants.BELOW_LAST_ANCHOR;
        return super.getNextLocation(position, setNewAnchor);
    }