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

com.palantir.atlasdb.timelock.api.GetCommitTimestampsResponse 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.databind.annotation.JsonDeserialize;
import com.google.errorprone.annotations.CheckReturnValue;
import com.palantir.lock.watch.LockWatchStateUpdate;
import com.palantir.logsafe.Preconditions;
import com.palantir.logsafe.SafeArg;
import com.palantir.logsafe.exceptions.SafeIllegalArgumentException;
import java.util.ArrayList;
import java.util.List;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import javax.annotation.processing.Generated;

@JsonDeserialize(builder = GetCommitTimestampsResponse.Builder.class)
@Generated("com.palantir.conjure.java.types.BeanGenerator")
public final class GetCommitTimestampsResponse {
    private final long inclusiveLower;

    private final long inclusiveUpper;

    private final LockWatchStateUpdate lockWatchUpdate;

    private int memoizedHashCode;

    private GetCommitTimestampsResponse(
            long inclusiveLower, long inclusiveUpper, LockWatchStateUpdate lockWatchUpdate) {
        validateFields(lockWatchUpdate);
        this.inclusiveLower = inclusiveLower;
        this.inclusiveUpper = inclusiveUpper;
        this.lockWatchUpdate = lockWatchUpdate;
    }

    @JsonProperty("inclusiveLower")
    public long getInclusiveLower() {
        return this.inclusiveLower;
    }

    @JsonProperty("inclusiveUpper")
    public long getInclusiveUpper() {
        return this.inclusiveUpper;
    }

    @JsonProperty("lockWatchUpdate")
    public LockWatchStateUpdate getLockWatchUpdate() {
        return this.lockWatchUpdate;
    }

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

    private boolean equalTo(GetCommitTimestampsResponse other) {
        if (this.memoizedHashCode != 0
                && other.memoizedHashCode != 0
                && this.memoizedHashCode != other.memoizedHashCode) {
            return false;
        }
        return this.inclusiveLower == other.inclusiveLower
                && this.inclusiveUpper == other.inclusiveUpper
                && this.lockWatchUpdate.equals(other.lockWatchUpdate);
    }

    @Override
    public int hashCode() {
        int result = memoizedHashCode;
        if (result == 0) {
            int hash = 1;
            hash = 31 * hash + Long.hashCode(this.inclusiveLower);
            hash = 31 * hash + Long.hashCode(this.inclusiveUpper);
            hash = 31 * hash + this.lockWatchUpdate.hashCode();
            result = hash;
            memoizedHashCode = result;
        }
        return result;
    }

    @Override
    public String toString() {
        return "GetCommitTimestampsResponse{inclusiveLower: " + inclusiveLower + ", inclusiveUpper: " + inclusiveUpper
                + ", lockWatchUpdate: " + lockWatchUpdate + '}';
    }

    public static GetCommitTimestampsResponse of(
            long inclusiveLower, long inclusiveUpper, LockWatchStateUpdate lockWatchUpdate) {
        return builder()
                .inclusiveLower(inclusiveLower)
                .inclusiveUpper(inclusiveUpper)
                .lockWatchUpdate(lockWatchUpdate)
                .build();
    }

    private static void validateFields(LockWatchStateUpdate lockWatchUpdate) {
        List missingFields = null;
        missingFields = addFieldIfMissing(missingFields, lockWatchUpdate, "lockWatchUpdate");
        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 long inclusiveLower;

        private long inclusiveUpper;

        private LockWatchStateUpdate lockWatchUpdate;

        private boolean _inclusiveLowerInitialized = false;

        private boolean _inclusiveUpperInitialized = false;

        private Builder() {}

        public Builder from(GetCommitTimestampsResponse other) {
            checkNotBuilt();
            inclusiveLower(other.getInclusiveLower());
            inclusiveUpper(other.getInclusiveUpper());
            lockWatchUpdate(other.getLockWatchUpdate());
            return this;
        }

        @JsonSetter("inclusiveLower")
        public Builder inclusiveLower(long inclusiveLower) {
            checkNotBuilt();
            this.inclusiveLower = inclusiveLower;
            this._inclusiveLowerInitialized = true;
            return this;
        }

        @JsonSetter("inclusiveUpper")
        public Builder inclusiveUpper(long inclusiveUpper) {
            checkNotBuilt();
            this.inclusiveUpper = inclusiveUpper;
            this._inclusiveUpperInitialized = true;
            return this;
        }

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

        private void validatePrimitiveFieldsHaveBeenInitialized() {
            List missingFields = null;
            missingFields = addFieldIfMissing(missingFields, _inclusiveLowerInitialized, "inclusiveLower");
            missingFields = addFieldIfMissing(missingFields, _inclusiveUpperInitialized, "inclusiveUpper");
            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<>(2);
                }
                missingFields.add(fieldName);
            }
            return missingFields;
        }

        @CheckReturnValue
        public GetCommitTimestampsResponse build() {
            checkNotBuilt();
            this._buildInvoked = true;
            validatePrimitiveFieldsHaveBeenInitialized();
            return new GetCommitTimestampsResponse(inclusiveLower, inclusiveUpper, lockWatchUpdate);
        }

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




© 2015 - 2024 Weber Informatics LLC | Privacy Policy