public Position getAdjacentItemPosition(Position position, Direction direction) {
    Position adjacent;

    Coordinate displacement = getDisplacement(direction);
    int adjacentColumn = position.getColumn() + displacement.getX();
    int adjacentRow = position.getRow() + displacement.getY();

    int numberOfRows = getNumberOfRows();
    int numberOfColumns = getNumberOfColumns();
    int numberOfItems = getNumberOfItems();

    if (adjacentColumn < 0 || adjacentColumn >= numberOfColumns
        || adjacentRow < 0 || adjacentRow > numberOfRows
        || adjacentColumn + numberOfColumns * adjacentRow >= numberOfItems) {
      adjacent = Position.INVALID_POSITION;
    } else {
      adjacent = new Position(
          numberOfColumns * adjacentRow + adjacentColumn,
          adjacentColumn,
          adjacentRow,
          numberOfColumns - 1,
          numberOfRows - 1);
    }

    return adjacent;
  }
Returns the position adjacent to the provided one in a specific direction.
dividers/src/main/java/com/karumi/dividers/PositionAdapter.java