All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.palantir.timelock.feedback.ConjureTimeLockClientFeedback Maven / Gradle / Ivy

There is a newer version: 0.1152.0
Show newest version
package com.palantir.timelock.feedback;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;
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.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.Optional;
import java.util.UUID;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import javax.annotation.processing.Generated;

@Safe
@JsonDeserialize(builder = ConjureTimeLockClientFeedback.Builder.class)
@Generated("com.palantir.conjure.java.types.BeanGenerator")
public final class ConjureTimeLockClientFeedback {
    private final String atlasVersion;

    private final String serviceName;

    private final UUID nodeId;

    private final Optional startTransaction;

    private final Optional leaderTime;

    private final Optional namespace;

    private int memoizedHashCode;

    private ConjureTimeLockClientFeedback(
            String atlasVersion,
            String serviceName,
            UUID nodeId,
            Optional startTransaction,
            Optional leaderTime,
            Optional namespace) {
        validateFields(atlasVersion, serviceName, nodeId, startTransaction, leaderTime, namespace);
        this.atlasVersion = atlasVersion;
        this.serviceName = serviceName;
        this.nodeId = nodeId;
        this.startTransaction = startTransaction;
        this.leaderTime = leaderTime;
        this.namespace = namespace;
    }

    @JsonProperty("atlasVersion")
    @Safe
    public String getAtlasVersion() {
        return this.atlasVersion;
    }

    @JsonProperty("serviceName")
    @Safe
    public String getServiceName() {
        return this.serviceName;
    }

    @JsonProperty("nodeId")
    @Safe
    public UUID getNodeId() {
        return this.nodeId;
    }

    @JsonProperty("startTransaction")
    @JsonInclude(JsonInclude.Include.NON_ABSENT)
    public Optional getStartTransaction() {
        return this.startTransaction;
    }

    @JsonProperty("leaderTime")
    @JsonInclude(JsonInclude.Include.NON_ABSENT)
    public Optional getLeaderTime() {
        return this.leaderTime;
    }

    /** The namespace the client uses to make timestamp/lock requests */
    @JsonProperty("namespace")
    @Safe
    @JsonInclude(JsonInclude.Include.NON_ABSENT)
    public Optional getNamespace() {
        return this.namespace;
    }

    @Override
    public boolean equals(@Nullable Object other) {
        return this == other
                || (other instanceof ConjureTimeLockClientFeedback && equalTo((ConjureTimeLockClientFeedback) other));
    }

    private boolean equalTo(ConjureTimeLockClientFeedback other) {
        if (this.memoizedHashCode != 0
                && other.memoizedHashCode != 0
                && this.memoizedHashCode != other.memoizedHashCode) {
            return false;
        }
        return this.atlasVersion.equals(other.atlasVersion)
                && this.serviceName.equals(other.serviceName)
                && this.nodeId.equals(other.nodeId)
                && this.startTransaction.equals(other.startTransaction)
                && this.leaderTime.equals(other.leaderTime)
                && this.namespace.equals(other.namespace);
    }

    @Override
    public int hashCode() {
        int result = memoizedHashCode;
        if (result == 0) {
            int hash = 1;
            hash = 31 * hash + this.atlasVersion.hashCode();
            hash = 31 * hash + this.serviceName.hashCode();
            hash = 31 * hash + this.nodeId.hashCode();
            hash = 31 * hash + this.startTransaction.hashCode();
            hash = 31 * hash + this.leaderTime.hashCode();
            hash = 31 * hash + this.namespace.hashCode();
            result = hash;
            memoizedHashCode = result;
        }
        return result;
    }

    @Override
    @Safe
    public String toString() {
        return "ConjureTimeLockClientFeedback{atlasVersion: " + atlasVersion + ", serviceName: " + serviceName
                + ", nodeId: " + nodeId + ", startTransaction: " + startTransaction + ", leaderTime: " + leaderTime
                + ", namespace: " + namespace + '}';
    }

    private static void validateFields(
            String atlasVersion,
            String serviceName,
            UUID nodeId,
            Optional startTransaction,
            Optional leaderTime,
            Optional namespace) {
        List missingFields = null;
        missingFields = addFieldIfMissing(missingFields, atlasVersion, "atlasVersion");
        missingFields = addFieldIfMissing(missingFields, serviceName, "serviceName");
        missingFields = addFieldIfMissing(missingFields, nodeId, "nodeId");
        missingFields = addFieldIfMissing(missingFields, startTransaction, "startTransaction");
        missingFields = addFieldIfMissing(missingFields, leaderTime, "leaderTime");
        missingFields = addFieldIfMissing(missingFields, namespace, "namespace");
        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<>(6);
            }
            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 String atlasVersion;

        private @Safe String serviceName;

        private @Safe UUID nodeId;

        private Optional startTransaction = Optional.empty();

        private Optional leaderTime = Optional.empty();

        private Optional<@Safe String> namespace = Optional.empty();

        private Builder() {}

        public Builder from(ConjureTimeLockClientFeedback other) {
            checkNotBuilt();
            atlasVersion(other.getAtlasVersion());
            serviceName(other.getServiceName());
            nodeId(other.getNodeId());
            startTransaction(other.getStartTransaction());
            leaderTime(other.getLeaderTime());
            namespace(other.getNamespace());
            return this;
        }

        @JsonSetter("atlasVersion")
        public Builder atlasVersion(@Nonnull @Safe String atlasVersion) {
            checkNotBuilt();
            this.atlasVersion = Preconditions.checkNotNull(atlasVersion, "atlasVersion cannot be null");
            return this;
        }

        @JsonSetter("serviceName")
        public Builder serviceName(@Nonnull @Safe String serviceName) {
            checkNotBuilt();
            this.serviceName = Preconditions.checkNotNull(serviceName, "serviceName cannot be null");
            return this;
        }

        @JsonSetter("nodeId")
        public Builder nodeId(@Nonnull @Safe UUID nodeId) {
            checkNotBuilt();
            this.nodeId = Preconditions.checkNotNull(nodeId, "nodeId cannot be null");
            return this;
        }

        @JsonSetter(value = "startTransaction", nulls = Nulls.SKIP)
        public Builder startTransaction(@Nonnull Optional startTransaction) {
            checkNotBuilt();
            this.startTransaction = Preconditions.checkNotNull(startTransaction, "startTransaction cannot be null");
            return this;
        }

        public Builder startTransaction(@Nonnull EndpointStatistics startTransaction) {
            checkNotBuilt();
            this.startTransaction =
                    Optional.of(Preconditions.checkNotNull(startTransaction, "startTransaction cannot be null"));
            return this;
        }

        @JsonSetter(value = "leaderTime", nulls = Nulls.SKIP)
        public Builder leaderTime(@Nonnull Optional leaderTime) {
            checkNotBuilt();
            this.leaderTime = Preconditions.checkNotNull(leaderTime, "leaderTime cannot be null");
            return this;
        }

        public Builder leaderTime(@Nonnull EndpointStatistics leaderTime) {
            checkNotBuilt();
            this.leaderTime = Optional.of(Preconditions.checkNotNull(leaderTime, "leaderTime cannot be null"));
            return this;
        }

        /** The namespace the client uses to make timestamp/lock requests */
        @JsonSetter(value = "namespace", nulls = Nulls.SKIP)
        public Builder namespace(@Nonnull Optional<@Safe String> namespace) {
            checkNotBuilt();
            this.namespace = Preconditions.checkNotNull(namespace, "namespace cannot be null");
            return this;
        }

        /** The namespace the client uses to make timestamp/lock requests */
        public Builder namespace(@Nonnull @Safe String namespace) {
            checkNotBuilt();
            this.namespace = Optional.of(Preconditions.checkNotNull(namespace, "namespace cannot be null"));
            return this;
        }

        @CheckReturnValue
        public ConjureTimeLockClientFeedback build() {
            checkNotBuilt();
            this._buildInvoked = true;
            return new ConjureTimeLockClientFeedback(
                    atlasVersion, serviceName, nodeId, startTransaction, leaderTime, namespace);
        }

        private void checkNotBuilt() {
            Preconditions.checkState(!_buildInvoked, "Build has already been called");
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy