List of usage examples for com.google.gson JsonObject getAsJsonArray
public JsonArray getAsJsonArray(String memberName)
From source file:com.simiacryptus.mindseye.layers.java.ImgBandSelectLayer.java
License:Apache License
/** * Instantiates a new Img band select key. * * @param json the json/*from www . j av a2s. c o m*/ */ protected ImgBandSelectLayer(@Nonnull final JsonObject json) { super(json); final JsonArray jsonArray = json.getAsJsonArray("bands"); bands = new int[jsonArray.size()]; for (int i = 0; i < bands.length; i++) { bands[i] = jsonArray.get(i).getAsInt(); } }
From source file:com.simiacryptus.mindseye.layers.java.MaxDropoutNoiseLayer.java
License:Apache License
/** * Instantiates a new Max dropout noise key. * * @param json the json/*from www . j av a2 s . c o m*/ */ protected MaxDropoutNoiseLayer(@Nonnull final JsonObject json) { super(json); kernelSize = JsonUtil.getIntArray(json.getAsJsonArray("kernelSize")); }
From source file:com.simiacryptus.mindseye.layers.java.MaxImageBandLayer.java
License:Apache License
/** * From json max png band key./* w ww .j a v a 2s . com*/ * * @param json the json * @param rs the rs * @return the max png band key */ public static MaxImageBandLayer fromJson(@Nonnull final JsonObject json, Map<CharSequence, byte[]> rs) { return new MaxImageBandLayer(json, JsonUtil.getIntArray(json.getAsJsonArray("heapCopy"))); }
From source file:com.simiacryptus.mindseye.layers.java.MaxPoolingLayer.java
License:Apache License
/** * From json max subsample key.//from ww w . j ava 2 s .c o m * * @param json the json * @param rs the rs * @return the max subsample key */ public static MaxPoolingLayer fromJson(@Nonnull final JsonObject json, Map<CharSequence, byte[]> rs) { return new MaxPoolingLayer(json, JsonUtil.getIntArray(json.getAsJsonArray("heapCopy"))); }
From source file:com.simiacryptus.mindseye.layers.java.ReshapeLayer.java
License:Apache License
/** * Instantiates a new Img eval key.//from w w w . ja v a2 s . c o m * * @param json the json * @param rs the rs */ protected ReshapeLayer(@Nonnull final JsonObject json, Map<CharSequence, byte[]> rs) { super(json); outputDims = JsonUtil.getIntArray(json.getAsJsonArray("outputDims")); }
From source file:com.simiacryptus.mindseye.layers.java.ValueLayer.java
License:Apache License
/** * Instantiates a new Const nn key.//w ww.j a v a 2s. c o m * * @param json the json * @param resources the resources */ protected ValueLayer(@Nonnull final JsonObject json, Map<CharSequence, byte[]> resources) { super(json); JsonArray values = json.getAsJsonArray("values"); data = IntStream.range(0, values.size()).mapToObj(i -> Tensor.fromJson(values.get(i), resources)) .toArray(i -> new Tensor[i]); }
From source file:com.simiacryptus.mindseye.network.DAGNetwork.java
License:Apache License
/** * Instantiates a new Dag network./*from w w w. ja v a 2 s.c o m*/ * * @param json the json * @param rs the rs */ protected DAGNetwork(@Nonnull final JsonObject json, Map<CharSequence, byte[]> rs) { super(json); for (@Nonnull final JsonElement item : json.getAsJsonArray("inputs")) { @Nonnull final UUID key = UUID.fromString(item.getAsString()); inputHandles.add(key); InputNode replaced = inputNodes.put(key, new InputNode(this, key)); if (null != replaced) replaced.freeRef(); } final JsonObject jsonNodes = json.getAsJsonObject("nodes"); final JsonObject jsonLayers = json.getAsJsonObject("layers"); final JsonObject jsonLinks = json.getAsJsonObject("links"); final JsonObject jsonLabels = json.getAsJsonObject("labels"); @Nonnull final Map<UUID, Layer> source_layersByNodeId = new HashMap<>(); @Nonnull final Map<UUID, Layer> source_layersByLayerId = new HashMap<>(); for (@Nonnull final Entry<String, JsonElement> e : jsonLayers.entrySet()) { @Nonnull Layer value = Layer.fromJson(e.getValue().getAsJsonObject(), rs); source_layersByLayerId.put(UUID.fromString(e.getKey()), value); } for (@Nonnull final Entry<String, JsonElement> e : jsonNodes.entrySet()) { @Nonnull final UUID nodeId = UUID.fromString(e.getKey()); @Nonnull final UUID layerId = UUID.fromString(e.getValue().getAsString()); final Layer layer = source_layersByLayerId.get(layerId); assert null != layer; source_layersByNodeId.put(nodeId, layer); } @Nonnull final LinkedHashMap<CharSequence, UUID> labels = new LinkedHashMap<>(); for (@Nonnull final Entry<String, JsonElement> e : jsonLabels.entrySet()) { labels.put(e.getKey(), UUID.fromString(e.getValue().getAsString())); } @Nonnull final Map<UUID, List<UUID>> deserializedLinks = new HashMap<>(); for (@Nonnull final Entry<String, JsonElement> e : jsonLinks.entrySet()) { @Nonnull final ArrayList<UUID> linkList = new ArrayList<>(); for (@Nonnull final JsonElement linkItem : e.getValue().getAsJsonArray()) { linkList.add(UUID.fromString(linkItem.getAsString())); } deserializedLinks.put(UUID.fromString(e.getKey()), linkList); } for (final UUID key : labels.values()) { initLinks(deserializedLinks, source_layersByNodeId, key); } for (final UUID key : source_layersByNodeId.keySet()) { initLinks(deserializedLinks, source_layersByNodeId, key); } @Nonnull final UUID head = UUID.fromString(json.getAsJsonPrimitive("head").getAsString()); initLinks(deserializedLinks, source_layersByNodeId, head); source_layersByLayerId.values().forEach(x -> x.freeRef()); this.labels.putAll(labels); assertConsistent(); }
From source file:com.simiacryptus.mindseye.network.util.PolynomialNetwork.java
License:Apache License
/** * Instantiates a new Polynomial network. * * @param json the json/*from w ww . j a va 2 s .c o m*/ * @param rs the rs */ protected PolynomialNetwork(@Nonnull final JsonObject json, Map<CharSequence, byte[]> rs) { super(json, rs); head = getNodeById(UUID.fromString(json.get("head").getAsString())); Map<UUID, Layer> layersById = getLayersById(); if (json.get("alpha") != null) { alpha = layersById.get(UUID.fromString(json.get("alpha").getAsString())); } if (json.get("alphaBias") != null) { alphaBias = layersById.get(UUID.fromString(json.get("alphaBias").getAsString())); } inputDims = PolynomialNetwork.toIntArray(json.getAsJsonArray("inputDims")); outputDims = PolynomialNetwork.toIntArray(json.getAsJsonArray("outputDims")); json.getAsJsonArray("corrections").forEach(item -> { corrections.add(new Correcton(item.getAsJsonObject())); }); }
From source file:com.sixt.service.framework.jetty.JsonHandler.java
License:Apache License
protected JsonRpcRequest parseRpcRequest(String jsonRequestString) throws IllegalArgumentException { JsonObject jsonRpcRequest = null; try {//ww w . j a va 2 s .co m jsonRpcRequest = new JsonParser().parse(jsonRequestString).getAsJsonObject(); } catch (Exception ex) { throw new IllegalArgumentException(ex.getMessage(), ex); } JsonElement methodElement = jsonRpcRequest.get(METHOD_FIELD); if (methodElement == null || methodElement.getAsString().isEmpty()) { throw new IllegalArgumentException("Missing method name"); } if (!handlers.hasMethodHandler(methodElement.getAsString())) { throw new IllegalArgumentException( "No handler registered for method '" + methodElement.getAsString() + "'"); } JsonArray paramsArray = jsonRpcRequest.getAsJsonArray(PARAMS_FIELD); JsonElement idElement = jsonRpcRequest.get(JsonRpcRequest.ID_FIELD); return new JsonRpcRequest(idElement, methodElement.getAsString(), paramsArray); }
From source file:com.sixt.service.framework.servicetest.helper.DockerPortResolver.java
License:Apache License
protected int parseExposedPort(String dockerJson, int internalPort) { try {/* w ww.j av a 2s . c o m*/ JsonArray jobj = new JsonParser().parse(dockerJson).getAsJsonArray(); JsonObject network = jobj.get(0).getAsJsonObject().get("NetworkSettings").getAsJsonObject(); JsonObject ports = network.getAsJsonObject("Ports"); JsonArray mappings = ports.getAsJsonArray("" + internalPort + "/tcp"); if (mappings != null) { return mappings.get(0).getAsJsonObject().get("HostPort").getAsInt(); } } catch (Exception ex) { logger.warn("Error parsing exposed port", ex); } return -1; }