com.palantir.atlasdb.timelock.api.LockWatchRequest 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.annotation.Nulls;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.google.errorprone.annotations.CheckReturnValue;
import com.palantir.conjure.java.lib.internal.ConjureCollections;
import com.palantir.lock.watch.LockWatchReferences.LockWatchReference;
import com.palantir.logsafe.Preconditions;
import com.palantir.logsafe.SafeArg;
import com.palantir.logsafe.exceptions.SafeIllegalArgumentException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Set;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import javax.annotation.processing.Generated;
@JsonDeserialize(builder = LockWatchRequest.Builder.class)
@Generated("com.palantir.conjure.java.types.BeanGenerator")
public final class LockWatchRequest {
private final Set references;
private int memoizedHashCode;
private LockWatchRequest(Set references) {
validateFields(references);
this.references = Collections.unmodifiableSet(references);
}
@JsonProperty("references")
public Set getReferences() {
return this.references;
}
@Override
public boolean equals(@Nullable Object other) {
return this == other || (other instanceof LockWatchRequest && equalTo((LockWatchRequest) other));
}
private boolean equalTo(LockWatchRequest other) {
if (this.memoizedHashCode != 0
&& other.memoizedHashCode != 0
&& this.memoizedHashCode != other.memoizedHashCode) {
return false;
}
return this.references.equals(other.references);
}
@Override
public int hashCode() {
int result = memoizedHashCode;
if (result == 0) {
result = this.references.hashCode();
memoizedHashCode = result;
}
return result;
}
@Override
public String toString() {
return "LockWatchRequest{references: " + references + '}';
}
public static LockWatchRequest of(Set references) {
return builder().references(references).build();
}
private static void validateFields(Set references) {
List missingFields = null;
missingFields = addFieldIfMissing(missingFields, references, "references");
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 Set references = ConjureCollections.newSet();
private Builder() {}
public Builder from(LockWatchRequest other) {
checkNotBuilt();
references(other.getReferences());
return this;
}
@JsonSetter(value = "references", nulls = Nulls.SKIP)
public Builder references(@Nonnull Iterable extends LockWatchReference> references) {
checkNotBuilt();
this.references =
ConjureCollections.newSet(Preconditions.checkNotNull(references, "references cannot be null"));
return this;
}
public Builder addAllReferences(@Nonnull Iterable extends LockWatchReference> references) {
checkNotBuilt();
ConjureCollections.addAll(
this.references, Preconditions.checkNotNull(references, "references cannot be null"));
return this;
}
public Builder references(LockWatchReference references) {
checkNotBuilt();
this.references.add(references);
return this;
}
@CheckReturnValue
public LockWatchRequest build() {
checkNotBuilt();
this._buildInvoked = true;
return new LockWatchRequest(references);
}
private void checkNotBuilt() {
Preconditions.checkState(!_buildInvoked, "Build has already been called");
}
}
}