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