com.palantir.atlasdb.timelock.api.ConjureIdentifiedVersion 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.JsonProperty;
import com.fasterxml.jackson.annotation.JsonSetter;
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.UUID;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import javax.annotation.processing.Generated;
/** version
is always an inclusive number. If the event log is empty, -1
is returned. */
@JsonDeserialize(builder = ConjureIdentifiedVersion.Builder.class)
@Generated("com.palantir.conjure.java.types.BeanGenerator")
public final class ConjureIdentifiedVersion {
private final UUID id;
private final long version;
private int memoizedHashCode;
private ConjureIdentifiedVersion(UUID id, long version) {
validateFields(id);
this.id = id;
this.version = version;
}
@JsonProperty("id")
@Safe
public UUID getId() {
return this.id;
}
@JsonProperty("version")
public long getVersion() {
return this.version;
}
@Override
public boolean equals(@Nullable Object other) {
return this == other
|| (other instanceof ConjureIdentifiedVersion && equalTo((ConjureIdentifiedVersion) other));
}
private boolean equalTo(ConjureIdentifiedVersion other) {
if (this.memoizedHashCode != 0
&& other.memoizedHashCode != 0
&& this.memoizedHashCode != other.memoizedHashCode) {
return false;
}
return this.id.equals(other.id) && this.version == other.version;
}
@Override
public int hashCode() {
int result = memoizedHashCode;
if (result == 0) {
int hash = 1;
hash = 31 * hash + this.id.hashCode();
hash = 31 * hash + Long.hashCode(this.version);
result = hash;
memoizedHashCode = result;
}
return result;
}
@Override
public String toString() {
return "ConjureIdentifiedVersion{id: " + id + ", version: " + version + '}';
}
public static ConjureIdentifiedVersion of(@Safe UUID id, long version) {
return builder().id(id).version(version).build();
}
private static void validateFields(UUID id) {
List missingFields = null;
missingFields = addFieldIfMissing(missingFields, id, "id");
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<>(1);
}
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 id;
private long version;
private boolean _versionInitialized = false;
private Builder() {}
public Builder from(ConjureIdentifiedVersion other) {
checkNotBuilt();
id(other.getId());
version(other.getVersion());
return this;
}
@JsonSetter("id")
public Builder id(@Nonnull @Safe UUID id) {
checkNotBuilt();
this.id = Preconditions.checkNotNull(id, "id cannot be null");
return this;
}
@JsonSetter("version")
public Builder version(long version) {
checkNotBuilt();
this.version = version;
this._versionInitialized = true;
return this;
}
private void validatePrimitiveFieldsHaveBeenInitialized() {
List missingFields = null;
missingFields = addFieldIfMissing(missingFields, _versionInitialized, "version");
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 ConjureIdentifiedVersion build() {
checkNotBuilt();
this._buildInvoked = true;
validatePrimitiveFieldsHaveBeenInitialized();
return new ConjureIdentifiedVersion(id, version);
}
private void checkNotBuilt() {
Preconditions.checkState(!_buildInvoked, "Build has already been called");
}
}
}