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

com.palantir.atlasdb.timelock.api.ConjureUnlockResponse 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.palantir.conjure.java.lib.internal.ConjureCollections;
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.Collections;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import javax.annotation.processing.Generated;

@Safe
@JsonDeserialize(builder = ConjureUnlockResponse.Builder.class)
@Generated("com.palantir.conjure.java.types.BeanGenerator")
public final class ConjureUnlockResponse {
    private final Set tokens;

    private int memoizedHashCode;

    private ConjureUnlockResponse(Set tokens) {
        validateFields(tokens);
        this.tokens = Collections.unmodifiableSet(tokens);
    }

    @JsonProperty("tokens")
    public Set getTokens() {
        return this.tokens;
    }

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

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

    @Override
    public int hashCode() {
        int result = memoizedHashCode;
        if (result == 0) {
            result = this.tokens.hashCode();
            memoizedHashCode = result;
        }
        return result;
    }

    @Override
    @Safe
    public String toString() {
        return "ConjureUnlockResponse{tokens: " + tokens + '}';
    }

    public static ConjureUnlockResponse of(Set tokens) {
        return builder().tokens(tokens).build();
    }

    private static void validateFields(Set tokens) {
        List missingFields = null;
        missingFields = addFieldIfMissing(missingFields, tokens, "tokens");
        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 tokens = new LinkedHashSet<>();

        private Builder() {}

        public Builder from(ConjureUnlockResponse other) {
            checkNotBuilt();
            tokens(other.getTokens());
            return this;
        }

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

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

        public Builder tokens(ConjureLockToken tokens) {
            checkNotBuilt();
            this.tokens.add(tokens);
            return this;
        }

        public ConjureUnlockResponse build() {
            checkNotBuilt();
            this._buildInvoked = true;
            return new ConjureUnlockResponse(tokens);
        }

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




© 2015 - 2024 Weber Informatics LLC | Privacy Policy