
org.glowroot.storage.repo.ImmutableRollupConfig Maven / Gradle / Ivy
package org.glowroot.storage.repo;
import org.glowroot.agent.shaded.fasterxml.jackson.annotation.JsonCreator;
import org.glowroot.agent.shaded.fasterxml.jackson.annotation.JsonProperty;
import org.glowroot.agent.shaded.google.common.base.MoreObjects;
import org.glowroot.agent.shaded.google.common.base.Preconditions;
import org.glowroot.agent.shaded.google.common.collect.Lists;
import org.glowroot.agent.shaded.google.common.primitives.Longs;
import java.util.List;
import javax.annotation.Generated;
import javax.annotation.Nullable;
import javax.annotation.ParametersAreNonnullByDefault;
import javax.annotation.concurrent.Immutable;
import javax.annotation.concurrent.NotThreadSafe;
/**
* Immutable implementation of {@link ConfigRepository.RollupConfig}.
*
* Use builder to create immutable instances:
* {@code ImmutableRollupConfig.builder()}.
* Use static factory method to create immutable instances:
* {@code ImmutableRollupConfig.of()}.
*/
@SuppressWarnings("all")
@ParametersAreNonnullByDefault
@Generated({"Immutables.generator", "ConfigRepository.RollupConfig"})
@Immutable
public final class ImmutableRollupConfig extends ConfigRepository.RollupConfig {
private final long intervalMillis;
private final long viewThresholdMillis;
private ImmutableRollupConfig(long intervalMillis, long viewThresholdMillis) {
this.intervalMillis = intervalMillis;
this.viewThresholdMillis = viewThresholdMillis;
}
/**
* @return value of {@code intervalMillis} attribute
*/
@JsonProperty
@Override
public long intervalMillis() {
return intervalMillis;
}
/**
* @return value of {@code viewThresholdMillis} attribute
*/
@JsonProperty
@Override
public long viewThresholdMillis() {
return viewThresholdMillis;
}
/**
* Copy current immutable object by setting value for {@link ConfigRepository.RollupConfig#intervalMillis() intervalMillis}.
* Value equality check is used to prevent copying of the same value by returning {@code this}.
* @param value new value for intervalMillis
* @return modified copy of the {@code this} object
*/
public final ImmutableRollupConfig withIntervalMillis(long value) {
if (this.intervalMillis == value) return this;
long newValue = value;
return new ImmutableRollupConfig(newValue, this.viewThresholdMillis);
}
/**
* Copy current immutable object by setting value for {@link ConfigRepository.RollupConfig#viewThresholdMillis() viewThresholdMillis}.
* Value equality check is used to prevent copying of the same value by returning {@code this}.
* @param value new value for viewThresholdMillis
* @return modified copy of the {@code this} object
*/
public final ImmutableRollupConfig withViewThresholdMillis(long value) {
if (this.viewThresholdMillis == value) return this;
long newValue = value;
return new ImmutableRollupConfig(this.intervalMillis, newValue);
}
/**
* This instance is equal to instances of {@code ImmutableRollupConfig} with equal attribute values.
* @return {@code true} if {@code this} is equal to {@code another} instance
*/
@Override
public boolean equals(@Nullable Object another) {
if (this == another) return true;
return another instanceof ImmutableRollupConfig
&& equalTo((ImmutableRollupConfig) another);
}
private boolean equalTo(ImmutableRollupConfig another) {
return intervalMillis == another.intervalMillis
&& viewThresholdMillis == another.viewThresholdMillis;
}
/**
* Computes hash code from attributes: {@code intervalMillis}, {@code viewThresholdMillis}.
* @return hashCode value
*/
@Override
public int hashCode() {
int h = 31;
h = h * 17 + Longs.hashCode(intervalMillis);
h = h * 17 + Longs.hashCode(viewThresholdMillis);
return h;
}
/**
* Prints immutable value {@code RollupConfig...} with attribute values,
* excluding any non-generated and auxiliary attributes.
* @return string representation of value
*/
@Override
public String toString() {
return MoreObjects.toStringHelper("RollupConfig")
.add("intervalMillis", intervalMillis)
.add("viewThresholdMillis", viewThresholdMillis)
.toString();
}
/**
* Simple representation of this value type suitable Jackson binding
* @deprecated Do not use this type directly, it exists only for Jackson-binding infrastructure
*/
@Deprecated
static final class Json {
@JsonProperty
@Nullable Long intervalMillis;
@JsonProperty
@Nullable Long viewThresholdMillis;
}
/**
* @param json JSON-bindable data structure
* @return immutable value type
* @deprecated Do not use this method directly, it exists only for Jackson-binding infrastructure
*/
@Deprecated
@JsonCreator
static ImmutableRollupConfig fromJson(Json json) {
ImmutableRollupConfig.Builder builder = ImmutableRollupConfig.builder();
if (json.intervalMillis != null) {
builder.intervalMillis(json.intervalMillis);
}
if (json.viewThresholdMillis != null) {
builder.viewThresholdMillis(json.viewThresholdMillis);
}
return builder.build();
}
/**
* Construct new immutable {@code RollupConfig} instance.
* @param intervalMillis value for {@code intervalMillis}
* @param viewThresholdMillis value for {@code viewThresholdMillis}
* @return immutable RollupConfig instance
*/
public static ImmutableRollupConfig of(long intervalMillis, long viewThresholdMillis) {
return new ImmutableRollupConfig(intervalMillis, viewThresholdMillis);
}
/**
* Creates immutable copy of {@link ConfigRepository.RollupConfig}.
* Uses accessors to get values to initialize immutable instance.
* If an instance is already immutable, it is returned as is.
* @param instance instance to copy
* @return copied immutable RollupConfig instance
*/
public static ImmutableRollupConfig copyOf(ConfigRepository.RollupConfig instance) {
if (instance instanceof ImmutableRollupConfig) {
return (ImmutableRollupConfig) instance;
}
return ImmutableRollupConfig.builder()
.copyFrom(instance)
.build();
}
/**
* Creates builder for {@link org.glowroot.storage.repo.ImmutableRollupConfig ImmutableRollupConfig}.
* @return new ImmutableRollupConfig builder
*/
public static ImmutableRollupConfig.Builder builder() {
return new ImmutableRollupConfig.Builder();
}
/**
* Builds instances of {@link org.glowroot.storage.repo.ImmutableRollupConfig ImmutableRollupConfig}.
* Initialize attributes and then invoke {@link #build()} method to create
* immutable instance.
*
{@code Builder} is not thread safe and generally should not be stored in field or collection,
* but used immediately to create instances.
*/
@NotThreadSafe
public static final class Builder {
private static final long INIT_BIT_INTERVAL_MILLIS = 0x1L;
private static final long INIT_BIT_VIEW_THRESHOLD_MILLIS = 0x2L;
private long initBits = 0x3;
private long intervalMillis;
private long viewThresholdMillis;
private Builder() {}
/**
* Fill builder with attribute values from provided {@link ConfigRepository.RollupConfig} instance.
* Regular attribute values will be replaced with ones of an instance.
* Instance's absent optional values will not replace present values.
* @param instance instance to copy values from
* @return {@code this} builder for chained invocation
*/
public final Builder copyFrom(ConfigRepository.RollupConfig instance) {
Preconditions.checkNotNull(instance);
intervalMillis(instance.intervalMillis());
viewThresholdMillis(instance.viewThresholdMillis());
return this;
}
/**
* Initializes value for {@link ConfigRepository.RollupConfig#intervalMillis() intervalMillis}.
* @param intervalMillis value for intervalMillis
* @return {@code this} builder for chained invocation
*/
public final Builder intervalMillis(long intervalMillis) {
this.intervalMillis = intervalMillis;
initBits &= ~INIT_BIT_INTERVAL_MILLIS;
return this;
}
/**
* Initializes value for {@link ConfigRepository.RollupConfig#viewThresholdMillis() viewThresholdMillis}.
* @param viewThresholdMillis value for viewThresholdMillis
* @return {@code this} builder for chained invocation
*/
public final Builder viewThresholdMillis(long viewThresholdMillis) {
this.viewThresholdMillis = viewThresholdMillis;
initBits &= ~INIT_BIT_VIEW_THRESHOLD_MILLIS;
return this;
}
/**
* Builds new {@link org.glowroot.storage.repo.ImmutableRollupConfig ImmutableRollupConfig}.
* @return immutable instance of RollupConfig
* @throws exception {@code java.lang.IllegalStateException} if any required attributes are missing
*/
public ImmutableRollupConfig build()
throws IllegalStateException {
checkRequiredAttributes();
return new ImmutableRollupConfig(intervalMillis, viewThresholdMillis);
}
private boolean intervalMillisIsSet() {
return (initBits & INIT_BIT_INTERVAL_MILLIS) == 0;
}
private boolean viewThresholdMillisIsSet() {
return (initBits & INIT_BIT_VIEW_THRESHOLD_MILLIS) == 0;
}
private void checkRequiredAttributes() throws IllegalStateException {
if (initBits != 0) {
throw new IllegalStateException(formatRequiredAttributesMessage());
}
}
private String formatRequiredAttributesMessage() {
List attributes = Lists.newArrayList();
if (!intervalMillisIsSet()) attributes.add("intervalMillis");
if (!viewThresholdMillisIsSet()) attributes.add("viewThresholdMillis");
return "Cannot build RollupConfig, some of required attributes are not set " + attributes;
}
}
}