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

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

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

JsonPointer.isEmpty介绍

[英]Indicates whether this pointer does contain any elements or not. If the level count is zero the pointer is regarded to be empty.
[中]指示此指针是否包含任何元素。如果级别计数为零,则指针视为空。

代码示例

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

@Override
public boolean isEmpty() {
  return jsonPointer.isEmpty();
}

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

@Override
public boolean isEmpty() {
  return jsonPointer.isEmpty();
}

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

private ImmutableJsonFieldSelector(final Iterable<JsonPointer> thePointers,
    @Nullable final String theJsonFieldSelectorString) {
  final Set<JsonPointer> pointersSet = new LinkedHashSet<>();
  thePointers.forEach(p -> {
    if (!p.isEmpty()) {
      pointersSet.add(p);
    }
  });
  pointers = Collections.unmodifiableSet(pointersSet);
  jsonFieldSelectorString = theJsonFieldSelectorString != null ? theJsonFieldSelectorString :
      calculateFieldSelectorString(pointers);
}

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

private ImmutableJsonFieldSelector(final Iterable<JsonPointer> thePointers,
    @Nullable final String theJsonFieldSelectorString) {
  final Set<JsonPointer> pointersSet = new LinkedHashSet<>();
  thePointers.forEach(p -> {
    if (!p.isEmpty()) {
      pointersSet.add(p);
    }
  });
  pointers = Collections.unmodifiableSet(pointersSet);
  jsonFieldSelectorString = theJsonFieldSelectorString != null ? theJsonFieldSelectorString :
      calculateFieldSelectorString(pointers);
}

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

@Override
public ImmutableJsonPointer append(final JsonPointer subPointer) {
  checkSubPointer(subPointer);
  final ImmutableJsonPointer result;
  if (subPointer.isEmpty()) {
    result = this;
  } else {
    final List<JsonKey> newJsonKeys = new ArrayList<>(jsonKeyHierarchy);
    subPointer.forEach(newJsonKeys::add);
    result = newInstance(newJsonKeys);
  }
  return result;
}

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

@Override
public ImmutableJsonPointer append(final JsonPointer subPointer) {
  checkSubPointer(subPointer);
  final ImmutableJsonPointer result;
  if (subPointer.isEmpty()) {
    result = this;
  } else {
    final List<JsonKey> newJsonKeys = new ArrayList<>(jsonKeyHierarchy);
    subPointer.forEach(newJsonKeys::add);
    result = newInstance(newJsonKeys);
  }
  return result;
}

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

private static Function<JsonValue, JsonValue> transformResponse(final String serviceName, final Integer instance) {
  final JsonPointer transformerPointer = transformerPointer(serviceName, instance);
  if (transformerPointer.isEmpty()) {
    return resp -> resp;
  } else {
    return resp -> resp.asObject()
        .getValue(transformerPointer)
        .orElse(JsonFactory.nullObject());
  }
}

代码示例来源: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: org.eclipse.ditto/ditto-json

/**
 * Converts the specified char sequence to a {@link JsonPointer} which is guaranteed to be not empty.
 *
 * @param keyOrPointer a string representation of a JSON pointer or a JsonKey.
 * @return the pointer.
 * @throws NullPointerException if {@code keyOrPointer} is {@code null}.
 * @throws IllegalArgumentException if {@code keyOrPointer} would lead to an empty JsonPointer.
 */
static JsonPointer getNonEmptyPointer(final CharSequence keyOrPointer) {
  requireNonNull(keyOrPointer, "The key or pointer char sequence must not be null!");
  final JsonPointer result;
  if (isPointer(keyOrPointer)) {
    result = JsonFactory.newPointer(keyOrPointer);
  } else {
    final JsonKey jsonKey = JsonFactory.newKey(keyOrPointer);
    result = jsonKey.asPointer();
  }
  if (result.isEmpty()) {
    throw new IllegalArgumentException("The key or pointer must not be empty!");
  }
  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-signals-commands-things

private static JsonPointer checkAttributePointer(final JsonPointer pointer, final DittoHeaders dittoHeaders) {
  checkNotNull(pointer, "key of the attribute to be modified");
  if (pointer.isEmpty()) {
    throw AttributePointerInvalidException.newBuilder(pointer)
        .dittoHeaders(dittoHeaders)
        .build();
  }
  return pointer;
}

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

/**
 * Converts the specified char sequence to a {@link JsonPointer} which is guaranteed to be not empty.
 *
 * @param keyOrPointer a string representation of a JSON pointer or a JsonKey.
 * @return the pointer.
 * @throws NullPointerException if {@code keyOrPointer} is {@code null}.
 * @throws IllegalArgumentException if {@code keyOrPointer} would lead to an empty JsonPointer.
 */
static JsonPointer getNonEmptyPointer(final CharSequence keyOrPointer) {
  requireNonNull(keyOrPointer, "The key or pointer char sequence must not be null!");
  final JsonPointer result;
  if (isPointer(keyOrPointer)) {
    result = newPointer(keyOrPointer);
  } else {
    final JsonKey jsonKey = newKey(keyOrPointer);
    result = jsonKey.asPointer();
  }
  if (result.isEmpty()) {
    throw new IllegalArgumentException("The key or pointer must not be empty!");
  }
  return result;
}

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

private static JsonPointer checkAttributePointer(final JsonPointer pointer, final DittoHeaders dittoHeaders) {
  checkNotNull(pointer, "key of the attribute to be modified");
  if (pointer.isEmpty()) {
    throw AttributePointerInvalidException.newBuilder(pointer)
        .dittoHeaders(dittoHeaders)
        .build();
  }
  return pointer;
}

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

checkPointer(pointer);
if (pointer.isEmpty()) {
  return this;

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

/**
 * Verifies that the actual JSON pointer is empty.
 *
 * @return this assert to allow method chaining.
 */
public JsonPointerAssert isEmpty() {
  isNotNull();
  Assertions.assertThat(actual.isEmpty())
      .overridingErrorMessage("Expected JSON object to be empty but it was not.")
      .isTrue();
  return this;
}

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

/**
 * Verifies that the actual JSON pointer is <em>not</em> empty.
 *
 * @return this assert to allow method chaining.
 */
public JsonPointerAssert isNotEmpty() {
  isNotNull();
  Assertions.assertThat(actual.isEmpty())
      .overridingErrorMessage("Expected JSON object not to be empty but it was.")
      .isFalse();
  return this;
}

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

checkPointer(pointer);
if (pointer.isEmpty()) {
  return this;

代码示例来源: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;
}

相关文章