@Override public int getAsInteger(String name) { return map.getAsJsonPrimitive(name).getAsInt(); }
private void setInt(Consumer<Integer> setter, JsonObject jsonObject, String name) { JsonPrimitive primitive = jsonObject.getAsJsonPrimitive(name); if (primitive != null && primitive.isNumber()) { setter.accept(primitive.getAsInt()); } }
@Override public EntityData.GlobalStore deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { EntityData.GlobalStore.Builder world = EntityData.GlobalStore.newBuilder(); if (json.isJsonObject()) { JsonObject jsonObject = json.getAsJsonObject(); JsonArray prefabArray = jsonObject.getAsJsonArray("prefab"); if (prefabArray != null) { for (JsonElement prefabElem : prefabArray) { world.addPrefab((EntityData.Prefab) context.deserialize(prefabElem, EntityData.Prefab.class)); } } JsonArray entityArray = jsonObject.getAsJsonArray("entity"); if (entityArray != null) { for (JsonElement entityElem : entityArray) { world.addEntity((EntityData.Entity) context.deserialize(entityElem, EntityData.Entity.class)); } } JsonPrimitive nextId = jsonObject.getAsJsonPrimitive("next_entity_id"); if (nextId != null) { world.setNextEntityId(nextId.getAsInt()); } } return world.build(); } }
public void readScenes(JsonPrimitive defaultScene, Node rootNode) throws IOException { if (scenes == null) { //no scene... lets handle this later... throw new AssetLoadException("Gltf files with no scene is not yet supported"); } for (JsonElement scene : scenes) { Node sceneNode = new Node(); //specs says that only the default scene should be rendered, // if there are several scenes, they are attached to the rootScene, but they are culled sceneNode.setCullHint(Spatial.CullHint.Always); sceneNode.setName(getAsString(scene.getAsJsonObject(), "name")); JsonArray sceneNodes = scene.getAsJsonObject().getAsJsonArray("nodes"); sceneNode = customContentManager.readExtensionAndExtras("scene", scene, sceneNode); rootNode.attachChild(sceneNode); for (JsonElement node : sceneNodes) { readChild(sceneNode, node); } } //Setting the default scene cul hint to inherit. int activeChild = 0; if (defaultScene != null) { activeChild = defaultScene.getAsInt(); } rootNode.getChild(activeChild).setCullHint(Spatial.CullHint.Inherit); }
builder.value(primitive.getAsString()); } else if (primitive.isNumber()) { builder.value(primitive.getAsInt()); } else if (primitive.isBoolean()) { builder.value(primitive.getAsBoolean());
private void extractPrimitive(EntityData.Value.Builder value, JsonElement element) { JsonPrimitive primitive = element.getAsJsonPrimitive(); if (primitive.isNumber()) { value.addDouble(primitive.getAsDouble()); value.addFloat(primitive.getAsFloat()); try { value.addInteger(primitive.getAsInt()); value.addLong(primitive.getAsLong()); } catch (NumberFormatException e) { value.addInteger(0); value.addLong(0); } } if (primitive.isBoolean()) { value.addBoolean(primitive.getAsBoolean()); } if (primitive.isString()) { value.addString(primitive.getAsString()); } } }
/** * provides a {@link Category} by the given {@link JsonObject}. * * @param object JSON element * @return Category that is provided in JSON, if the code is not known it will fall back to {@link Category#InternalServerError}. */ private static Category getCategory(JsonObject object) { Category category = Category.InternalServerError; if (object.has(CATEGORY) && object.get(CATEGORY).isJsonPrimitive()) { // category could be an object ... JsonPrimitive primitive = object.getAsJsonPrimitive(CATEGORY); try { category = Category.fromStatus(primitive.getAsInt()); } catch (NumberFormatException nfe) { category = Category.InternalServerError; } } else if (object.has(CODE)) { category = Category.fromStatus(object.get(CODE).getAsInt()); } return category != null ? category : Category.InternalServerError; }
@Override public int nextInt() throws IOException { JsonToken token = peek(); if (token != JsonToken.NUMBER && token != JsonToken.STRING) { throw new IllegalStateException( "Expected " + JsonToken.NUMBER + " but was " + token + locationString()); } int result = ((JsonPrimitive) peekStack()).getAsInt(); popStack(); if (stackSize > 0) { pathIndices[stackSize - 1]++; } return result; }
/** * Instantiates a new Rescaled subnet layer. * * @param json the json * @param rs the rs */ protected SubnetLeg(@Nonnull final JsonObject json, Map<CharSequence, byte[]> rs) { fromBand = json.getAsJsonPrimitive("fromBand").getAsInt(); toBand = json.getAsJsonPrimitive("toBand").getAsInt(); inner = Layer.fromJson(json.getAsJsonObject("network"), rs); }
/** * Instantiates a new Rescaled subnet key. * * @param json the json * @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); }
/** * Instantiates a new Hyperbolic activation key. * * @param json the json * @param resources the resources */ protected HyperbolicActivationLayer(@Nonnull final JsonObject json, Map<CharSequence, byte[]> resources) { super(json); weights = Tensor.fromJson(json.get("weights"), resources); negativeMode = json.getAsJsonPrimitive("negativeMode").getAsInt(); }
@Override public WindDirection deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { int degree = json.getAsJsonPrimitive().getAsInt(); WindDirection windDirection = new WindDirection(); windDirection.setDegree(degree); return windDirection; } }
/** * Instantiates a new Img reshapeCast key. * * @param json the json */ protected ImgReshapeLayer(@Nonnull final JsonObject json) { super(json); kernelSizeX = json.getAsJsonPrimitive("kernelSizeX").getAsInt(); kernelSizeY = json.getAsJsonPrimitive("kernelSizeY").getAsInt(); expand = json.getAsJsonPrimitive("expandPlasma").getAsBoolean(); }
/** * Instantiates a new Img reshapeCast layer. * * @param json the json */ protected ImgReshapeLayer(@Nonnull final JsonObject json) { super(json); kernelSizeX = json.getAsJsonPrimitive("kernelSizeX").getAsInt(); kernelSizeY = json.getAsJsonPrimitive("kernelSizeY").getAsInt(); expand = json.getAsJsonPrimitive("expandPlasma").getAsBoolean(); }
@Override public int nextInt() throws IOException { JsonToken token = peek(); if (token != JsonToken.NUMBER && token != JsonToken.STRING) { throw new IllegalStateException("Expected " + JsonToken.NUMBER + " but was " + token); } int result = ((JsonPrimitive) peekStack()).getAsInt(); popStack(); return result; }
/** * Instantiates a new Activation key. * * @param json the json */ protected ActivationLayer(@Nonnull final JsonObject json) { super(json); mode = json.getAsJsonPrimitive("mode").getAsInt(); setAlpha(json.getAsJsonPrimitive("alpha").getAsDouble()); precision = Precision.valueOf(json.get("precision").getAsString()); }
private void assertTargetVersion(JsonObject jsonObject, int expectedVersion) { assertThat(jsonObject.get("target_version") instanceof JsonPrimitive, is(true)); assertThat(jsonObject.getAsJsonPrimitive("target_version").getAsInt(), is(expectedVersion)); } }