public static T getTyped()

in sdk-java/src/main/java/com/spotify/confidence/ConfidenceTypeMapper.java [106:160]


  public static <T> T getTyped(ConfidenceValue value, T defaultValue)
      throws IllegalValueType, IncompatibleValueType {
    if (value.equals(ConfidenceValue.NULL_VALUE)) {
      return defaultValue;
    }

    if (defaultValue instanceof String) {
      if (value.isString()) {
        return (T) value.asString();
      }
      throw new IncompatibleValueType(
          String.format(
              "Default type %s, but value of type %s", defaultValue.getClass(), value.getClass()));
    } else if (defaultValue instanceof Integer) {
      if (value.isInteger()) {
        return (T) java.lang.Integer.valueOf(value.asInteger());
      }
      throw new IncompatibleValueType(
          String.format(
              "Default type %s, but value of type %s", defaultValue.getClass(), value.getClass()));
    } else if (defaultValue instanceof Double) {
      if (value.isDouble()) {
        return (T) Double.valueOf(value.asDouble());
      }
      throw new IncompatibleValueType(
          String.format(
              "Default type %s, but value of type %s", defaultValue.getClass(), value.getClass()));
    } else if (defaultValue instanceof Boolean) {
      if (value.isBoolean()) {
        return (T) Boolean.valueOf(value.asBoolean());
      }
      throw new IncompatibleValueType(
          String.format(
              "Default type %s, but value of type %s", defaultValue.getClass(), value.getClass()));
    } else if (defaultValue instanceof ConfidenceValue.List) {
      if (value.isList()) {
        return (T) value.asList();
      }
      throw new IncompatibleValueType(
          String.format(
              "Default value type %s, but value of type %s",
              defaultValue.getClass(), value.getClass()));
    } else if (defaultValue instanceof ConfidenceValue.Struct) {
      if (value.isStruct()) {
        return (T) value.asStruct();
      }
      throw new IncompatibleValueType(
          String.format(
              "Default value type %s, but value of type %s",
              defaultValue.getClass(), value.getClass()));
    } else {
      // Unsupported default value type
      throw new IllegalValueType(String.format("Illegal value type: %s", defaultValue.getClass()));
    }
  }