package com.google.sps.servlets;

import com.google.sps.data.Grid;
import com.google.sps.data.Location;
import java.io.FileReader;
import java.io.BufferedReader; 
import java.util.HashMap;
import java.io.IOException;

public class WaypointsLoader {
  private static final int NUM_GRIDS_ROWS = 6;
  private static final int NUM_GRIDS_COLS = 16;  
  private static final HashMap<Grid, Location> MAP = readWaypoints();
  
  public static HashMap<Grid,Location> readWaypoints(){
    HashMap<Grid,Location> map = new HashMap<>();

    try{
    int gridRow = 0;
    int gridCol = 0;
    
    BufferedReader waypointsReader = new BufferedReader(
        new FileReader("waypoints.txt"));
    String coordinate;
    
      while((coordinate = waypointsReader.readLine()) != null){
        String[] coordinateWaypoint = coordinate.split(",");
        Location waypoint = new Location(
            Double.parseDouble(coordinateWaypoint[0].trim()), 
            Double.parseDouble(coordinateWaypoint[1].trim()));

        map.put(new Grid(gridRow, gridCol), waypoint);
        gridCol++;

        if(gridCol == NUM_GRIDS_COLS){
            gridCol = 0;
            gridRow++;
        }
      }
    }
    catch(IOException error){
        System.out.println(error);
    }

    return map;
  }
}
@@ -27,16 +27,45 @@
 vlets;%0A%0A
+import com.google.gson.Gson;%0A
 import c
@@ -145,19 +145,24 @@
 .io.
-File
+Buffered
 Reader;
+ 
 %0Aimp
@@ -173,32 +173,27 @@
 java.io.
-Buffered
+File
 Reader;
- 
 %0Aimport 
@@ -239,16 +239,261 @@
 eption;%0A
+import javax.servlet.annotation.WebServlet;%0Aimport javax.servlet.http.HttpServlet;%0Aimport javax.servlet.http.HttpServletRequest;%0Aimport javax.servlet.http.HttpServletResponse;%0A%0A/** Handles fetching and saving grids data. */%0A@WebServlet(%22/grids%22)
 %0Apublic 
@@ -514,16 +514,36 @@
 sLoader 
+extends HttpServlet 
 %7B%0A  priv
@@ -660,54 +660,329 @@
 nal 
-HashMap%3CGrid, Location%3E MAP = readWaypoints();
+Gson gson = new Gson();%0A%0A  @Override%0A  public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException%7B%0A    HashMap%3CGrid, Location%3E MAP = readWaypoints(request);%0A    String json = gson.toJson(MAP);%0A    response.setContentType(%22application/json%22);%0A    response.getWriter().println(json);%0A  %7D
 %0A  %0A
@@ -1034,16 +1034,42 @@
 ypoints(
+HttpServletRequest request
 )%7B%0A    H
@@ -1251,16 +1251,88 @@
 Reader(%22
+/home/dpvalles/step148-2020/portfolio/src/main/java/com/google/sps/data/
 waypoint

Add servlet to get the waypoints