com.palantir.atlasdb.timelock.api.ConjureStartTransactionsRequest 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.google.errorprone.annotations.CheckReturnValue;
import com.palantir.logsafe.Preconditions;
import com.palantir.logsafe.Safe;
import com.palantir.logsafe.SafeArg;
import com.palantir.logsafe.exceptions.SafeIllegalArgumentException;
import java.util.ArrayList;
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;
@JsonDeserialize(builder = ConjureStartTransactionsRequest.Builder.class)
@Generated("com.palantir.conjure.java.types.BeanGenerator")
public final class ConjureStartTransactionsRequest {
private final UUID requestId;
private final UUID requestorId;
private final int numTransactions;
private final Optional lastKnownVersion;
private int memoizedHashCode;
private ConjureStartTransactionsRequest(
UUID requestId,
UUID requestorId,
int numTransactions,
Optional lastKnownVersion) {
validateFields(requestId, requestorId, lastKnownVersion);
this.requestId = requestId;
this.requestorId = requestorId;
this.numTransactions = numTransactions;
this.lastKnownVersion = lastKnownVersion;
}
@JsonProperty("requestId")
@Safe
public UUID getRequestId() {
return this.requestId;
}
@JsonProperty("requestorId")
@Safe
public UUID getRequestorId() {
return this.requestorId;
}
@JsonProperty("numTransactions")
@Safe
public int getNumTransactions() {
return this.numTransactions;
}
@JsonProperty("lastKnownVersion")
@JsonInclude(JsonInclude.Include.NON_ABSENT)
public Optional getLastKnownVersion() {
return this.lastKnownVersion;
}
@Override
public boolean equals(@Nullable Object other) {
return this == other
|| (other instanceof ConjureStartTransactionsRequest
&& equalTo((ConjureStartTransactionsRequest) other));
}
private boolean equalTo(ConjureStartTransactionsRequest other) {
if (this.memoizedHashCode != 0
&& other.memoizedHashCode != 0
&& this.memoizedHashCode != other.memoizedHashCode) {
return false;
}
return this.requestId.equals(other.requestId)
&& this.requestorId.equals(other.requestorId)
&& this.numTransactions == other.numTransactions
&& this.lastKnownVersion.equals(other.lastKnownVersion);
}
@Override
public int hashCode() {
int result = memoizedHashCode;
if (result == 0) {
int hash = 1;
hash = 31 * hash + this.requestId.hashCode();
hash = 31 * hash + this.requestorId.hashCode();
hash = 31 * hash + this.numTransactions;
hash = 31 * hash + this.lastKnownVersion.hashCode();
result = hash;
memoizedHashCode = result;
}
return result;
}
@Override
public String toString() {
return "ConjureStartTransactionsRequest{requestId: " + requestId + ", requestorId: " + requestorId
+ ", numTransactions: " + numTransactions + ", lastKnownVersion: " + lastKnownVersion + '}';
}
private static void validateFields(
UUID requestId, UUID requestorId, Optional lastKnownVersion) {
List missingFields = null;
missingFields = addFieldIfMissing(missingFields, requestId, "requestId");
missingFields = addFieldIfMissing(missingFields, requestorId, "requestorId");
missingFields = addFieldIfMissing(missingFields, lastKnownVersion, "lastKnownVersion");
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<>(3);
}
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 @Safe UUID requestorId;
private @Safe int numTransactions;
private Optional lastKnownVersion = Optional.empty();
private boolean _numTransactionsInitialized = false;
private Builder() {}
public Builder from(ConjureStartTransactionsRequest other) {
checkNotBuilt();
requestId(other.getRequestId());
requestorId(other.getRequestorId());
numTransactions(other.getNumTransactions());
lastKnownVersion(other.getLastKnownVersion());
return this;
}
@JsonSetter("requestId")
public Builder requestId(@Nonnull @Safe UUID requestId) {
checkNotBuilt();
this.requestId = Preconditions.checkNotNull(requestId, "requestId cannot be null");
return this;
}
@JsonSetter("requestorId")
public Builder requestorId(@Nonnull @Safe UUID requestorId) {
checkNotBuilt();
this.requestorId = Preconditions.checkNotNull(requestorId, "requestorId cannot be null");
return this;
}
@JsonSetter("numTransactions")
public Builder numTransactions(@Safe int numTransactions) {
checkNotBuilt();
this.numTransactions = numTransactions;
this._numTransactionsInitialized = true;
return this;
}
@JsonSetter(value = "lastKnownVersion", nulls = Nulls.SKIP)
public Builder lastKnownVersion(@Nonnull Optional lastKnownVersion) {
checkNotBuilt();
this.lastKnownVersion = Preconditions.checkNotNull(lastKnownVersion, "lastKnownVersion cannot be null");
return this;
}
public Builder lastKnownVersion(@Nonnull ConjureIdentifiedVersion lastKnownVersion) {
checkNotBuilt();
this.lastKnownVersion =
Optional.of(Preconditions.checkNotNull(lastKnownVersion, "lastKnownVersion cannot be null"));
return this;
}
private void validatePrimitiveFieldsHaveBeenInitialized() {
List missingFields = null;
missingFields = addFieldIfMissing(missingFields, _numTransactionsInitialized, "numTransactions");
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;
}
@CheckReturnValue
public ConjureStartTransactionsRequest build() {
checkNotBuilt();
this._buildInvoked = true;
validatePrimitiveFieldsHaveBeenInitialized();
return new ConjureStartTransactionsRequest(requestId, requestorId, numTransactions, lastKnownVersion);
}
private void checkNotBuilt() {
Preconditions.checkState(!_buildInvoked, "Build has already been called");
}
}
}