diff --git a/src/main/java/com/example/cosmos_serversb/entities/Shop.java b/src/main/java/com/example/cosmos_serversb/entities/Shop.java index f019eb2..dd45901 100644 --- a/src/main/java/com/example/cosmos_serversb/entities/Shop.java +++ b/src/main/java/com/example/cosmos_serversb/entities/Shop.java @@ -16,7 +16,6 @@ * @param genre string * @param code int * @param location Location - * @param shop String * */ @JsonInclude(JsonInclude.Include.NON_NULL) diff --git a/src/main/java/com/example/cosmos_serversb/models/Shops.java b/src/main/java/com/example/cosmos_serversb/models/Shops.java index e6410b7..8a2c12e 100644 --- a/src/main/java/com/example/cosmos_serversb/models/Shops.java +++ b/src/main/java/com/example/cosmos_serversb/models/Shops.java @@ -13,12 +13,14 @@ import java.io.*; import java.net.HttpURLConnection; import java.net.URL; +import java.util.ArrayList; @Singleton public class Shops { private static Shops theInstance = null; private static SessionFactory sessionFactory; + private static ArrayList shops = new ArrayList<>(); private static String baseURI="http://nitta-lab-www.is.konan-u.ac.jp/"; private static String AppName="cosmos"; @@ -33,7 +35,7 @@ return theInstance; } - public static Shop getShop(String leftLatitude, String leftLongitude, String rightLatitude, String rightLongitude) { + public static ArrayList getShop(String leftLatitude, String leftLongitude, String rightLatitude, String rightLongitude) { String result = ""; String genre; String code; @@ -62,12 +64,16 @@ }catch(Exception e){ e.printStackTrace(); } + + for (int i = 0; i < 90; i++) { genre = jnode.get("Feature").get(0).get("Property").get("Genre").get(0).get("Name").asText(); code = jnode.get("Feature").get(0).get("Property").get("Genre").get(0).get("Code").asText(); location = jnode.get("Feature").get(0).get("Geometry").get("Coordinates").asText(); split = location.split(","); - Shop shop = new Shop(genre, Integer.parseInt(code), Double.parseDouble(split[0]), Double.parseDouble(split[1])); + Shop shop = new Shop(genre, Integer.parseInt(code), Double.parseDouble(split[0]), Double.parseDouble(split[1])); + shops.add(shop); + } - return shop; + return shops; } } \ No newline at end of file diff --git a/src/test/java/HttpUrlConnectionTest/SampleTest.java b/src/test/java/HttpUrlConnectionTest/SampleTest.java index d185525..e8857f6 100644 --- a/src/test/java/HttpUrlConnectionTest/SampleTest.java +++ b/src/test/java/HttpUrlConnectionTest/SampleTest.java @@ -26,20 +26,20 @@ } in.close(); con.disconnect(); - }catch(Exception e){ + } catch (Exception e) { e.printStackTrace(); } return result; } - public static JsonNode getJsonNode(String jsonString){ + public static JsonNode getJsonNode(String jsonString) { JsonNode head = null; - try{ + try { JsonFactory jfactory = new JsonFactory(); JsonParser parser = jfactory.createJsonParser(jsonString); ObjectMapper mapper = new ObjectMapper(); head = mapper.readTree(parser); - }catch(Exception e){ + } catch (Exception e) { e.printStackTrace(); } return head; @@ -48,19 +48,21 @@ public static void main(String[] args) { String Result; JsonNode json; - String URL = "https://map.yahooapis.jp/search/local/V1/localSearch?bbox=139.727685,35.663782,139.734251,35.669378&gc=02&results=20&output=json&appid=dj00aiZpPTVzYzloUDJjS0VMSyZzPWNvbnN1bWVyc2VjcmV0Jng9MGE-"; + String URL = "https://map.yahooapis.jp/search/local/V1/localSearch?bbox=139.727685,35.663782,139.734251,35.669378&gc=02&results=90&output=json&appid=dj00aiZpPTVzYzloUDJjS0VMSyZzPWNvbnN1bWVyc2VjcmV0Jng9MGE-"; Result = getResult(URL); json = getJsonNode(Result); - String genre = json.get("Feature").get(0).get("Property").get("Genre").get(0).get("Name").asText(); - String code = json.get("Feature").get(0).get("Property").get("Genre").get(0).get("Code").asText(); - String location = json.get("Feature").get(0).get("Geometry").get("Coordinates").asText(); + for (int i = 0; i < 90; i++) { + String genre = json.get("Feature").get(i).get("Property").get("Genre").get(0).get("Name").asText(); + String code = json.get("Feature").get(i).get("Property").get("Genre").get(0).get("Code").asText(); + String location = json.get("Feature").get(i).get("Geometry").get("Coordinates").asText(); - String[] split = location.split(","); - System.out.println(genre); - System.out.println(Integer.parseInt(code)); - System.out.println(split[0]); - System.out.println(split[1]); - System.out.println(json); + String[] split = location.split(","); + System.out.println(genre); + System.out.println(Integer.parseInt(code)); + System.out.println(split[0]); + System.out.println(split[1]); + } + System.out.println(json); } -} +} \ No newline at end of file