本文整理了Java中org.eclipse.ditto.json.JsonPointer.getRoot()
方法的一些代码示例,展示了JsonPointer.getRoot()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。JsonPointer.getRoot()
方法的具体详情如下:
包路径:org.eclipse.ditto.json.JsonPointer
类名称:JsonPointer
方法名:getRoot
[英]Returns the root JSON key of this pointer. If the level count of this pointer is one the root is the same as the leaf.
[中]返回此指针的根JSON键。如果此指针的级别计数为1,则根与叶相同。
代码示例来源:origin: org.eclipse.ditto/ditto-protocol-adapter
@Override
public Optional<JsonKey> getRoot() {
return jsonPointer.getRoot();
}
代码示例来源:origin: eclipse/ditto
@Override
public Optional<JsonKey> getRoot() {
return jsonPointer.getRoot();
}
代码示例来源:origin: org.eclipse.ditto/ditto-protocol-adapter
@Override
public Optional<MessageDirection> getDirection() {
return jsonPointer.getRoot()
.flatMap(ImmutableMessagePath::jsonKeyToDirection)
.map(Optional::of)
.orElseGet(() -> jsonPointer.getRoot()
.filter(FEATURES::equals)
.flatMap(features -> jsonPointer.get(2))
.flatMap(ImmutableMessagePath::jsonKeyToDirection));
}
代码示例来源:origin: eclipse/ditto
@Override
public Optional<MessageDirection> getDirection() {
return jsonPointer.getRoot()
.flatMap(ImmutableMessagePath::jsonKeyToDirection)
.map(Optional::of)
.orElseGet(() -> jsonPointer.getRoot()
.filter(FEATURES::equals)
.flatMap(features -> jsonPointer.get(2))
.flatMap(ImmutableMessagePath::jsonKeyToDirection));
}
代码示例来源: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: eclipse/ditto
/**
* Check if inlined policy should be retrieved together with the thing.
*
* @param command the thing query command.
* @return whether it is necessary to retrieve the thing's policy.
*/
private static boolean shouldRetrievePolicyWithThing(final ThingCommand command) {
final RetrieveThing retrieveThing = (RetrieveThing) command;
final boolean isNotV1 = JsonSchemaVersion.V_1 != command.getImplementedSchemaVersion();
return isNotV1 && retrieveThing.getSelectedFields().filter(selector ->
selector.getPointers().stream().anyMatch(jsonPointer ->
jsonPointer.getRoot()
.filter(jsonKey -> Policy.INLINED_FIELD_NAME.equals(jsonKey.toString()))
.isPresent()))
.isPresent();
}
代码示例来源: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: 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: 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 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
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
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 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: eclipse/ditto
/**
* Verifies that the actual JSON pointer has the specified root.
*
* @param expectedRoot the expected root of the actual JSON pointer.
* @return this assert to allow method chaining.
*/
public JsonPointerAssert hasRoot(final JsonKey expectedRoot) {
isNotNull();
final Optional<JsonKey> actualRoot = actual.getRoot();
Assertions.assertThat(actualRoot)
.overridingErrorMessage("Expected <%s> to have root <%s> but it had <%s>", actual, expectedRoot,
actualRoot.orElse(null))
.contains(expectedRoot);
return myself;
}
代码示例来源: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);
}
内容来源于网络,如有侵权,请联系作者删除!