@Override public Map<String, Object> toQuery() { final Map<String, Object> result = new HashMap<>(); if (isRecurse()) { result.put("recurse", ""); } optionallyAdd(result, "cas", getCas()); optionallyAdd(result, "dc", getDatacenter()); return result; } }
@Value.Derived public boolean isRecurse() { return getRecurse().isPresent(); }
/** * Fill a builder with attribute values from the provided {@code DeleteOptions} instance. * Regular attribute values will be replaced with those from the given instance. * Absent optional values will not replace present values. * @param instance The instance from which to copy values * @return {@code this} builder for use in a chained invocation */ public final Builder from(DeleteOptions instance) { Preconditions.checkNotNull(instance, "instance"); Optional<Long> casOptional = instance.getCas(); if (casOptional.isPresent()) { cas(casOptional); } Optional<Boolean> recurseOptional = instance.getRecurse(); if (recurseOptional.isPresent()) { recurse(recurseOptional); } Optional<String> datacenterOptional = instance.getDatacenter(); if (datacenterOptional.isPresent()) { datacenter(datacenterOptional); } return this; }
private ImmutableDeleteOptions( @Nullable Long cas, @Nullable Boolean recurse, @Nullable String datacenter) { this.cas = cas; this.recurse = recurse; this.datacenter = datacenter; this.isRecurse = super.isRecurse(); }
/** * Deletes a specified key. * * DELETE /v1/kv/{key} * * @param key The key to delete. * @param deleteOptions DELETE options (e.g. recurse, cas) */ public void deleteKey(String key, DeleteOptions deleteOptions) { checkArgument(StringUtils.isNotEmpty(key), "Key must be defined"); Map<String, Object> query = deleteOptions.toQuery(); http.handle(api.deleteValues(trimLeadingSlash(key), query)); }