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

com.palantir.timelock.feedback.LeaderElectionStatistics Maven / Gradle / Ivy

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

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.conjure.java.lib.SafeLong;
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 = LeaderElectionStatistics.Builder.class)
@Generated("com.palantir.conjure.java.types.BeanGenerator")
public final class LeaderElectionStatistics {
    private final double p99;

    private final double p95;

    private final double mean;

    private final SafeLong count;

    private final Optional durationEstimate;

    private int memoizedHashCode;

    private LeaderElectionStatistics(
            double p99, double p95, double mean, SafeLong count, Optional durationEstimate) {
        validateFields(count, durationEstimate);
        this.p99 = p99;
        this.p95 = p95;
        this.mean = mean;
        this.count = count;
        this.durationEstimate = durationEstimate;
    }

    @JsonProperty("p99")
    @Safe
    public double getP99() {
        return this.p99;
    }

    @JsonProperty("p95")
    @Safe
    public double getP95() {
        return this.p95;
    }

    @JsonProperty("mean")
    @Safe
    public double getMean() {
        return this.mean;
    }

    @JsonProperty("count")
    @Safe
    public SafeLong getCount() {
        return this.count;
    }

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

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

    private boolean equalTo(LeaderElectionStatistics other) {
        if (this.memoizedHashCode != 0
                && other.memoizedHashCode != 0
                && this.memoizedHashCode != other.memoizedHashCode) {
            return false;
        }
        return Double.doubleToLongBits(this.p99) == Double.doubleToLongBits(other.p99)
                && Double.doubleToLongBits(this.p95) == Double.doubleToLongBits(other.p95)
                && Double.doubleToLongBits(this.mean) == Double.doubleToLongBits(other.mean)
                && this.count.equals(other.count)
                && this.durationEstimate.equals(other.durationEstimate);
    }

    @Override
    public int hashCode() {
        int result = memoizedHashCode;
        if (result == 0) {
            int hash = 1;
            hash = 31 * hash + Double.hashCode(this.p99);
            hash = 31 * hash + Double.hashCode(this.p95);
            hash = 31 * hash + Double.hashCode(this.mean);
            hash = 31 * hash + this.count.hashCode();
            hash = 31 * hash + this.durationEstimate.hashCode();
            result = hash;
            memoizedHashCode = result;
        }
        return result;
    }

    @Override
    public String toString() {
        return "LeaderElectionStatistics{p99: " + p99 + ", p95: " + p95 + ", mean: " + mean + ", count: " + count
                + ", durationEstimate: " + durationEstimate + '}';
    }

    private static void validateFields(SafeLong count, Optional durationEstimate) {
        List missingFields = null;
        missingFields = addFieldIfMissing(missingFields, count, "count");
        missingFields = addFieldIfMissing(missingFields, durationEstimate, "durationEstimate");
        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 @Safe double p99;

        private @Safe double p95;

        private @Safe double mean;

        private @Safe SafeLong count;

        private Optional durationEstimate = Optional.empty();

        private boolean _p99Initialized = false;

        private boolean _p95Initialized = false;

        private boolean _meanInitialized = false;

        private Builder() {}

        public Builder from(LeaderElectionStatistics other) {
            checkNotBuilt();
            p99(other.getP99());
            p95(other.getP95());
            mean(other.getMean());
            count(other.getCount());
            durationEstimate(other.getDurationEstimate());
            return this;
        }

        @JsonSetter("p99")
        public Builder p99(@Safe double p99) {
            checkNotBuilt();
            this.p99 = p99;
            this._p99Initialized = true;
            return this;
        }

        @JsonSetter("p95")
        public Builder p95(@Safe double p95) {
            checkNotBuilt();
            this.p95 = p95;
            this._p95Initialized = true;
            return this;
        }

        @JsonSetter("mean")
        public Builder mean(@Safe double mean) {
            checkNotBuilt();
            this.mean = mean;
            this._meanInitialized = true;
            return this;
        }

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

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

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

        private void validatePrimitiveFieldsHaveBeenInitialized() {
            List missingFields = null;
            missingFields = addFieldIfMissing(missingFields, _p99Initialized, "p99");
            missingFields = addFieldIfMissing(missingFields, _p95Initialized, "p95");
            missingFields = addFieldIfMissing(missingFields, _meanInitialized, "mean");
            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<>(3);
                }
                missingFields.add(fieldName);
            }
            return missingFields;
        }

        @CheckReturnValue
        public LeaderElectionStatistics build() {
            checkNotBuilt();
            this._buildInvoked = true;
            validatePrimitiveFieldsHaveBeenInitialized();
            return new LeaderElectionStatistics(p99, p95, mean, count, durationEstimate);
        }

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




© 2015 - 2024 Weber Informatics LLC | Privacy Policy