com.google.gson.JsonElement.getAsFloat()方法的使用及代码示例

x33g5p2x  于2022-01-21 转载在 其他  
字(8.4k)|赞(0)|评价(0)|浏览(173)

本文整理了Java中com.google.gson.JsonElement.getAsFloat()方法的一些代码示例,展示了JsonElement.getAsFloat()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。JsonElement.getAsFloat()方法的具体详情如下:
包路径:com.google.gson.JsonElement
类名称:JsonElement
方法名:getAsFloat

JsonElement.getAsFloat介绍

[英]convenience method to get this element as a primitive float value.
[中]将此元素作为基本浮点值获取的简便方法。

代码示例

代码示例来源:origin: apache/incubator-gobblin

@Override
Object convertField(JsonElement value) {
 return value.getAsFloat();
}

代码示例来源:origin: jMonkeyEngine/jmonkeyengine

public static Float getAsFloat(JsonObject parent, String name, float defaultValue) {
  JsonElement el = parent.get(name);
  return el == null ? defaultValue : el.getAsFloat();
}

代码示例来源:origin: jMonkeyEngine/jmonkeyengine

public static Float getAsFloat(JsonObject parent, String name) {
  JsonElement el = parent.get(name);
  return el == null ? null : el.getAsFloat();
}

代码示例来源:origin: jMonkeyEngine/jmonkeyengine

public static ColorRGBA getAsColor(JsonObject parent, String name) {
  JsonElement el = parent.get(name);
  if (el == null) {
    return null;
  }
  JsonArray color = el.getAsJsonArray();
  return new ColorRGBA(color.get(0).getAsFloat(), color.get(1).getAsFloat(), color.get(2).getAsFloat(), color.size() > 3 ? color.get(3).getAsFloat() : 1f);
}

代码示例来源:origin: MovingBlocks/Terasology

@Override
  public Quat4f deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
    if (json.isJsonArray()) {
      JsonArray array = json.getAsJsonArray();
      if (array.size() == 4) {
        return new Quat4f(array.get(0).getAsFloat(), array.get(1).getAsFloat(), array.get(2).getAsFloat(), array.get(3).getAsFloat());
      }
    }
    return null;
  }
}

代码示例来源:origin: MovingBlocks/Terasology

@Override
  public Vector3f deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
    JsonArray jsonArray = json.getAsJsonArray();
    return new Vector3f(jsonArray.get(0).getAsFloat(), jsonArray.get(1).getAsFloat(), jsonArray.get(2).getAsFloat());
  }
}

代码示例来源:origin: MovingBlocks/Terasology

@Override
  public Vector4f deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
    if (json.isJsonArray()) {
      JsonArray array = json.getAsJsonArray();
      if (array.size() == 4) {
        return new Vector4f(array.get(0).getAsFloat(), array.get(1).getAsFloat(), array.get(2).getAsFloat(), array.get(3).getAsFloat());
      } else if (array.size() == 3) {
        return new Vector4f(array.get(0).getAsFloat(), array.get(1).getAsFloat(), array.get(2).getAsFloat(), 1);
      }
    }
    return null;
  }
}

代码示例来源:origin: MovingBlocks/Terasology

@Override
  public Vector2f deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
    JsonArray jsonArray = json.getAsJsonArray();
    return new Vector2f(jsonArray.get(0).getAsFloat(), jsonArray.get(1).getAsFloat());
  }
}

代码示例来源:origin: MovingBlocks/Terasology

private void bindAxisEvent(BindAxisEvent event, JsonObject jsonObject) {
  String id = jsonObject.get("id").getAsString();
  float value = jsonObject.get("value").getAsFloat();
  float delta = jsonObject.get("delta").getAsFloat();
  event.prepare(id, value, delta);
}

代码示例来源:origin: MovingBlocks/Terasology

private void inputEventSetup(InputEvent event, JsonObject jsonObject) {
    float delta = jsonObject.get("delta").getAsFloat();
    boolean consumed = jsonObject.get("consumed").getAsBoolean();
    EntityRef target =  new RecordedEntityRef(jsonObject.get("target").getAsLong(), (LowLevelEntityManager) this.entityManager);
    JsonObject aux = jsonObject.get("hitNormal").getAsJsonObject();
    Vector3f hitNormal = new Vector3f(aux.get("x").getAsFloat(), aux.get("y").getAsFloat(), aux.get("z").getAsFloat());
    aux = jsonObject.get("hitPosition").getAsJsonObject();
    Vector3f hitPosition = new Vector3f(aux.get("x").getAsFloat(), aux.get("y").getAsFloat(), aux.get("z").getAsFloat());
    aux = jsonObject.get("targetBlockPosition").getAsJsonObject();
    Vector3i targetBlockPosition = new Vector3i(aux.get("x").getAsInt(), aux.get("y").getAsInt(), aux.get("z").getAsInt());
    event.setTargetInfo(target, targetBlockPosition, hitPosition, hitNormal);
  }
}

代码示例来源:origin: MovingBlocks/Terasology

@Override
public final float getAsFloat() {
  return getElement().getAsFloat();
}

代码示例来源:origin: apache/incubator-gobblin

@Override
 FloatValue convertField(JsonElement value) {
  return new FloatValue(value.getAsFloat());
 }
}

代码示例来源:origin: searchbox-io/Jest

public Float getMaxScore() {
  Float maxScore = null;
  JsonElement obj = getPath(PATH_TO_MAX_SCORE);
  if (obj != null && !obj.isJsonNull()) maxScore = obj.getAsFloat();
  return maxScore;
}

代码示例来源:origin: chanjarster/weixin-java-tools

public static Float getAsFloat(JsonElement element) {
  return isNull(element) ? null : element.getAsFloat();
}

代码示例来源:origin: MovingBlocks/Terasology

private ColliderInfo processSphereShape(JsonDeserializationContext context, JsonObject colliderDef) {
  Vector3f offset = context.deserialize(colliderDef.get(POSITION), Vector3f.class);
  float radius = colliderDef.get(RADIUS).getAsFloat();
  if (offset == null) {
    throw new JsonParseException("Sphere Collider missing position");
  }
  return new ColliderInfo(offset, COLLISION_SHAPE_FACTORY.getNewSphere(radius));
}

代码示例来源:origin: jMonkeyEngine/jmonkeyengine

tmpArray[i] = matrix.get(i).getAsFloat();
if (translation != null) {
  transform.setTranslation(
      translation.get(0).getAsFloat(),
      translation.get(1).getAsFloat(),
      translation.get(2).getAsFloat());
      rotation.get(0).getAsFloat(),
      rotation.get(1).getAsFloat(),
      rotation.get(2).getAsFloat(),
      rotation.get(3).getAsFloat()));
      scale.get(0).getAsFloat(),
      scale.get(1).getAsFloat(),
      scale.get(2).getAsFloat());

代码示例来源:origin: MovingBlocks/Terasology

private void writeRealVector3fData(JsonWriter writer, GsonSerializationContext serializationContext, InputEvent e) throws IOException {
  TypeHandler handler = typeSerializationLibrary.getTypeHandlerFromClass(Vector3f.class);
  GsonPersistedData data = (GsonPersistedData) handler.serialize(e.getHitNormal(), serializationContext);
  writer.name("hitNormal");
  writer.beginObject();
  JsonArray array = data.getElement().getAsJsonArray();
  writer.name("x").value(array.get(0).getAsFloat());
  writer.name("y").value(array.get(1).getAsFloat());
  writer.name("z").value(array.get(2).getAsFloat());
  writer.endObject();
  data = (GsonPersistedData) handler.serialize(e.getHitPosition(), serializationContext);
  writer.name("hitPosition");
  writer.beginObject();
  array = data.getElement().getAsJsonArray();
  writer.name("x").value(array.get(0).getAsFloat());
  writer.name("y").value(array.get(1).getAsFloat());
  writer.name("z").value(array.get(2).getAsFloat());
  writer.endObject();
  handler = typeSerializationLibrary.getTypeHandlerFromClass(Vector3i.class);
  data = (GsonPersistedData) handler.serialize(e.getTargetBlockPosition(), serializationContext);
  writer.name("targetBlockPosition");
  writer.beginObject();
  array = data.getElement().getAsJsonArray();
  writer.name("x").value(array.get(0).getAsInt());
  writer.name("y").value(array.get(1).getAsInt());
  writer.name("z").value(array.get(2).getAsInt());
  writer.endObject();
}

代码示例来源:origin: MovingBlocks/Terasology

metadata.floatParams.put(prop.getKey(), prop.getValue().getAsFloat());
} else if (prop.getValue().getAsJsonPrimitive().isBoolean()) {
  metadata.intParams.put(prop.getKey(), (prop.getValue().getAsBoolean()) ? 1 : 0);
    break;
  result[i] = array.get(i).getAsFloat();

代码示例来源:origin: MovingBlocks/Terasology

@Override
public TFloatList getAsFloatArray() {
  TFloatList result = new TFloatArrayList(size());
  for (JsonElement element : array) {
    result.add(element.getAsFloat());
  }
  return result;
}

代码示例来源:origin: MovingBlocks/Terasology

private void bindButtonEventSetup(BindButtonEvent event, JsonObject jsonObject, GsonDeserializationContext deserializationContext) {
  GsonPersistedData data = new GsonPersistedData(jsonObject.get("state"));
  TypeHandler typeHandler = typeSerializationLibrary.getTypeHandlerFromClass(ButtonState.class);
  ButtonState state = (ButtonState) typeHandler.deserialize(data, deserializationContext);
  float delta = jsonObject.get("delta").getAsFloat();
  typeHandler = typeSerializationLibrary.getTypeHandlerFromClass(Name.class);
  JsonObject aux = jsonObject.get("id").getAsJsonObject();
  data = new GsonPersistedData(aux.get("moduleName"));
  Name moduleName = (Name) typeHandler.deserialize(data, deserializationContext);
  data = new GsonPersistedData(aux.get("objectName"));
  Name objectName = (Name) typeHandler.deserialize(data, deserializationContext);
  SimpleUri id = new SimpleUri(moduleName, objectName);
  event.prepare(id, state, delta);
}

相关文章