
org.glowroot.ui.ImmutableUserRecordingConfigDto Maven / Gradle / Ivy
package org.glowroot.ui;
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.Objects;
import org.glowroot.agent.shaded.google.common.base.Preconditions;
import org.glowroot.agent.shaded.google.common.collect.ImmutableList;
import org.glowroot.agent.shaded.google.common.collect.Lists;
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 ConfigJsonService.UserRecordingConfigDto}.
*
* Use builder to create immutable instances:
* {@code ImmutableUserRecordingConfigDto.builder()}.
*/
@SuppressWarnings("all")
@ParametersAreNonnullByDefault
@Generated({"Immutables.generator", "ConfigJsonService.UserRecordingConfigDto"})
@Immutable
final class ImmutableUserRecordingConfigDto
extends ConfigJsonService.UserRecordingConfigDto {
private final ImmutableList users;
private final @Nullable Integer profilingIntervalMillis;
private final String version;
private ImmutableUserRecordingConfigDto(
ImmutableList users,
@Nullable Integer profilingIntervalMillis,
String version) {
this.users = users;
this.profilingIntervalMillis = profilingIntervalMillis;
this.version = version;
}
/**
* @return value of {@code users} attribute
*/
@JsonProperty
@Override
ImmutableList users() {
return users;
}
/**
* @return value of {@code profilingIntervalMillis} attribute
*/
@JsonProperty
@Override
@Nullable Integer profilingIntervalMillis() {
return profilingIntervalMillis;
}
/**
* @return value of {@code version} attribute
*/
@JsonProperty
@Override
String version() {
return version;
}
/**
* Copy current immutable object with elements that replace content of {@link ConfigJsonService.UserRecordingConfigDto#users() users}.
* @param elements elements to set
* @return modified copy of {@code this} object
*/
public final ImmutableUserRecordingConfigDto withUsers(String... elements) {
ImmutableList newValue = ImmutableList.copyOf(elements);
return new ImmutableUserRecordingConfigDto(newValue, this.profilingIntervalMillis, this.version);
}
/**
* Copy current immutable object with elements that replace content of {@link ConfigJsonService.UserRecordingConfigDto#users() users}.
* Shallow reference equality check is used to prevent copying of the same value by returning {@code this}.
* @param elements iterable of users elements to set
* @return modified copy of {@code this} object
*/
public final ImmutableUserRecordingConfigDto withUsers(Iterable elements) {
if (this.users == elements) return this;
ImmutableList newValue = ImmutableList.copyOf(elements);
return new ImmutableUserRecordingConfigDto(newValue, this.profilingIntervalMillis, this.version);
}
/**
* Copy current immutable object by setting value for {@link ConfigJsonService.UserRecordingConfigDto#profilingIntervalMillis() profilingIntervalMillis}.
* Shallow reference equality check is used to prevent copying of the same value by returning {@code this}.
* @param value new value for profilingIntervalMillis, can be {@code null}
* @return modified copy of the {@code this} object
*/
public final ImmutableUserRecordingConfigDto withProfilingIntervalMillis(@Nullable Integer value) {
if (this.profilingIntervalMillis == value) return this;
@Nullable Integer newValue = value;
return new ImmutableUserRecordingConfigDto(this.users, newValue, this.version);
}
/**
* Copy current immutable object by setting value for {@link ConfigJsonService.UserRecordingConfigDto#version() version}.
* Shallow reference equality check is used to prevent copying of the same value by returning {@code this}.
* @param value new value for version
* @return modified copy of the {@code this} object
*/
public final ImmutableUserRecordingConfigDto withVersion(String value) {
if (this.version == value) return this;
String newValue = Preconditions.checkNotNull(value);
return new ImmutableUserRecordingConfigDto(this.users, this.profilingIntervalMillis, newValue);
}
/**
* This instance is equal to instances of {@code ImmutableUserRecordingConfigDto} 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 ImmutableUserRecordingConfigDto
&& equalTo((ImmutableUserRecordingConfigDto) another);
}
private boolean equalTo(ImmutableUserRecordingConfigDto another) {
return users.equals(another.users)
&& Objects.equal(profilingIntervalMillis, another.profilingIntervalMillis)
&& version.equals(another.version);
}
/**
* Computes hash code from attributes: {@code users}, {@code profilingIntervalMillis}, {@code version}.
* @return hashCode value
*/
@Override
public int hashCode() {
int h = 31;
h = h * 17 + users.hashCode();
h = h * 17 + Objects.hashCode(profilingIntervalMillis);
h = h * 17 + version.hashCode();
return h;
}
/**
* Prints immutable value {@code UserRecordingConfigDto...} with attribute values,
* excluding any non-generated and auxiliary attributes.
* @return string representation of value
*/
@Override
public String toString() {
return MoreObjects.toStringHelper("UserRecordingConfigDto")
.add("users", users)
.add("profilingIntervalMillis", profilingIntervalMillis)
.add("version", version)
.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 ImmutableList users;
@JsonProperty
@Nullable Integer profilingIntervalMillis;
@JsonProperty
@Nullable String version;
}
/**
* @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 ImmutableUserRecordingConfigDto fromJson(Json json) {
ImmutableUserRecordingConfigDto.Builder builder = ImmutableUserRecordingConfigDto.builder();
if (json.users != null) {
builder.addAllUsers(json.users);
}
if (json.profilingIntervalMillis != null) {
builder.profilingIntervalMillis(json.profilingIntervalMillis);
}
if (json.version != null) {
builder.version(json.version);
}
return builder.build();
}
/**
* Creates immutable copy of {@link ConfigJsonService.UserRecordingConfigDto}.
* 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 UserRecordingConfigDto instance
*/
static ImmutableUserRecordingConfigDto copyOf(ConfigJsonService.UserRecordingConfigDto instance) {
if (instance instanceof ImmutableUserRecordingConfigDto) {
return (ImmutableUserRecordingConfigDto) instance;
}
return ImmutableUserRecordingConfigDto.builder()
.copyFrom(instance)
.build();
}
/**
* Creates builder for {@link org.glowroot.ui.ImmutableUserRecordingConfigDto ImmutableUserRecordingConfigDto}.
* @return new ImmutableUserRecordingConfigDto builder
*/
static ImmutableUserRecordingConfigDto.Builder builder() {
return new ImmutableUserRecordingConfigDto.Builder();
}
/**
* Builds instances of {@link org.glowroot.ui.ImmutableUserRecordingConfigDto ImmutableUserRecordingConfigDto}.
* 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
static final class Builder {
private static final long INIT_BIT_VERSION = 0x1L;
private long initBits = 0x1;
private ImmutableList.Builder usersBuilder = ImmutableList.builder();
private @Nullable Integer profilingIntervalMillis;
private @Nullable String version;
private Builder() {}
/**
* Fill builder with attribute values from provided {@link ConfigJsonService.UserRecordingConfigDto} instance.
* Regular attribute values will be replaced with ones of an instance.
* Instance's absent optional values will not replace present values.
* Collection elements and entries will be added, not replaced.
* @param instance instance to copy values from
* @return {@code this} builder for chained invocation
*/
public final Builder copyFrom(ConfigJsonService.UserRecordingConfigDto instance) {
Preconditions.checkNotNull(instance);
addAllUsers(instance.users());
@Nullable Integer profilingIntervalMillisValue = instance.profilingIntervalMillis();
if (profilingIntervalMillisValue != null) {
profilingIntervalMillis(profilingIntervalMillisValue);
}
version(instance.version());
return this;
}
/**
* Adds one element to {@link ConfigJsonService.UserRecordingConfigDto#users() users} list.
* @param element users element
* @return {@code this} builder for chained invocation
*/
public final Builder addUsers(String element) {
usersBuilder.add(element);
return this;
}
/**
* Adds elements to {@link ConfigJsonService.UserRecordingConfigDto#users() users} list.
* @param elements array of users elements
* @return {@code this} builder for chained invocation
*/
public final Builder addUsers(String... elements) {
usersBuilder.add(elements);
return this;
}
/**
* Sets or replaces all elements for {@link ConfigJsonService.UserRecordingConfigDto#users() users} list.
* @param elements iterable of users elements
* @return {@code this} builder for chained invocation
*/
public final Builder users(Iterable elements) {
usersBuilder = ImmutableList.builder();
return addAllUsers(elements);
}
/**
* Adds elements to {@link ConfigJsonService.UserRecordingConfigDto#users() users} list.
* @param elements iterable of users elements
* @return {@code this} builder for chained invocation
*/
public final Builder addAllUsers(Iterable elements) {
usersBuilder.addAll(elements);
return this;
}
/**
* Initializes value for {@link ConfigJsonService.UserRecordingConfigDto#profilingIntervalMillis() profilingIntervalMillis}.
* @param profilingIntervalMillis value for profilingIntervalMillis, can be {@code null}
* @return {@code this} builder for chained invocation
*/
public final Builder profilingIntervalMillis(@Nullable Integer profilingIntervalMillis) {
this.profilingIntervalMillis = profilingIntervalMillis;
return this;
}
/**
* Initializes value for {@link ConfigJsonService.UserRecordingConfigDto#version() version}.
* @param version value for version
* @return {@code this} builder for chained invocation
*/
public final Builder version(String version) {
this.version = Preconditions.checkNotNull(version);
initBits &= ~INIT_BIT_VERSION;
return this;
}
/**
* Builds new {@link org.glowroot.ui.ImmutableUserRecordingConfigDto ImmutableUserRecordingConfigDto}.
* @return immutable instance of UserRecordingConfigDto
* @throws exception {@code java.lang.IllegalStateException} if any required attributes are missing
*/
public ImmutableUserRecordingConfigDto build()
throws IllegalStateException {
checkRequiredAttributes();
return new ImmutableUserRecordingConfigDto(usersBuilder.build(), profilingIntervalMillis, version);
}
private boolean versionIsSet() {
return (initBits & INIT_BIT_VERSION) == 0;
}
private void checkRequiredAttributes() throws IllegalStateException {
if (initBits != 0) {
throw new IllegalStateException(formatRequiredAttributesMessage());
}
}
private String formatRequiredAttributesMessage() {
List attributes = Lists.newArrayList();
if (!versionIsSet()) attributes.add("version");
return "Cannot build UserRecordingConfigDto, some of required attributes are not set " + attributes;
}
}
}