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

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

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

JsonPointer.nextLevel介绍

[英]Goes to the next sub level of this pointer.
[中]转到此指针的下一个子级别。

代码示例

代码示例来源:origin: org.eclipse.ditto/ditto-protocol-adapter

@Override
public JsonPointer nextLevel() {
  return jsonPointer.nextLevel();
}

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

@Override
public JsonPointer nextLevel() {
  return jsonPointer.nextLevel();
}

代码示例来源:origin: org.eclipse.ditto/ditto-protocol-adapter

@Override
public Optional<String> getFeatureId() {
  return jsonPointer.getRoot()
      .filter(FEATURES::equals)
      .map(features -> jsonPointer.nextLevel())
      .flatMap(JsonPointer::getRoot)
      .map(JsonKey::toString);
}

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

@Override
public Optional<String> getFeatureId() {
  return jsonPointer.getRoot()
      .filter(FEATURES::equals)
      .map(features -> jsonPointer.nextLevel())
      .flatMap(JsonPointer::getRoot)
      .map(JsonKey::toString);
}

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

@Override
public Optional<JsonField> getField(final CharSequence key) {
  requireNonNull(key, "The key or pointer of the field to be retrieved must not be null!");
  final JsonPointer pointer = JsonFactory.newPointer(key);
  Optional<JsonField> result = pointer.getRoot()
      .map(JsonKey::toString)
      .map(fields::get);
  if (1 < pointer.getLevelCount()) {
    result = result.map(JsonField::getValue)
        .filter(JsonValue::isObject)
        .map(JsonValue::asObject)
        .flatMap(jsonObject -> jsonObject.getField(pointer.nextLevel())); // Recursion
  }
  return result;
}

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

@Override
public Optional<JsonField> getField(final CharSequence key) {
  requireNonNull(key, "The key or pointer of the field to be retrieved must not be null!");
  final JsonPointer pointer = JsonPointer.of(key);
  Optional<JsonField> result = pointer.getRoot()
      .map(JsonKey::toString)
      .map(fieldMap::getOrNull);
  if (1 < pointer.getLevelCount()) {
    result = result.map(JsonField::getValue)
        .filter(JsonValue::isObject)
        .map(JsonValue::asObject)
        .flatMap(jsonObject -> jsonObject.getField(pointer.nextLevel())); // Recursion
  }
  return result;
}

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

private Optional<JsonValue> getValueForPointer(final JsonPointer pointer) {
  final Optional<JsonValue> result;
  final JsonKey rootKey = pointer.getRoot().orElse(ROOT_KEY);
  final int levelCount = pointer.getLevelCount();
  if (0 == levelCount) {
    result = Optional.of(this);
  } else if (1 == levelCount) {
    // same as getting a value for a key
    result = getValueForKey(rootKey);
  } else {
    result = getValueForKey(rootKey)
        .filter(JsonValue::isObject)
        .map(JsonValue::asObject)
        .flatMap(jsonObject -> jsonObject.getValue(pointer.nextLevel()));
  }
  return result;
}

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

private Optional<JsonValue> getValueForPointer(final JsonPointer pointer) {
  final Optional<JsonValue> result;
  final JsonKey rootKey = pointer.getRoot().orElse(ROOT_KEY);
  final int levelCount = pointer.getLevelCount();
  if (0 == levelCount) {
    result = Optional.of(this);
  } else if (1 == levelCount) {
    // same as getting a value for a key
    result = getValueForKey(rootKey);
  } else {
    result = getValueForKey(rootKey)
        .filter(JsonValue::isObject)
        .map(JsonValue::asObject)
        .flatMap(jsonObject -> jsonObject.getValue(pointer.nextLevel()));
  }
  return result;
}

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

@Override
public boolean contains(final CharSequence key) {
  requireNonNull(key, "The key or pointer to check the existence of a value for must not be null!");
  final boolean result;
  final JsonPointer pointer = JsonFactory.newPointer(key);
  if (1 >= pointer.getLevelCount()) {
    result = pointer.getRoot().map(this::containsKey).orElse(false);
  } else {
    result = pointer.getRoot()
        .flatMap(this::getValueForKey)
        .map(jsonValue -> !jsonValue.isObject() ||
            jsonValue.asObject().contains(pointer.nextLevel())) // Recursion
        .orElse(false);
  }
  return result;
}

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

private static JsonObject setFieldInHierarchy(final JsonObject target, final JsonPointer pointer,
    final JsonField jsonField) {
  if (1 >= pointer.getLevelCount()) {
    return target.set(jsonField);
  }
  final JsonKey rootKey = pointer.getRoot().orElse(ROOT_KEY);
  final JsonObject newTarget = target.getValue(rootKey)
      .filter(JsonValue::isObject)
      .filter(jsonValue -> !jsonValue.isNull())
      .map(JsonValue::asObject)
      .orElseGet(ImmutableJsonObject::empty);
  // let the recursion begin ]:-)
  return target.setValue(rootKey, setFieldInHierarchy(newTarget, pointer.nextLevel(), jsonField));
}

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

@Override
public boolean contains(final CharSequence key) {
  requireNonNull(key, "The key or pointer to check the existence of a value for must not be null!");
  final boolean result;
  final JsonPointer pointer = JsonPointer.of(key);
  if (1 >= pointer.getLevelCount()) {
    result = pointer.getRoot().map(this::containsKey).orElse(false);
  } else {
    result = pointer.getRoot()
        .flatMap(this::getValueForKey)
        .map(jsonValue -> !jsonValue.isObject() ||
            jsonValue.asObject().contains(pointer.nextLevel())) // Recursion
        .orElse(false);
  }
  return result;
}

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

private static JsonObject setFieldInHierarchy(final JsonObject target, final JsonPointer pointer,
    final JsonField jsonField) {
  if (1 >= pointer.getLevelCount()) {
    return target.set(jsonField);
  }
  final JsonKey rootKey = pointer.getRoot().orElse(ROOT_KEY);
  final JsonObject newTarget = target.getValue(rootKey)
      .filter(JsonValue::isObject)
      .filter(jsonValue -> !jsonValue.isNull())
      .map(JsonValue::asObject)
      .orElseGet(ImmutableJsonObject::empty);
  // let the recursion begin ]:-)
  return target.setValue(rootKey, setFieldInHierarchy(newTarget, pointer.nextLevel(), jsonField));
}

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

private JsonObject removeForPointer(final JsonPointer pointer) {
  final JsonObject result;
  final JsonKey rootKey = pointer.getRoot().orElse(ROOT_KEY);
  final Optional<JsonFieldDefinition> rootKeyDefinition = getDefinitionForKey(rootKey);
  if (pointer.isEmpty()) {
    result = this;
  } else if (1 == pointer.getLevelCount()) {
    result = removeValueForKey(rootKey);
  } else {
    final JsonPointer nextPointerLevel = pointer.nextLevel();
    final Predicate<JsonObject> containsNextLevelRootKey = jsonObject -> nextPointerLevel.getRoot()
        .map(jsonObject::contains)
        .orElse(false);
    result = getValueForKey(rootKey)
        .filter(JsonValue::isObject)
        .map(JsonValue::asObject)
        .filter(containsNextLevelRootKey)
        .map(jsonObject -> jsonObject.remove(nextPointerLevel)) // Recursion
        .map(withoutValue -> JsonFactory.newField(rootKey, withoutValue, rootKeyDefinition.orElse(null)))
        .map(this::set)
        .orElse(this);
  }
  return result;
}

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

private JsonObject removeForPointer(final JsonPointer pointer) {
  final JsonObject result;
  final JsonKey rootKey = pointer.getRoot().orElse(ROOT_KEY);
  final Optional<JsonFieldDefinition> rootKeyDefinition = getDefinitionForKey(rootKey);
  if (pointer.isEmpty()) {
    result = this;
  } else if (1 == pointer.getLevelCount()) {
    result = removeValueForKey(rootKey);
  } else {
    final JsonPointer nextPointerLevel = pointer.nextLevel();
    final Predicate<JsonObject> containsNextLevelRootKey = jsonObject -> nextPointerLevel.getRoot()
        .map(jsonObject::contains)
        .orElse(false);
    result = getValueForKey(rootKey)
        .filter(JsonValue::isObject)
        .map(JsonValue::asObject)
        .filter(containsNextLevelRootKey)
        .map(jsonObject -> jsonObject.remove(nextPointerLevel)) // Recursion
        .map(withoutValue -> JsonField.newInstance(rootKey, withoutValue, rootKeyDefinition.orElse(null)))
        .map(this::set)
        .orElse(this);
  }
  return result;
}

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

final JsonPointer nextPointerLevel = pointer.nextLevel();
final Predicate<JsonObject> containsNextLevelRootKey = jsonObject -> nextPointerLevel.getRoot()
    .filter(jsonObject::contains)

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

return newChild;
});
addResourceSubTree(node, resource, path.nextLevel());

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

private ImmutableJsonObjectBuilder remove(final JsonPointer pointer) {
  pointer.getRoot()
      .map(JsonKey::toString)
      .map(fields::get)
      .ifPresent(jsonField -> {
        final JsonValue rootValue = jsonField.getValue();
        final JsonPointer nextPointerLevel = pointer.nextLevel();
        if (rootValue.isObject() && !nextPointerLevel.isEmpty()) {
          JsonObject rootObject = rootValue.asObject();
          rootObject = rootObject.remove(nextPointerLevel);
          set(JsonFactory.newField(jsonField.getKey(), rootObject,
              jsonField.getDefinition().orElse(null)));
        } else {
          fields.remove(jsonField.getKeyName());
        }
      });
  return this;
}

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

private ImmutableJsonObjectBuilder remove(final JsonPointer pointer) {
  pointer.getRoot()
      .map(JsonKey::toString)
      .map(fields::get)
      .ifPresent(jsonField -> {
        final JsonValue rootValue = jsonField.getValue();
        final JsonPointer nextPointerLevel = pointer.nextLevel();
        if (rootValue.isObject() && !nextPointerLevel.isEmpty()) {
          JsonObject rootObject = rootValue.asObject();
          rootObject = rootObject.remove(nextPointerLevel);
          set(JsonFactory.newField(jsonField.getKey(), rootObject,
              jsonField.getDefinition().orElse(null)));
        } else {
          fields.remove(jsonField.getKeyName());
        }
      });
  return this;
}

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

private static JsonObjectBuilder setFieldInHierarchy(final ImmutableJsonObjectBuilder target,
    final JsonPointer pointer, final JsonField field) {
  if (1 >= pointer.getLevelCount()) {
    return target.set(field);
  }
  final JsonKey rootKey = pointer.getRoot().orElse(ROOT_KEY);
  final ImmutableJsonObjectBuilder newTarget = newInstance();
  final JsonField rootJsonField = target.fields.get(rootKey.toString());
  if (null != rootJsonField) {
    final JsonValue rootValue = rootJsonField.getValue();
    if (rootValue.isObject() && !rootValue.isNull()) {
      newTarget.setAll(rootValue.asObject());
    }
  }
  // let the recursion begin >:-(
  final JsonObject jsonObject = setFieldInHierarchy(newTarget, pointer.nextLevel(), field).build();
  return target.set(rootKey, jsonObject);
}

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

private static JsonObjectBuilder setFieldInHierarchy(final ImmutableJsonObjectBuilder target,
    final JsonPointer pointer, final JsonField field) {
  if (1 >= pointer.getLevelCount()) {
    return target.set(field);
  }
  final JsonKey rootKey = pointer.getRoot().orElse(ROOT_KEY);
  final ImmutableJsonObjectBuilder newTarget = newInstance();
  final JsonField rootJsonField = target.fields.get(rootKey.toString());
  if (null != rootJsonField) {
    final JsonValue rootValue = rootJsonField.getValue();
    if (rootValue.isObject() && !rootValue.isNull()) {
      newTarget.setAll(rootValue.asObject());
    }
  }
  // let the recursion begin >:-(
  final JsonObject jsonObject = setFieldInHierarchy(newTarget, pointer.nextLevel(), field).build();
  return target.set(rootKey, jsonObject);
}

相关文章