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

com.palantir.timelock.feedback.EndpointStatistics 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.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.OptionalDouble;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import javax.annotation.processing.Generated;

@Safe
@JsonDeserialize(builder = EndpointStatistics.Builder.class)
@Generated("com.palantir.conjure.java.types.BeanGenerator")
public final class EndpointStatistics {
    private final double p99;

    private final double oneMin;

    private final OptionalDouble errorRate;

    private int memoizedHashCode;

    private EndpointStatistics(double p99, double oneMin, OptionalDouble errorRate) {
        validateFields(errorRate);
        this.p99 = p99;
        this.oneMin = oneMin;
        this.errorRate = errorRate;
    }

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

    @JsonProperty("oneMin")
    @Safe
    public double getOneMin() {
        return this.oneMin;
    }

    @JsonProperty("errorRate")
    @Safe
    @JsonInclude(JsonInclude.Include.NON_ABSENT)
    public OptionalDouble getErrorRate() {
        return this.errorRate;
    }

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

    private boolean equalTo(EndpointStatistics 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.oneMin) == Double.doubleToLongBits(other.oneMin)
                && this.errorRate.equals(other.errorRate);
    }

    @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.oneMin);
            hash = 31 * hash + this.errorRate.hashCode();
            result = hash;
            memoizedHashCode = result;
        }
        return result;
    }

    @Override
    @Safe
    public String toString() {
        return "EndpointStatistics{p99: " + p99 + ", oneMin: " + oneMin + ", errorRate: " + errorRate + '}';
    }

    public static EndpointStatistics of(@Safe double p99, @Safe double oneMin, @Safe OptionalDouble errorRate) {
        return builder().p99(p99).oneMin(oneMin).errorRate(errorRate).build();
    }

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

        private @Safe double oneMin;

        private @Safe OptionalDouble errorRate = OptionalDouble.empty();

        private boolean _p99Initialized = false;

        private boolean _oneMinInitialized = false;

        private Builder() {}

        public Builder from(EndpointStatistics other) {
            checkNotBuilt();
            p99(other.getP99());
            oneMin(other.getOneMin());
            errorRate(other.getErrorRate());
            return this;
        }

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

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

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

        public Builder errorRate(@Safe double errorRate) {
            checkNotBuilt();
            this.errorRate = OptionalDouble.of(errorRate);
            return this;
        }

        private void validatePrimitiveFieldsHaveBeenInitialized() {
            List missingFields = null;
            missingFields = addFieldIfMissing(missingFields, _p99Initialized, "p99");
            missingFields = addFieldIfMissing(missingFields, _oneMinInitialized, "oneMin");
            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 EndpointStatistics build() {
            checkNotBuilt();
            this._buildInvoked = true;
            validatePrimitiveFieldsHaveBeenInitialized();
            return new EndpointStatistics(p99, oneMin, errorRate);
        }

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




© 2015 - 2024 Weber Informatics LLC | Privacy Policy