org.eclipse.ditto.json.JsonObject.stream()方法的使用及代码示例

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

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

JsonObject.stream介绍

暂无

代码示例

代码示例来源:origin: org.eclipse.ditto/ditto-model-things

@Override
public Stream<JsonField> stream() {
  return wrapped.stream();
}

代码示例来源:origin: eclipse/ditto

@Override
public Stream<JsonField> stream() {
  return wrapped.stream();
}

代码示例来源:origin: org.eclipse.ditto/ditto-model-things

@Override
public Stream<JsonField> stream() {
  return wrapped.stream();
}

代码示例来源:origin: eclipse/ditto

@Override
public Stream<JsonField> stream() {
  return wrapped.stream();
}

代码示例来源:origin: org.eclipse.ditto/ditto-services-utils-jwt

private static Map<String, Object> toJavaMap(final JsonObject jsonObject) {
  return jsonObject.stream()
      .collect(Collectors.toMap(
          JsonField::getKeyName,
          field -> toJavaObject(field.getValue())));
}

代码示例来源:origin: eclipse/ditto

private static Map<String, Object> toJavaMap(final JsonObject jsonObject) {
  return jsonObject.stream()
      .collect(Collectors.toMap(JsonField::getKeyName, field -> toJavaObject(field.getValue())));
}

代码示例来源:origin: org.eclipse.ditto/ditto-services-utils-config

private static Map<String, String> getAliases() {
  final String configAliasesStr = System.getenv(ENV_CONFIG_ALIASES);
  if (configAliasesStr == null || configAliasesStr.isEmpty()) {
    LOGGER.info("Environment variable {} is not defined or empty, using default config aliases: {}",
        ENV_CONFIG_ALIASES, DEFAULT_CONFIG_ALIASES);
    return DEFAULT_CONFIG_ALIASES;
  }
  final Map<String, String> aliases = new HashMap<>();
  final JsonObject configAliasesJsonObj = JsonFactory.newObject(configAliasesStr);
  configAliasesJsonObj.stream().forEach(jsonField -> {
    final String alias = jsonField.getKeyName();
    final String originalPathStr = jsonField.getValue().asString();
    aliases.put(alias, originalPathStr);
  });
  LOGGER.info("Environment variable {} defines these config aliases: {}", ENV_CONFIG_ALIASES, aliases);
  return aliases;
}

代码示例来源:origin: eclipse/ditto

private static Map<String, String> getAliases() {
  final String configAliasesStr = System.getenv(ENV_CONFIG_ALIASES);
  if (configAliasesStr == null || configAliasesStr.isEmpty()) {
    LOGGER.info("Environment variable {} is not defined or empty, using default config aliases: {}",
        ENV_CONFIG_ALIASES, DEFAULT_CONFIG_ALIASES);
    return DEFAULT_CONFIG_ALIASES;
  }
  final Map<String, String> aliases = new HashMap<>();
  final JsonObject configAliasesJsonObj = JsonFactory.newObject(configAliasesStr);
  configAliasesJsonObj.stream().forEach(jsonField -> {
    final String alias = jsonField.getKeyName();
    final String originalPathStr = jsonField.getValue().asString();
    aliases.put(alias, originalPathStr);
  });
  LOGGER.info("Environment variable {} defines these config aliases: {}", ENV_CONFIG_ALIASES, aliases);
  return aliases;
}

代码示例来源:origin: org.eclipse.ditto/ditto-model-connectivity

/**
 * Creates a new {@code HeaderMapping} object from the specified JSON object.
 *
 * @param jsonObject a JSON object which provides the data for the HeaderMapping to be created.
 * @return a new HeaderMapping which is initialised with the extracted data from {@code jsonObject}.
 * @throws NullPointerException if {@code jsonObject} is {@code null}.
 * @throws org.eclipse.ditto.json.JsonParseException if {@code jsonObject} is not an appropriate JSON object.
 */
public static HeaderMapping fromJson(final JsonObject jsonObject) {
  return new ImmutableHeaderMapping(jsonObject.stream()
      .filter(f -> f.getValue().isString())
      .collect(Collectors.toMap(JsonField::getKeyName, jsonField -> jsonField.getValue().asString())));
}

代码示例来源:origin: eclipse/ditto

/**
 * Returns a new immutable Iterable of Policy entries based on the given JSON object.
 *
 * @param jsonObject the JSON object representation of Policy entries.
 * @return the new initialised {@code Iterable} of {@code PolicyEntry}s.
 * @throws NullPointerException if {@code jsonObject} is {@code null}.
 * @throws org.eclipse.ditto.model.base.exceptions.DittoJsonException if {@code jsonObject} cannot be parsed to
 * {@link Iterable} of {@link PolicyEntry}s.
 */
public static Iterable<PolicyEntry> newPolicyEntries(final JsonObject jsonObject) {
  checkNotNull(jsonObject, "JSON object");
  return jsonObject.stream()
      .map(jsonField -> newPolicyEntry(jsonField.getKey(), jsonField.getValue()))
      .collect(Collectors.toSet());
}

代码示例来源:origin: eclipse/ditto

/**
 * Creates a new {@code HeaderMapping} object from the specified JSON object.
 *
 * @param jsonObject a JSON object which provides the data for the HeaderMapping to be created.
 * @return a new HeaderMapping which is initialised with the extracted data from {@code jsonObject}.
 * @throws NullPointerException if {@code jsonObject} is {@code null}.
 * @throws org.eclipse.ditto.json.JsonParseException if {@code jsonObject} is not an appropriate JSON object.
 */
public static HeaderMapping fromJson(final JsonObject jsonObject) {
  return new ImmutableHeaderMapping(jsonObject.stream()
      .filter(f -> f.getValue().isString())
      .collect(Collectors.toMap(JsonField::getKeyName, jsonField -> jsonField.getValue().asString())));
}

代码示例来源:origin: org.eclipse.ditto/ditto-model-connectivity

/**
 * Creates a new {@code TargetMetrics} object from the specified JSON object.
 *
 * @param jsonObject a JSON object which provides the data for the TargetMetrics to be created.
 * @return a new TargetMetrics which is initialised with the extracted data from {@code jsonObject}.
 * @throws NullPointerException if {@code jsonObject} is {@code null}.
 * @throws org.eclipse.ditto.json.JsonParseException if {@code jsonObject} is not an appropriate JSON object.
 */
public static TargetMetrics fromJson(final JsonObject jsonObject) {
  final Map<String, AddressMetric> readAddressMetrics = jsonObject.getValue(JsonFields.ADDRESS_METRICS)
      .map(obj -> obj.stream()
          .collect(Collectors.toMap(
              f -> f.getKey().toString(),
              f -> ConnectivityModelFactory.addressMetricFromJson(f.getValue().asObject()))))
      .orElse(Collections.emptyMap());
  final long readPublishedMessages = jsonObject.getValueOrThrow(JsonFields.PUBLISHED_MESSAGES);
  return ImmutableTargetMetrics.of(readAddressMetrics, readPublishedMessages);
}

代码示例来源:origin: eclipse/ditto

/**
 * Creates a new {@code Resources} from the specified JSON object.
 *
 * @param jsonObject the JSON object of which a new Resources instance is to be created.
 * @return the {@code Resources} which was created from the given JSON object.
 * @throws NullPointerException if {@code jsonObject} is {@code null}.
 * @throws org.eclipse.ditto.json.JsonParseException if the passed in {@code jsonObject} was not in the expected
 * 'Resources' format.
 */
public static Resources fromJson(final JsonObject jsonObject) {
  final List<Resource> theResources = jsonObject.stream()
      .filter(field -> !Objects.equals(field.getKey(), JsonSchemaVersion.getJsonKey()))
      .map(field -> ImmutableResource.of(ResourceKey.newInstance(field.getKeyName()), field.getValue()))
      .collect(Collectors.toList());
  return of(theResources);
}

代码示例来源:origin: eclipse/ditto

/**
 * Creates a new {@code TargetMetrics} object from the specified JSON object.
 *
 * @param jsonObject a JSON object which provides the data for the TargetMetrics to be created.
 * @return a new TargetMetrics which is initialised with the extracted data from {@code jsonObject}.
 * @throws NullPointerException if {@code jsonObject} is {@code null}.
 * @throws org.eclipse.ditto.json.JsonParseException if {@code jsonObject} is not an appropriate JSON object.
 */
public static TargetMetrics fromJson(final JsonObject jsonObject) {
  final Map<String, AddressMetric> readAddressMetrics = jsonObject.getValue(JsonFields.ADDRESS_METRICS)
      .map(obj -> obj.stream()
          .collect(Collectors.toMap(
              f -> f.getKey().toString(),
              f -> ConnectivityModelFactory.addressMetricFromJson(f.getValue().asObject()))))
      .orElse(Collections.emptyMap());
  final long readPublishedMessages = jsonObject.getValueOrThrow(JsonFields.PUBLISHED_MESSAGES);
  return ImmutableTargetMetrics.of(readAddressMetrics, readPublishedMessages);
}

代码示例来源:origin: eclipse/ditto

/**
 * Creates a new {@code SourceMetrics} object from the specified JSON object.
 *
 * @param jsonObject a JSON object which provides the data for the SourceMetrics to be created.
 * @return a new SourceMetrics which is initialised with the extracted data from {@code jsonObject}.
 * @throws NullPointerException if {@code jsonObject} is {@code null}.
 * @throws org.eclipse.ditto.json.JsonParseException if {@code jsonObject} is not an appropriate JSON object.
 */
public static SourceMetrics fromJson(final JsonObject jsonObject) {
  final Map<String, AddressMetric> readAddressMetrics = jsonObject.getValue(JsonFields.ADDRESS_METRICS)
      .map(obj -> obj.stream()
          .collect(Collectors.toMap(
              f -> f.getKey().toString(),
              f -> ConnectivityModelFactory.addressMetricFromJson(f.getValue().asObject()))))
      .orElse(Collections.emptyMap());
  final long readConsumedMessages = jsonObject.getValueOrThrow(JsonFields.CONSUMED_MESSAGES);
  return ImmutableSourceMetrics.of(readAddressMetrics, readConsumedMessages);
}

代码示例来源:origin: org.eclipse.ditto/ditto-model-connectivity

/**
 * Creates a new {@code SourceMetrics} object from the specified JSON object.
 *
 * @param jsonObject a JSON object which provides the data for the SourceMetrics to be created.
 * @return a new SourceMetrics which is initialised with the extracted data from {@code jsonObject}.
 * @throws NullPointerException if {@code jsonObject} is {@code null}.
 * @throws org.eclipse.ditto.json.JsonParseException if {@code jsonObject} is not an appropriate JSON object.
 */
public static SourceMetrics fromJson(final JsonObject jsonObject) {
  final Map<String, AddressMetric> readAddressMetrics = jsonObject.getValue(JsonFields.ADDRESS_METRICS)
      .map(obj -> obj.stream()
          .collect(Collectors.toMap(
              f -> f.getKey().toString(),
              f -> ConnectivityModelFactory.addressMetricFromJson(f.getValue().asObject()))))
      .orElse(Collections.emptyMap());
  final long readConsumedMessages = jsonObject.getValueOrThrow(JsonFields.CONSUMED_MESSAGES);
  return ImmutableSourceMetrics.of(readAddressMetrics, readConsumedMessages);
}

代码示例来源:origin: org.eclipse.ditto/ditto-model-things

/**
 * Creates a new {@code AclEntry} object from the specified JSON object. If, for any reason, the specified JSON
 * object contains more than one field with Authorization Subject/permissions pairs only the first field is used
 * while all remaining fields are ignored.
 *
 * @param jsonObject a JSON object which provides the data for the ACL entry to be created.
 * @return a new ACL entry which is initialised with the extracted data from {@code jsonObject}.
 * @throws NullPointerException if {@code jsonObject} is {@code null}.
 * @throws DittoJsonException if {@code jsonObject} <ul> <li>is empty,</li> <li>contains only a field with the schema
 * version</li> <li>or it contains more than two fields.</li> </ul>
 */
public static AclEntry fromJson(final JsonObject jsonObject) {
  checkNotNull(jsonObject, "JSON object");
  return jsonObject.stream()
      .filter(field -> !Objects.equals(field.getKey(), JsonSchemaVersion.getJsonKey()))
      .findFirst()
      .map(field -> ImmutableAclEntry.of(field.getKey(), field.getValue()))
      .orElseThrow(() -> new DittoJsonException(JsonMissingFieldException.newBuilder()
          .message("The JSON object for 'aclEntry' is missing.")
          .build()));
}

代码示例来源:origin: eclipse/ditto

private static boolean isJsonValueIllegal(final JsonValue entity) {
  final boolean result;
  if (entity.isArray()) {
    result = entity.asArray().stream().anyMatch(CommandWithOptionalEntityValidator::isJsonValueIllegal);
  } else if (entity.isObject()) {
    result = entity.asObject().stream().anyMatch(CommandWithOptionalEntityValidator::isJsonFieldIllegal);
  } else if (entity.isString()) {
    result = isStringIllegal(entity.asString());
  } else {
    result = false;
  }
  return result;
}

代码示例来源:origin: org.eclipse.ditto/ditto-model-connectivity

/**
 * Creates a new {@code MappingContext} object from the specified JSON object.
 *
 * @param jsonObject a JSON object which provides the data for the MappingContext to be created.
 * @return a new MappingContext which is initialised with the extracted data from {@code jsonObject}.
 * @throws NullPointerException if {@code jsonObject} is {@code null}.
 * @throws org.eclipse.ditto.json.JsonParseException if {@code jsonObject} is not an appropriate JSON object.
 */
public static MappingContext fromJson(final JsonObject jsonObject) {
  final String mappingEngine = jsonObject.getValueOrThrow(JsonFields.MAPPING_ENGINE);
  final Map<String, String> options = jsonObject.getValueOrThrow(JsonFields.OPTIONS).stream()
      .collect(Collectors.toMap(
          e -> e.getKey().toString(),
          e -> e.getValue().isString() ? e.getValue().asString() : e.getValue().toString())
      );
  return of(mappingEngine, options);
}

代码示例来源:origin: eclipse/ditto

/**
 * Creates a new {@code MappingContext} object from the specified JSON object.
 *
 * @param jsonObject a JSON object which provides the data for the MappingContext to be created.
 * @return a new MappingContext which is initialised with the extracted data from {@code jsonObject}.
 * @throws NullPointerException if {@code jsonObject} is {@code null}.
 * @throws org.eclipse.ditto.json.JsonParseException if {@code jsonObject} is not an appropriate JSON object.
 */
public static MappingContext fromJson(final JsonObject jsonObject) {
  final String mappingEngine = jsonObject.getValueOrThrow(JsonFields.MAPPING_ENGINE);
  final Map<String, String> options = jsonObject.getValueOrThrow(JsonFields.OPTIONS).stream()
      .collect(Collectors.toMap(
          e -> e.getKey().toString(),
          e -> e.getValue().isString() ? e.getValue().asString() : e.getValue().toString())
      );
  return of(mappingEngine, options);
}

相关文章