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

com.palantir.atlasdb.timelock.api.ConjureRefreshLocksResponseV2 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.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.v2.Lease;
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 = ConjureRefreshLocksResponseV2.Builder.class)
@Generated("com.palantir.conjure.java.types.BeanGenerator")
public final class ConjureRefreshLocksResponseV2 {
    private final Set refreshedTokens;

    private final Lease lease;

    private int memoizedHashCode;

    private ConjureRefreshLocksResponseV2(Set refreshedTokens, Lease lease) {
        validateFields(refreshedTokens, lease);
        this.refreshedTokens = Collections.unmodifiableSet(refreshedTokens);
        this.lease = lease;
    }

    @JsonProperty("refreshedTokens")
    public Set getRefreshedTokens() {
        return this.refreshedTokens;
    }

    @JsonProperty("lease")
    public Lease getLease() {
        return this.lease;
    }

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

    private boolean equalTo(ConjureRefreshLocksResponseV2 other) {
        if (this.memoizedHashCode != 0
                && other.memoizedHashCode != 0
                && this.memoizedHashCode != other.memoizedHashCode) {
            return false;
        }
        return this.refreshedTokens.equals(other.refreshedTokens) && this.lease.equals(other.lease);
    }

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

    @Override
    public String toString() {
        return "ConjureRefreshLocksResponseV2{refreshedTokens: " + refreshedTokens + ", lease: " + lease + '}';
    }

    public static ConjureRefreshLocksResponseV2 of(Set refreshedTokens, Lease lease) {
        return builder().refreshedTokens(refreshedTokens).lease(lease).build();
    }

    private static void validateFields(Set refreshedTokens, Lease lease) {
        List missingFields = null;
        missingFields = addFieldIfMissing(missingFields, refreshedTokens, "refreshedTokens");
        missingFields = addFieldIfMissing(missingFields, lease, "lease");
        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 Set refreshedTokens = ConjureCollections.newSet();

        private Lease lease;

        private Builder() {}

        public Builder from(ConjureRefreshLocksResponseV2 other) {
            checkNotBuilt();
            refreshedTokens(other.getRefreshedTokens());
            lease(other.getLease());
            return this;
        }

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

        public Builder addAllRefreshedTokens(@Nonnull Iterable refreshedTokens) {
            checkNotBuilt();
            ConjureCollections.addAll(
                    this.refreshedTokens,
                    Preconditions.checkNotNull(refreshedTokens, "refreshedTokens cannot be null"));
            return this;
        }

        public Builder refreshedTokens(ConjureLockTokenV2 refreshedTokens) {
            checkNotBuilt();
            this.refreshedTokens.add(refreshedTokens);
            return this;
        }

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

        @CheckReturnValue
        public ConjureRefreshLocksResponseV2 build() {
            checkNotBuilt();
            this._buildInvoked = true;
            return new ConjureRefreshLocksResponseV2(refreshedTokens, lease);
        }

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




© 2015 - 2024 Weber Informatics LLC | Privacy Policy