/** * Copy the current immutable object by setting a <i>present</i> value for the optional {@link Operation#flags() flags} attribute. * @param value The value for flags * @return A modified copy of {@code this} object */ public final ImmutableOperation withFlags(long value) { @Nullable Long newValue = value; if (Objects.equals(this.flags, newValue)) return this; return new ImmutableOperation(this.verb, this.key, this.value, newValue, this.index, this.session); }
/** * This instance is equal to all instances of {@code ImmutableOperation} that have equal attribute values. * @return {@code true} if {@code this} is equal to {@code another} instance */ @Override public boolean equals(@Nullable Object another) { if (this == another) return true; return another instanceof ImmutableOperation && equalTo((ImmutableOperation) another); }
public static ImmutableOperation.Builder builder(Verb verb) { return ImmutableOperation.builder().verb(verb.toValue()); } }
/** * Creates an immutable copy of a {@link Operation} value. * Uses accessors to get values to initialize the new immutable instance. * If an instance is already immutable, it is returned as is. * @param instance The instance to copy * @return A copied immutable Operation instance */ public static ImmutableOperation copyOf(Operation instance) { if (instance instanceof ImmutableOperation) { return (ImmutableOperation) instance; } return ImmutableOperation.builder() .from(instance) .build(); }
/** * Returns {@code true} if the given session owned the lock, otherwise {@code false}. */ public static boolean unlockAndDelete(KeyValueClient kv, String key, String sessionId) { try { kv.performTransaction( ImmutableOperation.builder(Verb.UNLOCK).key(key).session(sessionId).build(), ImmutableOperation.builder(Verb.DELETE).key(key).build()); return true; } catch (ConsulException e) { if (e.getCode() == HTTP_CONFLICT) { return false; // didn't own lock; no worries } throw e; } }
/** * Copy the current immutable object by setting a <i>present</i> value for the optional {@link Operation#value() value} attribute. * @param value The value for value * @return A modified copy of {@code this} object */ public final ImmutableOperation withValue(String value) { @Nullable String newValue = Preconditions.checkNotNull(value, "value"); if (Objects.equals(this.value, newValue)) return this; return new ImmutableOperation(this.verb, this.key, newValue, this.flags, this.index, this.session); }
/** * @param json A JSON-bindable data structure * @return An immutable value type * @deprecated Do not use this method directly, it exists only for the <em>Jackson</em>-binding infrastructure */ @Deprecated @JsonCreator static ImmutableOperation fromJson(Json json) { ImmutableOperation.Builder builder = ImmutableOperation.builder(); if (json.verb != null) { builder.verb(json.verb); } if (json.key != null) { builder.key(json.key); } if (json.value != null) { builder.value(json.value); } if (json.flags != null) { builder.flags(json.flags); } if (json.index != null) { builder.index(json.index); } if (json.session != null) { builder.session(json.session); } return builder.build(); }
/** * Copy the current immutable object by setting an optional value for the {@link Operation#index() index} attribute. * A shallow reference equality check is used on unboxed optional value to prevent copying of the same value by returning {@code this}. * @param optional A value for index * @return A modified copy of {@code this} object */ public final ImmutableOperation withIndex(Optional<BigInteger> optional) { @Nullable BigInteger value = optional.orElse(null); if (this.index == value) return this; return new ImmutableOperation(this.verb, this.key, this.value, this.flags, value, this.session); }
/** * Copy the current immutable object by setting an optional value for the {@link Operation#key() key} attribute. * An equality check is used on inner nullable value to prevent copying of the same value by returning {@code this}. * @param optional A value for key * @return A modified copy of {@code this} object */ public final ImmutableOperation withKey(Optional<String> optional) { @Nullable String value = optional.orElse(null); if (Objects.equals(this.key, value)) return this; return new ImmutableOperation(this.verb, value, this.value, this.flags, this.index, this.session); }
/** * Copy the current immutable object by setting a <i>present</i> value for the optional {@link Operation#index() index} attribute. * @param value The value for index * @return A modified copy of {@code this} object */ public final ImmutableOperation withIndex(BigInteger value) { @Nullable BigInteger newValue = Preconditions.checkNotNull(value, "index"); if (this.index == newValue) return this; return new ImmutableOperation(this.verb, this.key, this.value, this.flags, newValue, this.session); }
/** * Copy the current immutable object by setting an optional value for the {@link Operation#flags() flags} attribute. * An equality check is used on inner nullable value to prevent copying of the same value by returning {@code this}. * @param optional A value for flags * @return A modified copy of {@code this} object */ public final ImmutableOperation withFlags(Optional<Long> optional) { @Nullable Long value = optional.orElse(null); if (Objects.equals(this.flags, value)) return this; return new ImmutableOperation(this.verb, this.key, this.value, value, this.index, this.session); }
/** * Copy the current immutable object by setting a <i>present</i> value for the optional {@link Operation#key() key} attribute. * @param value The value for key * @return A modified copy of {@code this} object */ public final ImmutableOperation withKey(String value) { @Nullable String newValue = Preconditions.checkNotNull(value, "key"); if (Objects.equals(this.key, newValue)) return this; return new ImmutableOperation(this.verb, newValue, this.value, this.flags, this.index, this.session); }
/** * Copy the current immutable object by setting a <i>present</i> value for the optional {@link Operation#session() session} attribute. * @param value The value for session * @return A modified copy of {@code this} object */ public final ImmutableOperation withSession(String value) { @Nullable String newValue = Preconditions.checkNotNull(value, "session"); if (Objects.equals(this.session, newValue)) return this; return new ImmutableOperation(this.verb, this.key, this.value, this.flags, this.index, newValue); }
/** * Copy the current immutable object by setting an optional value for the {@link Operation#value() value} attribute. * An equality check is used on inner nullable value to prevent copying of the same value by returning {@code this}. * @param optional A value for value * @return A modified copy of {@code this} object */ public final ImmutableOperation withValue(Optional<String> optional) { @Nullable String value = optional.orElse(null); if (Objects.equals(this.value, value)) return this; return new ImmutableOperation(this.verb, this.key, value, this.flags, this.index, this.session); }
/** * Copy the current immutable object by setting an optional value for the {@link Operation#session() session} attribute. * An equality check is used on inner nullable value to prevent copying of the same value by returning {@code this}. * @param optional A value for session * @return A modified copy of {@code this} object */ public final ImmutableOperation withSession(Optional<String> optional) { @Nullable String value = optional.orElse(null); if (Objects.equals(this.session, value)) return this; return new ImmutableOperation(this.verb, this.key, this.value, this.flags, this.index, value); }
/** * Copy the current immutable object by setting a value for the {@link Operation#verb() verb} attribute. * An equals check used to prevent copying of the same value by returning {@code this}. * @param value A new value for verb * @return A modified copy of the {@code this} object */ public final ImmutableOperation withVerb(String value) { if (this.verb.equals(value)) return this; return new ImmutableOperation( Preconditions.checkNotNull(value, "verb"), this.key, this.value, this.flags, this.index, this.session); }
/** * Builds a new {@link ImmutableOperation ImmutableOperation}. * @return An immutable instance of Operation * @throws java.lang.IllegalStateException if any required attributes are missing */ public ImmutableOperation build() { if (initBits != 0) { throw new IllegalStateException(formatRequiredAttributesMessage()); } return new ImmutableOperation(verb, key, value, flags, index, session); }