/**
   * Fills in the null values of a locationArray by taking the average value of the null value's
   * neighbors. This method should be used after an array is expanded, and calls the methods
   * firstPass and secondPass to fill in the data
   *
   * @param locationArray - The LocationBean[][] to be filled in
   * @param debug - the LEVEL of debugging
   * @return the locationArray after completely filling in all null values
   */
  @Deprecated
  public LocationBean[][] fillInArray(LocationBean[][] locationArray, LEVEL debug) {
    double xStep = 0.0;
    double yStep = 0.0;

    double lat1 = locationArray[0][0].getLatitude();
    double lat2 = locationArray[0][2].getLatitude();
    double lon1 = locationArray[0][0].getLongitude();
    double lon2 = locationArray[2][0].getLongitude();
    xStep = (lat2 - lat1) / 2;
    yStep = (lon2 - lon1) / 2;

    if (debug.getLevel() >= 3)
      System.out.println("Initial lats: " + lat1 + " " + lat2 + " | step = " + xStep);
    if (debug.getLevel() >= 3)
      System.out.println("Initial lons: " + lon1 + " " + lon2 + " | step = " + yStep);

    locationArray = firstPass(locationArray, debug);

    if (debug.getLevel() >= 2) System.out.println("After first pass");
    if (debug.getLevel() >= 2) printLocationWeightsAsMap(locationArray);

    locationArray = secondPass(locationArray, debug, xStep, yStep);

    return locationArray;
  }
  /**
   * This method fills in all null values in the 2D array that are surrounded by other null values
   *
   * <p>Ex (x indicates a null value): initial array: New array: 1 x 2 1 x 2 x x x x 2.5 x 3 x 4 3 x
   * 4
   *
   * @param locationArray - The LocationBean[][] to be filled in
   * @param debug - the LEVEL of debugging
   * @return the partially filled in locationArray
   */
  @Deprecated
  public LocationBean[][] firstPass(LocationBean[][] locationArray, LEVEL debug) {
    int rows = locationArray[0].length;
    int cols = locationArray.length;

    for (int x = 0; x < rows; x++) {
      for (int y = 0; y < cols; y++) {
        double sum = 0.0;
        if (debug.getLevel() >= 3) System.out.print(x + " " + y);
        if (locationArray[y][x] == null
            && 0 < y
            && y < cols - 1 // make sure it's not at an edge
            && 0 < x
            && x < rows - 1
            && locationArray[y - 1][x]
                == null // make sure it's not "in between" two other items but is instead the center
                        // of an X
            && locationArray[y - 1][x - 1] != null // make sure that all four points have values
            && locationArray[y - 1][x - 1] != null
            && locationArray[y - 1][x - 1] != null
            && locationArray[y - 1][x - 1] != null) {
          sum +=
              locationArray[y - 1][x - 1].getWeight()
                  + locationArray[y + 1][x - 1].getWeight()
                  + locationArray[y - 1][x + 1].getWeight()
                  + locationArray[y + 1][x + 1].getWeight();

          if (debug.getLevel() >= 3) System.out.print(sum);
          double average = sum / 4;
          double lat =
              (locationArray[y + 1][x + 1].getLatitude()
                      + locationArray[y - 1][x - 1].getLatitude())
                  / 2;
          double lon =
              (locationArray[y + 1][x + 1].getLongitude()
                      + locationArray[y - 1][x - 1].getLongitude())
                  / 2;
          locationArray[y][x] = new LocationBean(lat, lon, average);
        }
        if (debug.getLevel() >= 3) System.out.println();
      }
    }

    return locationArray;
  }
  /**
   * This method fills in all null values in the 2D array that remain after the first pass
   *
   * <p>Ex (x indicates a null value): initial array: New array: 1 x 2 1 1.5 2 x 2.5 x 2 2.5 3 3 x 4
   * 3 3.5 4
   *
   * @param locationArray - The LocationBean[][] to be filled in
   * @param debug - the LEVEL of debugging
   * @param lonStep - double distance between longitudes
   * @param latStep - double distance between latitudes
   * @return the filled in locationArray
   */
  @Deprecated
  public LocationBean[][] secondPass(
      LocationBean[][] locationArray, LEVEL debug, double lonStep, double latStep) {
    int rows = locationArray[0].length;
    int cols = locationArray.length;

    for (int x = 0; x < rows; x++) {
      for (int y = 0; y < cols; y++) {
        double sum = 0.0;
        int count = 0;
        if (debug.getLevel() >= 3) System.out.print(x + " " + y);
        if (locationArray[y][x] == null) {
          if (y > 0) {
            if (debug.getLevel() >= 4) System.out.print("a");
            sum += locationArray[y - 1][x].getWeight();
            count++;
          }
          if (x > 0) {
            if (debug.getLevel() >= 4) System.out.print("b");
            sum += locationArray[y][x - 1].getWeight();
            count++;
          }
          if (y < cols - 1) {
            if (debug.getLevel() >= 4) System.out.print("c");
            sum += locationArray[y + 1][x].getWeight();
            count++;
          }
          if (x < rows - 1) {
            if (debug.getLevel() >= 4) System.out.print("d");
            sum += locationArray[y][x + 1].getWeight();
            count++;
          }

          double average = sum / count;

          double lat = 0.0;
          double lon = 0.0;

          if (y == 0 || y == cols - 1) {
            lon = locationArray[y][x - 1].getLongitude();
          } else {
            lon =
                (locationArray[y - 1][x].getLongitude() + locationArray[y + 1][x].getLongitude())
                    / 2;
          }
          if (x == 0 || x == rows - 1) {
            lat = locationArray[y - 1][x].getLatitude();
          } else {
            lat =
                (locationArray[y][x - 1].getLatitude() + locationArray[y][x + 1].getLatitude()) / 2;
          }

          locationArray[y][x] = new LocationBean(lat, lon, average);
        }
        if (debug.getLevel() >= 3) System.out.println();
      }
    }

    return locationArray;
  }