com.palantir.atlasdb.timelock.api.ConjureLockDescriptorListChecksum 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.conjure.java.lib.Bytes;
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.List;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import javax.annotation.processing.Generated;
@Unsafe
@JsonDeserialize(builder = ConjureLockDescriptorListChecksum.Builder.class)
@Generated("com.palantir.conjure.java.types.BeanGenerator")
public final class ConjureLockDescriptorListChecksum {
private final int typeId;
private final Bytes value;
private int memoizedHashCode;
private ConjureLockDescriptorListChecksum(int typeId, Bytes value) {
validateFields(value);
this.typeId = typeId;
this.value = value;
}
@JsonProperty("typeId")
@Safe
public int getTypeId() {
return this.typeId;
}
@JsonProperty("value")
@Unsafe
public Bytes getValue() {
return this.value;
}
@Override
public boolean equals(@Nullable Object other) {
return this == other
|| (other instanceof ConjureLockDescriptorListChecksum
&& equalTo((ConjureLockDescriptorListChecksum) other));
}
private boolean equalTo(ConjureLockDescriptorListChecksum other) {
if (this.memoizedHashCode != 0
&& other.memoizedHashCode != 0
&& this.memoizedHashCode != other.memoizedHashCode) {
return false;
}
return this.typeId == other.typeId && this.value.equals(other.value);
}
@Override
public int hashCode() {
int result = memoizedHashCode;
if (result == 0) {
int hash = 1;
hash = 31 * hash + this.typeId;
hash = 31 * hash + this.value.hashCode();
result = hash;
memoizedHashCode = result;
}
return result;
}
@Override
@Unsafe
public String toString() {
return "ConjureLockDescriptorListChecksum{typeId: " + typeId + ", value: " + value + '}';
}
public static ConjureLockDescriptorListChecksum of(@Safe int typeId, @Unsafe Bytes value) {
return builder().typeId(typeId).value(value).build();
}
private static void validateFields(Bytes value) {
List missingFields = null;
missingFields = addFieldIfMissing(missingFields, value, "value");
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 int typeId;
private @Unsafe Bytes value;
private boolean _typeIdInitialized = false;
private Builder() {}
public Builder from(ConjureLockDescriptorListChecksum other) {
checkNotBuilt();
typeId(other.getTypeId());
value(other.getValue());
return this;
}
@JsonSetter("typeId")
public Builder typeId(@Safe int typeId) {
checkNotBuilt();
this.typeId = typeId;
this._typeIdInitialized = true;
return this;
}
@JsonSetter("value")
public Builder value(@Nonnull @Unsafe Bytes value) {
checkNotBuilt();
this.value = Preconditions.checkNotNull(value, "value cannot be null");
return this;
}
private void validatePrimitiveFieldsHaveBeenInitialized() {
List missingFields = null;
missingFields = addFieldIfMissing(missingFields, _typeIdInitialized, "typeId");
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 ConjureLockDescriptorListChecksum build() {
checkNotBuilt();
this._buildInvoked = true;
validatePrimitiveFieldsHaveBeenInitialized();
return new ConjureLockDescriptorListChecksum(typeId, value);
}
private void checkNotBuilt() {
Preconditions.checkState(!_buildInvoked, "Build has already been called");
}
}
}