com.palantir.atlasdb.timelock.api.LeaderTimes 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.lock.v2.LeaderTime;
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.LinkedHashMap;
import java.util.List;
import java.util.Map;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import javax.annotation.processing.Generated;
@JsonDeserialize(builder = LeaderTimes.Builder.class)
@Generated("com.palantir.conjure.java.types.BeanGenerator")
public final class LeaderTimes {
private final Map leaderTimes;
private int memoizedHashCode;
private LeaderTimes(Map leaderTimes) {
validateFields(leaderTimes);
this.leaderTimes = Collections.unmodifiableMap(leaderTimes);
}
@JsonProperty("leaderTimes")
public Map getLeaderTimes() {
return this.leaderTimes;
}
@Override
public boolean equals(@Nullable Object other) {
return this == other || (other instanceof LeaderTimes && equalTo((LeaderTimes) other));
}
private boolean equalTo(LeaderTimes other) {
if (this.memoizedHashCode != 0
&& other.memoizedHashCode != 0
&& this.memoizedHashCode != other.memoizedHashCode) {
return false;
}
return this.leaderTimes.equals(other.leaderTimes);
}
@Override
public int hashCode() {
int result = memoizedHashCode;
if (result == 0) {
result = this.leaderTimes.hashCode();
memoizedHashCode = result;
}
return result;
}
@Override
public String toString() {
return "LeaderTimes{leaderTimes: " + leaderTimes + '}';
}
public static LeaderTimes of(Map leaderTimes) {
return builder().leaderTimes(leaderTimes).build();
}
private static void validateFields(Map leaderTimes) {
List missingFields = null;
missingFields = addFieldIfMissing(missingFields, leaderTimes, "leaderTimes");
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 Map leaderTimes = new LinkedHashMap<>();
private Builder() {}
public Builder from(LeaderTimes other) {
checkNotBuilt();
leaderTimes(other.getLeaderTimes());
return this;
}
@JsonSetter(value = "leaderTimes", nulls = Nulls.SKIP)
public Builder leaderTimes(@Nonnull Map leaderTimes) {
checkNotBuilt();
this.leaderTimes =
new LinkedHashMap<>(Preconditions.checkNotNull(leaderTimes, "leaderTimes cannot be null"));
return this;
}
public Builder putAllLeaderTimes(@Nonnull Map leaderTimes) {
checkNotBuilt();
this.leaderTimes.putAll(Preconditions.checkNotNull(leaderTimes, "leaderTimes cannot be null"));
return this;
}
public Builder leaderTimes(Namespace key, LeaderTime value) {
checkNotBuilt();
this.leaderTimes.put(key, value);
return this;
}
@CheckReturnValue
public LeaderTimes build() {
checkNotBuilt();
this._buildInvoked = true;
return new LeaderTimes(leaderTimes);
}
private void checkNotBuilt() {
Preconditions.checkState(!_buildInvoked, "Build has already been called");
}
}
}