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

com.palantir.atlasdb.timelock.api.GetCommitTimestampResponse 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 = GetCommitTimestampResponse.Builder.class)
@Generated("com.palantir.conjure.java.types.BeanGenerator")
public final class GetCommitTimestampResponse {
    private final long timestamp;

    private final LockWatchStateUpdate lockWatchUpdate;

    private int memoizedHashCode;

    private GetCommitTimestampResponse(long timestamp, LockWatchStateUpdate lockWatchUpdate) {
        validateFields(lockWatchUpdate);
        this.timestamp = timestamp;
        this.lockWatchUpdate = lockWatchUpdate;
    }

    @JsonProperty("timestamp")
    public long getTimestamp() {
        return this.timestamp;
    }

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

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

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

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

    @Override
    public String toString() {
        return "GetCommitTimestampResponse{timestamp: " + timestamp + ", lockWatchUpdate: " + lockWatchUpdate + '}';
    }

    public static GetCommitTimestampResponse of(long timestamp, LockWatchStateUpdate lockWatchUpdate) {
        return builder().timestamp(timestamp).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 timestamp;

        private LockWatchStateUpdate lockWatchUpdate;

        private boolean _timestampInitialized = false;

        private Builder() {}

        public Builder from(GetCommitTimestampResponse other) {
            checkNotBuilt();
            timestamp(other.getTimestamp());
            lockWatchUpdate(other.getLockWatchUpdate());
            return this;
        }

        @JsonSetter("timestamp")
        public Builder timestamp(long timestamp) {
            checkNotBuilt();
            this.timestamp = timestamp;
            this._timestampInitialized = 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, _timestampInitialized, "timestamp");
            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 GetCommitTimestampResponse build() {
            checkNotBuilt();
            this._buildInvoked = true;
            validatePrimitiveFieldsHaveBeenInitialized();
            return new GetCommitTimestampResponse(timestamp, lockWatchUpdate);
        }

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




© 2015 - 2024 Weber Informatics LLC | Privacy Policy