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

com.palantir.atlasdb.timelock.api.GetCommitTimestampsRequest Maven / Gradle / Ivy

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

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 javax.annotation.Nonnull;
import javax.annotation.Nullable;
import javax.annotation.processing.Generated;

@JsonDeserialize(builder = GetCommitTimestampsRequest.Builder.class)
@Generated("com.palantir.conjure.java.types.BeanGenerator")
public final class GetCommitTimestampsRequest {
    private final int numTimestamps;

    private final Optional lastKnownVersion;

    private int memoizedHashCode;

    private GetCommitTimestampsRequest(int numTimestamps, Optional lastKnownVersion) {
        validateFields(lastKnownVersion);
        this.numTimestamps = numTimestamps;
        this.lastKnownVersion = lastKnownVersion;
    }

    @JsonProperty("numTimestamps")
    @Safe
    public int getNumTimestamps() {
        return this.numTimestamps;
    }

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

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

    private boolean equalTo(GetCommitTimestampsRequest other) {
        if (this.memoizedHashCode != 0
                && other.memoizedHashCode != 0
                && this.memoizedHashCode != other.memoizedHashCode) {
            return false;
        }
        return this.numTimestamps == other.numTimestamps && this.lastKnownVersion.equals(other.lastKnownVersion);
    }

    @Override
    public int hashCode() {
        int result = memoizedHashCode;
        if (result == 0) {
            int hash = 1;
            hash = 31 * hash + this.numTimestamps;
            hash = 31 * hash + this.lastKnownVersion.hashCode();
            result = hash;
            memoizedHashCode = result;
        }
        return result;
    }

    @Override
    public String toString() {
        return "GetCommitTimestampsRequest{numTimestamps: " + numTimestamps + ", lastKnownVersion: " + lastKnownVersion
                + '}';
    }

    public static GetCommitTimestampsRequest of(@Safe int numTimestamps, ConjureIdentifiedVersion lastKnownVersion) {
        return builder()
                .numTimestamps(numTimestamps)
                .lastKnownVersion(Optional.of(lastKnownVersion))
                .build();
    }

    private static void validateFields(Optional lastKnownVersion) {
        List missingFields = null;
        missingFields = addFieldIfMissing(missingFields, lastKnownVersion, "lastKnownVersion");
        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 numTimestamps;

        private Optional lastKnownVersion = Optional.empty();

        private boolean _numTimestampsInitialized = false;

        private Builder() {}

        public Builder from(GetCommitTimestampsRequest other) {
            checkNotBuilt();
            numTimestamps(other.getNumTimestamps());
            lastKnownVersion(other.getLastKnownVersion());
            return this;
        }

        @JsonSetter("numTimestamps")
        public Builder numTimestamps(@Safe int numTimestamps) {
            checkNotBuilt();
            this.numTimestamps = numTimestamps;
            this._numTimestampsInitialized = true;
            return this;
        }

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

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

        private void validatePrimitiveFieldsHaveBeenInitialized() {
            List missingFields = null;
            missingFields = addFieldIfMissing(missingFields, _numTimestampsInitialized, "numTimestamps");
            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 GetCommitTimestampsRequest build() {
            checkNotBuilt();
            this._buildInvoked = true;
            validatePrimitiveFieldsHaveBeenInitialized();
            return new GetCommitTimestampsRequest(numTimestamps, lastKnownVersion);
        }

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




© 2015 - 2024 Weber Informatics LLC | Privacy Policy