List of usage examples for com.google.gson JsonObject getAsJsonArray
public JsonArray getAsJsonArray(String memberName)
From source file:com.shared.rides.service.SignupUserService.java
private void saveTrack(JsonObject jsonDay, Driver driver, int day, String personalId, String tagName, String inout) {/*www . ja v a2 s . c o m*/ JsonArray trackArray = jsonDay.getAsJsonArray(tagName); Double[][] markers = new Double[trackArray.size()][2]; JsonElement lat; JsonElement lon; for (int j = 0; j < trackArray.size(); j++) { JsonObject trk = (JsonObject) trackArray.get(j); lat = trk.get("lat"); lon = trk.get("lon"); markers[j][0] = lat.getAsDouble(); markers[j][1] = lon.getAsDouble(); } Track track = new Track(); //El nombre del archivo esta formado por el identificador personal del usuario, mas el dia de semana que es y si es in o out String fileName = personalId + "_" + day + "_" + inout; String pathFile = context.getInitParameter("gpx-upload"); CreateGPXFile.createGPX(fileName, markers, pathFile); track.setPathFile(fileName); track.setDay(day + 1); if (inout.equalsIgnoreCase("in")) track.setInout(0); else track.setInout(1); trackDAO.save(track); track = trackDAO.getLastTrack(); driverDAO.newTrack(driver.getDriverId(), track.getTrackId()); }
From source file:com.sheepdog.mashmesh.Itinerary.java
License:Apache License
public static Itinerary fetch(String fromLocation, String toLocation, String viaLocation, DateTime arrivalTime) throws URISyntaxException, IOException { URIBuilder uriBuilder = new URIBuilder(DIRECTIONS_ENDPOINT_URL); uriBuilder.addParameter("origin", fromLocation); uriBuilder.addParameter("destination", toLocation); uriBuilder.addParameter("mode", "driving"); uriBuilder.addParameter("language", "en_US"); // TODO: Configurable? uriBuilder.addParameter("region", "us"); uriBuilder.addParameter("waypoints", viaLocation); uriBuilder.addParameter("sensor", "false"); URL url = uriBuilder.build().toURL(); BufferedReader responseReader = new BufferedReader(new InputStreamReader(url.openStream())); JsonParser parser = new JsonParser(); JsonObject responseObject = parser.parse(responseReader).getAsJsonObject(); JsonObject route = responseObject.getAsJsonArray("routes").get(0).getAsJsonObject(); JsonArray legs = route.getAsJsonArray("legs"); JsonObject startLeg = legs.get(0).getAsJsonObject(); JsonObject endLeg = legs.get(legs.size() - 1).getAsJsonObject(); DateTime departureTime = arrivalTime; List<Leg> directionLegs = new ArrayList<Leg>(); Preconditions.checkState(legs.size() == 2, "Expected two direction legs in response"); // Process the legs in reverse order so that we can compute departure and arrival // times by working backwards from the desired arrival time. for (int i = legs.size() - 1; i >= 0; i--) { JsonObject leg = legs.get(i).getAsJsonObject(); List<Step> directionSteps = new ArrayList<Step>(); DateTime legArrivalTime = departureTime; for (JsonElement stepElement : leg.getAsJsonArray("steps")) { JsonObject stepObject = stepElement.getAsJsonObject(); int duration = stepObject.getAsJsonObject("duration").get("value").getAsInt(); String htmlInstructions = stepObject.get("html_instructions").getAsString(); String distance = stepObject.getAsJsonObject("distance").get("text").getAsString(); departureTime = departureTime.minusSeconds(duration); directionSteps.add(new Step(htmlInstructions, distance)); }//from www .ja va 2s .c o m Leg directionLeg = new Leg(); directionLeg.departureTime = departureTime; directionLeg.startLatLng = getLatLng(leg.getAsJsonObject("start_location")); directionLeg.arrivalTime = legArrivalTime; directionLeg.endLatLng = getLatLng(leg.getAsJsonObject("end_location")); directionLeg.distanceMeters = leg.getAsJsonObject("distance").get("value").getAsInt(); directionLeg.steps = Collections.unmodifiableList(directionSteps); directionLegs.add(directionLeg); } Collections.reverse(directionLegs); Itinerary itinerary = new Itinerary(); itinerary.startAddress = startLeg.get("start_address").getAsString(); itinerary.endAddress = endLeg.get("end_address").getAsString(); itinerary.legs = Collections.unmodifiableList(directionLegs); itinerary.overviewPolyline = route.getAsJsonObject("overview_polyline").get("points").getAsString(); return itinerary; }
From source file:com.simiacryptus.mindseye.lang.Tensor.java
License:Apache License
/** * From json tensor./* w w w . ja v a2 s. c o m*/ * * @param json the json * @param resources the resources * @return the tensor */ @Nullable public static Tensor fromJson(@Nullable final JsonElement json, @Nullable Map<CharSequence, byte[]> resources) { if (null == json) return null; if (json.isJsonArray()) { final JsonArray array = json.getAsJsonArray(); final int size = array.size(); if (array.get(0).isJsonPrimitive()) { final double[] doubles = IntStream.range(0, size).mapToObj(i -> { return array.get(i); }).mapToDouble(element -> { return element.getAsDouble(); }).toArray(); @Nonnull Tensor tensor = new Tensor(doubles); assert tensor.isValid(); return tensor; } else { final List<Tensor> elements = IntStream.range(0, size).mapToObj(i -> { return array.get(i); }).map(element -> { return Tensor.fromJson(element, resources); }).collect(Collectors.toList()); @Nonnull final int[] dimensions = elements.get(0).getDimensions(); if (!elements.stream().allMatch(t -> Arrays.equals(dimensions, t.getDimensions()))) { throw new IllegalArgumentException(); } @Nonnull final int[] newDdimensions = Arrays.copyOf(dimensions, dimensions.length + 1); newDdimensions[dimensions.length] = size; @Nonnull final Tensor tensor = new Tensor(newDdimensions); @Nullable final double[] data = tensor.getData(); for (int i = 0; i < size; i++) { @Nullable final double[] e = elements.get(i).getData(); System.arraycopy(e, 0, data, i * e.length, e.length); } for (@Nonnull Tensor t : elements) { t.freeRef(); } assert tensor.isValid(); return tensor; } } else if (json.isJsonObject()) { JsonObject jsonObject = json.getAsJsonObject(); @Nonnull int[] dims = fromJsonArray(jsonObject.getAsJsonArray("length")); @Nonnull Tensor tensor = new Tensor(dims); SerialPrecision precision = SerialPrecision .valueOf(jsonObject.getAsJsonPrimitive("precision").getAsString()); JsonElement base64 = jsonObject.get("base64"); if (null == base64) { if (null == resources) throw new IllegalArgumentException("No Data Resources"); CharSequence resourceId = jsonObject.getAsJsonPrimitive("resource").getAsString(); tensor.setBytes(resources.get(resourceId), precision); } else { tensor.setBytes(Base64.getDecoder().decode(base64.getAsString()), precision); } assert tensor.isValid(); JsonElement id = jsonObject.get("id"); if (null != id) { tensor.setId(UUID.fromString(id.getAsString())); } return tensor; } else { @Nonnull Tensor tensor = new Tensor(json.getAsJsonPrimitive().getAsDouble()); assert tensor.isValid(); return tensor; } }
From source file:com.simiacryptus.mindseye.layers.cudnn.conv.FullyConnectedLayer.java
License:Apache License
/** * Instantiates a new Img eval key.// w w w .j av a2 s . co m * * @param json the json * @param rs the rs */ protected FullyConnectedLayer(@Nonnull final JsonObject json, Map<CharSequence, byte[]> rs) { super(json); outputDims = JsonUtil.getIntArray(json.getAsJsonArray("outputDims")); inputDims = JsonUtil.getIntArray(json.getAsJsonArray("inputDims")); @Nullable final Tensor data = Tensor.fromJson(json.get("weights"), rs); weights = data; this.precision = Precision.valueOf(json.getAsJsonPrimitive("precision").getAsString()); }
From source file:com.simiacryptus.mindseye.layers.java.AvgPoolingLayer.java
License:Apache License
/** * From json avg subsample key.//from w ww . j a v a2s .c om * * @param json the json * @param rs the rs * @return the avg subsample key */ public static AvgPoolingLayer fromJson(@Nonnull final JsonObject json, Map<CharSequence, byte[]> rs) { return new AvgPoolingLayer(json, JsonUtil.getIntArray(json.getAsJsonArray("heapCopy"))); }
From source file:com.simiacryptus.mindseye.layers.java.BiasLayer.java
License:Apache License
/** * Instantiates a new Bias key.// www . java 2s . c o m * * @param json the json */ protected BiasLayer(@Nonnull final JsonObject json) { super(json); bias = JsonUtil.getDoubleArray(json.getAsJsonArray("bias")); }
From source file:com.simiacryptus.mindseye.layers.java.FullyConnectedLayer.java
License:Apache License
/** * Instantiates a new Fully connected key. * * @param json the json/*w w w. j a va 2s .c o m*/ * @param resources the resources */ protected FullyConnectedLayer(@Nonnull final JsonObject json, Map<CharSequence, byte[]> resources) { super(json); outputDims = JsonUtil.getIntArray(json.getAsJsonArray("outputDims")); inputDims = JsonUtil.getIntArray(json.getAsJsonArray("inputDims")); weights = Tensor.fromJson(json.get("weights"), resources); }
From source file:com.simiacryptus.mindseye.layers.java.FullyConnectedReferenceLayer.java
License:Apache License
/** * Instantiates a new Fully connected key. * * @param json the json// www . jav a 2s. c om * @param resources the resources */ protected FullyConnectedReferenceLayer(@Nonnull final JsonObject json, Map<CharSequence, byte[]> resources) { super(json); outputDims = JsonUtil.getIntArray(json.getAsJsonArray("outputDims")); inputDims = JsonUtil.getIntArray(json.getAsJsonArray("inputDims")); weights = Tensor.fromJson(json.get("weights"), resources); }
From source file:com.simiacryptus.mindseye.layers.java.ImgBandBiasLayer.java
License:Apache License
/** * Instantiates a new Img band bias key. * * @param json the json// w w w. jav a2 s. c om */ protected ImgBandBiasLayer(@Nonnull final JsonObject json) { super(json); bias = JsonUtil.getDoubleArray(json.getAsJsonArray("bias")); }
From source file:com.simiacryptus.mindseye.layers.java.ImgBandScaleLayer.java
License:Apache License
/** * Instantiates a new Img band scale key. * * @param json the json/*w ww . j ava 2 s . c om*/ */ protected ImgBandScaleLayer(@Nonnull final JsonObject json) { super(json); weights = JsonUtil.getDoubleArray(json.getAsJsonArray("bias")); }