com.palantir.atlasdb.timelock.api.ConjureLockRequest Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of timelock-api-objects Show documentation
Show all versions of timelock-api-objects Show documentation
Palantir open source project
package com.palantir.atlasdb.timelock.api;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonSetter;
import com.fasterxml.jackson.annotation.Nulls;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.palantir.conjure.java.lib.internal.ConjureCollections;
import com.palantir.logsafe.Preconditions;
import com.palantir.logsafe.Safe;
import com.palantir.logsafe.SafeArg;
import com.palantir.logsafe.Unsafe;
import com.palantir.logsafe.exceptions.SafeIllegalArgumentException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Optional;
import java.util.UUID;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import javax.annotation.processing.Generated;
@Unsafe
@JsonDeserialize(builder = ConjureLockRequest.Builder.class)
@Generated("com.palantir.conjure.java.types.BeanGenerator")
public final class ConjureLockRequest {
private final UUID requestId;
private final List lockDescriptors;
private final int acquireTimeoutMs;
private final Optional clientDescription;
private final Optional metadata;
private int memoizedHashCode;
private ConjureLockRequest(
UUID requestId,
List lockDescriptors,
int acquireTimeoutMs,
Optional clientDescription,
Optional metadata) {
validateFields(requestId, lockDescriptors, clientDescription, metadata);
this.requestId = requestId;
this.lockDescriptors = Collections.unmodifiableList(lockDescriptors);
this.acquireTimeoutMs = acquireTimeoutMs;
this.clientDescription = clientDescription;
this.metadata = metadata;
}
@JsonProperty("requestId")
@Safe
public UUID getRequestId() {
return this.requestId;
}
@JsonProperty("lockDescriptors")
public List getLockDescriptors() {
return this.lockDescriptors;
}
@JsonProperty("acquireTimeoutMs")
@Safe
public int getAcquireTimeoutMs() {
return this.acquireTimeoutMs;
}
@JsonProperty("clientDescription")
@Unsafe
@JsonInclude(JsonInclude.Include.NON_ABSENT)
public Optional getClientDescription() {
return this.clientDescription;
}
@JsonProperty("metadata")
@JsonInclude(JsonInclude.Include.NON_ABSENT)
public Optional getMetadata() {
return this.metadata;
}
@Override
public boolean equals(@Nullable Object other) {
return this == other || (other instanceof ConjureLockRequest && equalTo((ConjureLockRequest) other));
}
private boolean equalTo(ConjureLockRequest other) {
if (this.memoizedHashCode != 0
&& other.memoizedHashCode != 0
&& this.memoizedHashCode != other.memoizedHashCode) {
return false;
}
return this.requestId.equals(other.requestId)
&& this.lockDescriptors.equals(other.lockDescriptors)
&& this.acquireTimeoutMs == other.acquireTimeoutMs
&& this.clientDescription.equals(other.clientDescription)
&& this.metadata.equals(other.metadata);
}
@Override
public int hashCode() {
int result = memoizedHashCode;
if (result == 0) {
int hash = 1;
hash = 31 * hash + this.requestId.hashCode();
hash = 31 * hash + this.lockDescriptors.hashCode();
hash = 31 * hash + this.acquireTimeoutMs;
hash = 31 * hash + this.clientDescription.hashCode();
hash = 31 * hash + this.metadata.hashCode();
result = hash;
memoizedHashCode = result;
}
return result;
}
@Override
@Unsafe
public String toString() {
return "ConjureLockRequest{requestId: " + requestId + ", lockDescriptors: " + lockDescriptors
+ ", acquireTimeoutMs: " + acquireTimeoutMs + ", clientDescription: " + clientDescription
+ ", metadata: " + metadata + '}';
}
private static void validateFields(
UUID requestId,
List lockDescriptors,
Optional clientDescription,
Optional metadata) {
List missingFields = null;
missingFields = addFieldIfMissing(missingFields, requestId, "requestId");
missingFields = addFieldIfMissing(missingFields, lockDescriptors, "lockDescriptors");
missingFields = addFieldIfMissing(missingFields, clientDescription, "clientDescription");
missingFields = addFieldIfMissing(missingFields, metadata, "metadata");
if (missingFields != null) {
throw new SafeIllegalArgumentException(
"Some required fields have not been set", SafeArg.of("missingFields", missingFields));
}
}
private static List addFieldIfMissing(List prev, Object fieldValue, String fieldName) {
List missingFields = prev;
if (fieldValue == null) {
if (missingFields == null) {
missingFields = new ArrayList<>(4);
}
missingFields.add(fieldName);
}
return missingFields;
}
public static Builder builder() {
return new Builder();
}
@Generated("com.palantir.conjure.java.types.BeanBuilderGenerator")
@JsonIgnoreProperties(ignoreUnknown = true)
public static final class Builder {
boolean _buildInvoked;
private @Safe UUID requestId;
private List lockDescriptors = new ArrayList<>();
private @Safe int acquireTimeoutMs;
private Optional<@Unsafe String> clientDescription = Optional.empty();
private Optional metadata = Optional.empty();
private boolean _acquireTimeoutMsInitialized = false;
private Builder() {}
public Builder from(ConjureLockRequest other) {
checkNotBuilt();
requestId(other.getRequestId());
lockDescriptors(other.getLockDescriptors());
acquireTimeoutMs(other.getAcquireTimeoutMs());
clientDescription(other.getClientDescription());
metadata(other.getMetadata());
return this;
}
@JsonSetter("requestId")
public Builder requestId(@Nonnull @Safe UUID requestId) {
checkNotBuilt();
this.requestId = Preconditions.checkNotNull(requestId, "requestId cannot be null");
return this;
}
@JsonSetter(value = "lockDescriptors", nulls = Nulls.SKIP)
public Builder lockDescriptors(@Nonnull Iterable lockDescriptors) {
checkNotBuilt();
this.lockDescriptors = ConjureCollections.newArrayList(
Preconditions.checkNotNull(lockDescriptors, "lockDescriptors cannot be null"));
return this;
}
public Builder addAllLockDescriptors(@Nonnull Iterable lockDescriptors) {
checkNotBuilt();
ConjureCollections.addAll(
this.lockDescriptors,
Preconditions.checkNotNull(lockDescriptors, "lockDescriptors cannot be null"));
return this;
}
public Builder lockDescriptors(ConjureLockDescriptor lockDescriptors) {
checkNotBuilt();
this.lockDescriptors.add(lockDescriptors);
return this;
}
@JsonSetter("acquireTimeoutMs")
public Builder acquireTimeoutMs(@Safe int acquireTimeoutMs) {
checkNotBuilt();
this.acquireTimeoutMs = acquireTimeoutMs;
this._acquireTimeoutMsInitialized = true;
return this;
}
@JsonSetter(value = "clientDescription", nulls = Nulls.SKIP)
public Builder clientDescription(@Nonnull Optional<@Unsafe String> clientDescription) {
checkNotBuilt();
this.clientDescription = Preconditions.checkNotNull(clientDescription, "clientDescription cannot be null");
return this;
}
public Builder clientDescription(@Nonnull @Unsafe String clientDescription) {
checkNotBuilt();
this.clientDescription =
Optional.of(Preconditions.checkNotNull(clientDescription, "clientDescription cannot be null"));
return this;
}
@JsonSetter(value = "metadata", nulls = Nulls.SKIP)
public Builder metadata(@Nonnull Optional metadata) {
checkNotBuilt();
this.metadata = Preconditions.checkNotNull(metadata, "metadata cannot be null");
return this;
}
public Builder metadata(@Nonnull ConjureLockRequestMetadata metadata) {
checkNotBuilt();
this.metadata = Optional.of(Preconditions.checkNotNull(metadata, "metadata cannot be null"));
return this;
}
private void validatePrimitiveFieldsHaveBeenInitialized() {
List missingFields = null;
missingFields = addFieldIfMissing(missingFields, _acquireTimeoutMsInitialized, "acquireTimeoutMs");
if (missingFields != null) {
throw new SafeIllegalArgumentException(
"Some required fields have not been set", SafeArg.of("missingFields", missingFields));
}
}
private static List addFieldIfMissing(List prev, boolean initialized, String fieldName) {
List missingFields = prev;
if (!initialized) {
if (missingFields == null) {
missingFields = new ArrayList<>(1);
}
missingFields.add(fieldName);
}
return missingFields;
}
public ConjureLockRequest build() {
checkNotBuilt();
this._buildInvoked = true;
validatePrimitiveFieldsHaveBeenInitialized();
return new ConjureLockRequest(requestId, lockDescriptors, acquireTimeoutMs, clientDescription, metadata);
}
private void checkNotBuilt() {
Preconditions.checkState(!_buildInvoked, "Build has already been called");
}
}
}