public Polygon[] parse() throws ParseException { // parse entire object parseObject(""); // make sure there's nothing left: readEnd(); // The order of JSON object keys (type, geometry, coordinates in our case) can be arbitrary, so we wait until we are done parsing to // put the pieces together here: if (coordinates == null) { throw newParseException("did not see any polygon coordinates"); } if (polyType == null) { throw newParseException("did not see type: Polygon or MultiPolygon"); } if (polyType.equals("Polygon")) { return new Polygon[] {parsePolygon(coordinates)}; } else { List<Polygon> polygons = new ArrayList<>(); for(int i=0;i<coordinates.size();i++) { Object o = coordinates.get(i); if (o instanceof List == false) { throw newParseException("elements of coordinates array should be an array, but got: " + o.getClass()); } polygons.add(parsePolygon((List<Object>) o)); } return polygons.toArray(new Polygon[polygons.size()]); } }
public Polygon[] parse() throws ParseException { // parse entire object parseObject(""); // make sure there's nothing left: readEnd(); // The order of JSON object keys (type, geometry, coordinates in our case) can be arbitrary, so we wait until we are done parsing to // put the pieces together here: if (coordinates == null) { throw newParseException("did not see any polygon coordinates"); } if (polyType == null) { throw newParseException("did not see type: Polygon or MultiPolygon"); } if (polyType.equals("Polygon")) { return new Polygon[] {parsePolygon(coordinates)}; } else { List<Polygon> polygons = new ArrayList<>(); for(int i=0;i<coordinates.size();i++) { Object o = coordinates.get(i); if (o instanceof List == false) { throw newParseException("elements of coordinates array should be an array, but got: " + o.getClass()); } polygons.add(parsePolygon((List<Object>) o)); } return polygons.toArray(new Polygon[polygons.size()]); } }