
org.glowroot.ui.ImmutableMBeanAttributeNamesResponse 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.Preconditions;
import org.glowroot.agent.shaded.google.common.collect.ImmutableList;
import org.glowroot.agent.shaded.google.common.collect.Lists;
import org.glowroot.agent.shaded.google.common.primitives.Booleans;
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 GaugeConfigJsonService.MBeanAttributeNamesResponse}.
*
* Use builder to create immutable instances:
* {@code ImmutableMBeanAttributeNamesResponse.builder()}.
*/
@SuppressWarnings("all")
@ParametersAreNonnullByDefault
@Generated({"Immutables.generator", "GaugeConfigJsonService.MBeanAttributeNamesResponse"})
@Immutable
final class ImmutableMBeanAttributeNamesResponse
implements GaugeConfigJsonService.MBeanAttributeNamesResponse {
private final boolean mbeanUnavailable;
private final boolean mbeanUnmatched;
private final boolean duplicateMBean;
private final ImmutableList mbeanAttributes;
private ImmutableMBeanAttributeNamesResponse(
boolean mbeanUnavailable,
boolean mbeanUnmatched,
boolean duplicateMBean,
ImmutableList mbeanAttributes) {
this.mbeanUnavailable = mbeanUnavailable;
this.mbeanUnmatched = mbeanUnmatched;
this.duplicateMBean = duplicateMBean;
this.mbeanAttributes = mbeanAttributes;
}
/**
* @return value of {@code mbeanUnavailable} attribute
*/
@JsonProperty
@Override
public boolean mbeanUnavailable() {
return mbeanUnavailable;
}
/**
* @return value of {@code mbeanUnmatched} attribute
*/
@JsonProperty
@Override
public boolean mbeanUnmatched() {
return mbeanUnmatched;
}
/**
* @return value of {@code duplicateMBean} attribute
*/
@JsonProperty
@Override
public boolean duplicateMBean() {
return duplicateMBean;
}
/**
* @return value of {@code mbeanAttributes} attribute
*/
@JsonProperty
@Override
public ImmutableList mbeanAttributes() {
return mbeanAttributes;
}
/**
* Copy current immutable object by setting value for {@link GaugeConfigJsonService.MBeanAttributeNamesResponse#mbeanUnavailable() mbeanUnavailable}.
* Value equality check is used to prevent copying of the same value by returning {@code this}.
* @param value new value for mbeanUnavailable
* @return modified copy of the {@code this} object
*/
public final ImmutableMBeanAttributeNamesResponse withMbeanUnavailable(boolean value) {
if (this.mbeanUnavailable == value) return this;
boolean newValue = value;
return new ImmutableMBeanAttributeNamesResponse(newValue, this.mbeanUnmatched, this.duplicateMBean, this.mbeanAttributes);
}
/**
* Copy current immutable object by setting value for {@link GaugeConfigJsonService.MBeanAttributeNamesResponse#mbeanUnmatched() mbeanUnmatched}.
* Value equality check is used to prevent copying of the same value by returning {@code this}.
* @param value new value for mbeanUnmatched
* @return modified copy of the {@code this} object
*/
public final ImmutableMBeanAttributeNamesResponse withMbeanUnmatched(boolean value) {
if (this.mbeanUnmatched == value) return this;
boolean newValue = value;
return new ImmutableMBeanAttributeNamesResponse(this.mbeanUnavailable, newValue, this.duplicateMBean, this.mbeanAttributes);
}
/**
* Copy current immutable object by setting value for {@link GaugeConfigJsonService.MBeanAttributeNamesResponse#duplicateMBean() duplicateMBean}.
* Value equality check is used to prevent copying of the same value by returning {@code this}.
* @param value new value for duplicateMBean
* @return modified copy of the {@code this} object
*/
public final ImmutableMBeanAttributeNamesResponse withDuplicateMBean(boolean value) {
if (this.duplicateMBean == value) return this;
boolean newValue = value;
return new ImmutableMBeanAttributeNamesResponse(this.mbeanUnavailable, this.mbeanUnmatched, newValue, this.mbeanAttributes);
}
/**
* Copy current immutable object with elements that replace content of {@link GaugeConfigJsonService.MBeanAttributeNamesResponse#mbeanAttributes() mbeanAttributes}.
* @param elements elements to set
* @return modified copy of {@code this} object
*/
public final ImmutableMBeanAttributeNamesResponse withMbeanAttributes(String... elements) {
ImmutableList newValue = ImmutableList.copyOf(elements);
return new ImmutableMBeanAttributeNamesResponse(this.mbeanUnavailable, this.mbeanUnmatched, this.duplicateMBean, newValue);
}
/**
* Copy current immutable object with elements that replace content of {@link GaugeConfigJsonService.MBeanAttributeNamesResponse#mbeanAttributes() mbeanAttributes}.
* Shallow reference equality check is used to prevent copying of the same value by returning {@code this}.
* @param elements iterable of mbeanAttributes elements to set
* @return modified copy of {@code this} object
*/
public final ImmutableMBeanAttributeNamesResponse withMbeanAttributes(Iterable elements) {
if (this.mbeanAttributes == elements) return this;
ImmutableList newValue = ImmutableList.copyOf(elements);
return new ImmutableMBeanAttributeNamesResponse(this.mbeanUnavailable, this.mbeanUnmatched, this.duplicateMBean, newValue);
}
/**
* This instance is equal to instances of {@code ImmutableMBeanAttributeNamesResponse} 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 ImmutableMBeanAttributeNamesResponse
&& equalTo((ImmutableMBeanAttributeNamesResponse) another);
}
private boolean equalTo(ImmutableMBeanAttributeNamesResponse another) {
return mbeanUnavailable == another.mbeanUnavailable
&& mbeanUnmatched == another.mbeanUnmatched
&& duplicateMBean == another.duplicateMBean
&& mbeanAttributes.equals(another.mbeanAttributes);
}
/**
* Computes hash code from attributes: {@code mbeanUnavailable}, {@code mbeanUnmatched}, {@code duplicateMBean}, {@code mbeanAttributes}.
* @return hashCode value
*/
@Override
public int hashCode() {
int h = 31;
h = h * 17 + Booleans.hashCode(mbeanUnavailable);
h = h * 17 + Booleans.hashCode(mbeanUnmatched);
h = h * 17 + Booleans.hashCode(duplicateMBean);
h = h * 17 + mbeanAttributes.hashCode();
return h;
}
/**
* Prints immutable value {@code MBeanAttributeNamesResponse...} with attribute values,
* excluding any non-generated and auxiliary attributes.
* @return string representation of value
*/
@Override
public String toString() {
return MoreObjects.toStringHelper("MBeanAttributeNamesResponse")
.add("mbeanUnavailable", mbeanUnavailable)
.add("mbeanUnmatched", mbeanUnmatched)
.add("duplicateMBean", duplicateMBean)
.add("mbeanAttributes", mbeanAttributes)
.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 Boolean mbeanUnavailable;
@JsonProperty
@Nullable Boolean mbeanUnmatched;
@JsonProperty
@Nullable Boolean duplicateMBean;
@JsonProperty
@Nullable ImmutableList mbeanAttributes;
}
/**
* @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 ImmutableMBeanAttributeNamesResponse fromJson(Json json) {
ImmutableMBeanAttributeNamesResponse.Builder builder = ImmutableMBeanAttributeNamesResponse.builder();
if (json.mbeanUnavailable != null) {
builder.mbeanUnavailable(json.mbeanUnavailable);
}
if (json.mbeanUnmatched != null) {
builder.mbeanUnmatched(json.mbeanUnmatched);
}
if (json.duplicateMBean != null) {
builder.duplicateMBean(json.duplicateMBean);
}
if (json.mbeanAttributes != null) {
builder.addAllMbeanAttributes(json.mbeanAttributes);
}
return builder.build();
}
/**
* Creates immutable copy of {@link GaugeConfigJsonService.MBeanAttributeNamesResponse}.
* 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 MBeanAttributeNamesResponse instance
*/
static ImmutableMBeanAttributeNamesResponse copyOf(GaugeConfigJsonService.MBeanAttributeNamesResponse instance) {
if (instance instanceof ImmutableMBeanAttributeNamesResponse) {
return (ImmutableMBeanAttributeNamesResponse) instance;
}
return ImmutableMBeanAttributeNamesResponse.builder()
.copyFrom(instance)
.build();
}
/**
* Creates builder for {@link org.glowroot.ui.ImmutableMBeanAttributeNamesResponse ImmutableMBeanAttributeNamesResponse}.
* @return new ImmutableMBeanAttributeNamesResponse builder
*/
static ImmutableMBeanAttributeNamesResponse.Builder builder() {
return new ImmutableMBeanAttributeNamesResponse.Builder();
}
/**
* Builds instances of {@link org.glowroot.ui.ImmutableMBeanAttributeNamesResponse ImmutableMBeanAttributeNamesResponse}.
* 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_MBEAN_UNAVAILABLE = 0x1L;
private static final long INIT_BIT_MBEAN_UNMATCHED = 0x2L;
private static final long INIT_BIT_DUPLICATE_M_BEAN = 0x4L;
private long initBits = 0x7;
private boolean mbeanUnavailable;
private boolean mbeanUnmatched;
private boolean duplicateMBean;
private ImmutableList.Builder mbeanAttributesBuilder = ImmutableList.builder();
private Builder() {}
/**
* Fill builder with attribute values from provided {@link GaugeConfigJsonService.MBeanAttributeNamesResponse} 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(GaugeConfigJsonService.MBeanAttributeNamesResponse instance) {
Preconditions.checkNotNull(instance);
mbeanUnavailable(instance.mbeanUnavailable());
mbeanUnmatched(instance.mbeanUnmatched());
duplicateMBean(instance.duplicateMBean());
addAllMbeanAttributes(instance.mbeanAttributes());
return this;
}
/**
* Initializes value for {@link GaugeConfigJsonService.MBeanAttributeNamesResponse#mbeanUnavailable() mbeanUnavailable}.
* @param mbeanUnavailable value for mbeanUnavailable
* @return {@code this} builder for chained invocation
*/
public final Builder mbeanUnavailable(boolean mbeanUnavailable) {
this.mbeanUnavailable = mbeanUnavailable;
initBits &= ~INIT_BIT_MBEAN_UNAVAILABLE;
return this;
}
/**
* Initializes value for {@link GaugeConfigJsonService.MBeanAttributeNamesResponse#mbeanUnmatched() mbeanUnmatched}.
* @param mbeanUnmatched value for mbeanUnmatched
* @return {@code this} builder for chained invocation
*/
public final Builder mbeanUnmatched(boolean mbeanUnmatched) {
this.mbeanUnmatched = mbeanUnmatched;
initBits &= ~INIT_BIT_MBEAN_UNMATCHED;
return this;
}
/**
* Initializes value for {@link GaugeConfigJsonService.MBeanAttributeNamesResponse#duplicateMBean() duplicateMBean}.
* @param duplicateMBean value for duplicateMBean
* @return {@code this} builder for chained invocation
*/
public final Builder duplicateMBean(boolean duplicateMBean) {
this.duplicateMBean = duplicateMBean;
initBits &= ~INIT_BIT_DUPLICATE_M_BEAN;
return this;
}
/**
* Adds one element to {@link GaugeConfigJsonService.MBeanAttributeNamesResponse#mbeanAttributes() mbeanAttributes} list.
* @param element mbeanAttributes element
* @return {@code this} builder for chained invocation
*/
public final Builder addMbeanAttributes(String element) {
mbeanAttributesBuilder.add(element);
return this;
}
/**
* Adds elements to {@link GaugeConfigJsonService.MBeanAttributeNamesResponse#mbeanAttributes() mbeanAttributes} list.
* @param elements array of mbeanAttributes elements
* @return {@code this} builder for chained invocation
*/
public final Builder addMbeanAttributes(String... elements) {
mbeanAttributesBuilder.add(elements);
return this;
}
/**
* Sets or replaces all elements for {@link GaugeConfigJsonService.MBeanAttributeNamesResponse#mbeanAttributes() mbeanAttributes} list.
* @param elements iterable of mbeanAttributes elements
* @return {@code this} builder for chained invocation
*/
public final Builder mbeanAttributes(Iterable elements) {
mbeanAttributesBuilder = ImmutableList.builder();
return addAllMbeanAttributes(elements);
}
/**
* Adds elements to {@link GaugeConfigJsonService.MBeanAttributeNamesResponse#mbeanAttributes() mbeanAttributes} list.
* @param elements iterable of mbeanAttributes elements
* @return {@code this} builder for chained invocation
*/
public final Builder addAllMbeanAttributes(Iterable elements) {
mbeanAttributesBuilder.addAll(elements);
return this;
}
/**
* Builds new {@link org.glowroot.ui.ImmutableMBeanAttributeNamesResponse ImmutableMBeanAttributeNamesResponse}.
* @return immutable instance of MBeanAttributeNamesResponse
* @throws exception {@code java.lang.IllegalStateException} if any required attributes are missing
*/
public ImmutableMBeanAttributeNamesResponse build()
throws IllegalStateException {
checkRequiredAttributes();
return new ImmutableMBeanAttributeNamesResponse(mbeanUnavailable, mbeanUnmatched, duplicateMBean, mbeanAttributesBuilder.build());
}
private boolean mbeanUnavailableIsSet() {
return (initBits & INIT_BIT_MBEAN_UNAVAILABLE) == 0;
}
private boolean mbeanUnmatchedIsSet() {
return (initBits & INIT_BIT_MBEAN_UNMATCHED) == 0;
}
private boolean duplicateMBeanIsSet() {
return (initBits & INIT_BIT_DUPLICATE_M_BEAN) == 0;
}
private void checkRequiredAttributes() throws IllegalStateException {
if (initBits != 0) {
throw new IllegalStateException(formatRequiredAttributesMessage());
}
}
private String formatRequiredAttributesMessage() {
List attributes = Lists.newArrayList();
if (!mbeanUnavailableIsSet()) attributes.add("mbeanUnavailable");
if (!mbeanUnmatchedIsSet()) attributes.add("mbeanUnmatched");
if (!duplicateMBeanIsSet()) attributes.add("duplicateMBean");
return "Cannot build MBeanAttributeNamesResponse, some of required attributes are not set " + attributes;
}
}
}