Example usage for com.google.gson JsonObject getAsJsonPrimitive

List of usage examples for com.google.gson JsonObject getAsJsonPrimitive

Introduction

In this page you can find the example usage for com.google.gson JsonObject getAsJsonPrimitive.

Prototype

public JsonPrimitive getAsJsonPrimitive(String memberName) 

Source Link

Document

Convenience method to get the specified member as a JsonPrimitive element.

Usage

From source file:com.simiacryptus.mindseye.layers.java.ImgTileAssemblyLayer.java

License:Apache License

/**
 * Instantiates a new Img crop key.//from w  w w  . ja  v  a 2s . c o m
 *
 * @param json the json
 */
protected ImgTileAssemblyLayer(@Nonnull final JsonObject json) {
    super(json);
    columns = json.getAsJsonPrimitive("columns").getAsInt();
    rows = json.getAsJsonPrimitive("rows").getAsInt();
    setPaddingX(json.getAsJsonPrimitive("paddingX").getAsInt());
    setPaddingY(json.getAsJsonPrimitive("paddingY").getAsInt());
    setOffsetX(json.getAsJsonPrimitive("offsetX").getAsInt());
    setOffsetY(json.getAsJsonPrimitive("offsetY").getAsInt());
}

From source file:com.simiacryptus.mindseye.layers.java.ImgTileSelectLayer.java

License:Apache License

/**
 * Instantiates a new Img crop key.// w  w  w  .ja  va2  s  .co m
 *
 * @param json the json
 */
protected ImgTileSelectLayer(@Nonnull final JsonObject json) {
    super(json);
    sizeX = json.getAsJsonPrimitive("sizeX").getAsInt();
    sizeY = json.getAsJsonPrimitive("sizeY").getAsInt();
    positionX = json.getAsJsonPrimitive("positionX").getAsInt();
    positionY = json.getAsJsonPrimitive("positionY").getAsInt();
    toroidal = json.getAsJsonPrimitive("toroidal").getAsBoolean();
}

From source file:com.simiacryptus.mindseye.layers.java.ImgTileSubnetLayer.java

License:Apache License

/**
 * Instantiates a new Rescaled subnet key.
 *
 * @param json the json//from  www  .  j a  va  2s .  co  m
 * @param rs   the rs
 */
protected ImgTileSubnetLayer(@Nonnull final JsonObject json, Map<CharSequence, byte[]> rs) {
    super(json, rs);
    height = json.getAsJsonPrimitive("height").getAsInt();
    width = json.getAsJsonPrimitive("width").getAsInt();
    strideX = json.getAsJsonPrimitive("strideX").getAsInt();
    strideY = json.getAsJsonPrimitive("strideY").getAsInt();
    JsonObject subnetwork = json.getAsJsonObject("subnetwork");
}

From source file:com.simiacryptus.mindseye.layers.java.ImgZeroPaddingLayer.java

License:Apache License

/**
 * Instantiates a new Img crop key./*from w ww.j  a v  a2 s . c o m*/
 *
 * @param json the json
 */
protected ImgZeroPaddingLayer(@Nonnull final JsonObject json) {
    super(json);
    sizeX = json.getAsJsonPrimitive("sizeX").getAsInt();
    sizeY = json.getAsJsonPrimitive("sizeY").getAsInt();
}

From source file:com.simiacryptus.mindseye.layers.java.RescaledSubnetLayer.java

License:Apache License

/**
 * Instantiates a new Rescaled subnet key.
 *
 * @param json the json/*from w w  w  . ja va 2  s  .c  o m*/
 * @param rs   the rs
 */
protected RescaledSubnetLayer(@Nonnull final JsonObject json, Map<CharSequence, byte[]> rs) {
    super(json);
    scale = json.getAsJsonPrimitive("scale").getAsInt();
    JsonObject subnetwork = json.getAsJsonObject("subnetwork");
    this.subnetwork = subnetwork == null ? null : Layer.fromJson(subnetwork, rs);
}

From source file:com.simiacryptus.mindseye.layers.java.SignReducerLayer.java

License:Apache License

/**
 * Instantiates a new Sign reducer key.//  w  w  w.  j a v a2 s .c  om
 *
 * @param json the json
 * @param rs   the rs
 */
protected SignReducerLayer(@Nonnull final JsonObject json, Map<CharSequence, byte[]> rs) {
    super(json, rs);
    head = getNodeById(UUID.fromString(json.getAsJsonPrimitive("head").getAsString()));
}

From source file:com.simiacryptus.mindseye.layers.java.StochasticSamplingSubnetLayer.java

License:Apache License

/**
 * Instantiates a new Rescaled subnet key.
 *
 * @param json the json//w w  w  .  j  a v  a  2  s.  co m
 * @param rs   the rs
 */
protected StochasticSamplingSubnetLayer(@Nonnull final JsonObject json, Map<CharSequence, byte[]> rs) {
    super(json);
    samples = json.getAsJsonPrimitive("samples").getAsInt();
    seed = json.getAsJsonPrimitive("seed").getAsInt();
    layerSeed = json.getAsJsonPrimitive("layerSeed").getAsInt();
    JsonObject subnetwork = json.getAsJsonObject("subnetwork");
    this.subnetwork = subnetwork == null ? null : Layer.fromJson(subnetwork, rs);
}

From source file:com.simiacryptus.mindseye.layers.java.TargetValueLayer.java

License:Apache License

/**
 * Instantiates a new Target value key.//from   w w  w .j a v a2  s.c om
 *
 * @param json the json
 * @param rs   the rs
 */
protected TargetValueLayer(@Nonnull final JsonObject json, Map<CharSequence, byte[]> rs) {
    super(json, rs);
    head = getNodeById(UUID.fromString(json.getAsJsonPrimitive("head").getAsString()));
    target = getNodeById(UUID.fromString(json.getAsJsonPrimitive("target").getAsString()));
}

From source file:com.simiacryptus.mindseye.network.DAGNetwork.java

License:Apache License

/**
 * Instantiates a new Dag network./*  w  w  w .  j  a  va 2  s . c om*/
 *
 * @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.smartling.cms.gateway.client.internal.CommandTypeAdapter.java

License:Apache License

@Override
public BaseCommand deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context)
        throws JsonParseException {
    JsonObject jsonObject = json.getAsJsonObject();
    JsonPrimitive prim = jsonObject.getAsJsonPrimitive("cmd");
    String commandName = prim.getAsString();

    if (commandName.equalsIgnoreCase("getResource")) {
        String requestId = jsonObject.getAsJsonPrimitive("rid").getAsString();
        String fileUri = jsonObject.getAsJsonPrimitive("uri").getAsString();
        return new GetResourceCommand(requestId, fileUri);
    }/*  w  w  w.j  a v  a  2s.c o m*/

    if (commandName.equalsIgnoreCase("getHtml")) {
        String requestId = jsonObject.getAsJsonPrimitive("rid").getAsString();
        String fileUri = jsonObject.getAsJsonPrimitive("uri").getAsString();
        return new GetHtmlCommand(requestId, fileUri);
    }

    if (commandName.equalsIgnoreCase("authenticationSuccess")) {
        return new AuthenticationSuccessCommand();
    }

    if (commandName.equalsIgnoreCase("authenticationError")) {
        return new AuthenticationErrorCommand();
    }

    if (commandName.equalsIgnoreCase("disconnect")) {
        JsonPrimitive reason = jsonObject.getAsJsonPrimitive("message");
        String message = reason == null ? null : reason.getAsString();
        return new DisconnectCommand(message);
    }

    throw new JsonParseException("Unknown command " + commandName);
}