
org.glowroot.common.live.ImmutableGlobalMeta Maven / Gradle / Ivy
package org.glowroot.common.live;
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.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 LiveWeavingService.GlobalMeta}.
*
* Use builder to create immutable instances:
* {@code ImmutableGlobalMeta.builder()}.
*/
@SuppressWarnings("all")
@ParametersAreNonnullByDefault
@Generated({"Immutables.generator", "LiveWeavingService.GlobalMeta"})
@Immutable
public final class ImmutableGlobalMeta implements LiveWeavingService.GlobalMeta {
private final boolean jvmOutOfSync;
private final boolean jvmRetransformClassesSupported;
private ImmutableGlobalMeta(boolean jvmOutOfSync, boolean jvmRetransformClassesSupported) {
this.jvmOutOfSync = jvmOutOfSync;
this.jvmRetransformClassesSupported = jvmRetransformClassesSupported;
}
/**
* @return value of {@code jvmOutOfSync} attribute
*/
@JsonProperty
@Override
public boolean jvmOutOfSync() {
return jvmOutOfSync;
}
/**
* @return value of {@code jvmRetransformClassesSupported} attribute
*/
@JsonProperty
@Override
public boolean jvmRetransformClassesSupported() {
return jvmRetransformClassesSupported;
}
/**
* Copy current immutable object by setting value for {@link LiveWeavingService.GlobalMeta#jvmOutOfSync() jvmOutOfSync}.
* Value equality check is used to prevent copying of the same value by returning {@code this}.
* @param value new value for jvmOutOfSync
* @return modified copy of the {@code this} object
*/
public final ImmutableGlobalMeta withJvmOutOfSync(boolean value) {
if (this.jvmOutOfSync == value) return this;
boolean newValue = value;
return new ImmutableGlobalMeta(newValue, this.jvmRetransformClassesSupported);
}
/**
* Copy current immutable object by setting value for {@link LiveWeavingService.GlobalMeta#jvmRetransformClassesSupported() jvmRetransformClassesSupported}.
* Value equality check is used to prevent copying of the same value by returning {@code this}.
* @param value new value for jvmRetransformClassesSupported
* @return modified copy of the {@code this} object
*/
public final ImmutableGlobalMeta withJvmRetransformClassesSupported(boolean value) {
if (this.jvmRetransformClassesSupported == value) return this;
boolean newValue = value;
return new ImmutableGlobalMeta(this.jvmOutOfSync, newValue);
}
/**
* This instance is equal to instances of {@code ImmutableGlobalMeta} 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 ImmutableGlobalMeta
&& equalTo((ImmutableGlobalMeta) another);
}
private boolean equalTo(ImmutableGlobalMeta another) {
return jvmOutOfSync == another.jvmOutOfSync
&& jvmRetransformClassesSupported == another.jvmRetransformClassesSupported;
}
/**
* Computes hash code from attributes: {@code jvmOutOfSync}, {@code jvmRetransformClassesSupported}.
* @return hashCode value
*/
@Override
public int hashCode() {
int h = 31;
h = h * 17 + Booleans.hashCode(jvmOutOfSync);
h = h * 17 + Booleans.hashCode(jvmRetransformClassesSupported);
return h;
}
/**
* Prints immutable value {@code GlobalMeta...} with attribute values,
* excluding any non-generated and auxiliary attributes.
* @return string representation of value
*/
@Override
public String toString() {
return MoreObjects.toStringHelper("GlobalMeta")
.add("jvmOutOfSync", jvmOutOfSync)
.add("jvmRetransformClassesSupported", jvmRetransformClassesSupported)
.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 jvmOutOfSync;
@JsonProperty
@Nullable Boolean jvmRetransformClassesSupported;
}
/**
* @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 ImmutableGlobalMeta fromJson(Json json) {
ImmutableGlobalMeta.Builder builder = ImmutableGlobalMeta.builder();
if (json.jvmOutOfSync != null) {
builder.jvmOutOfSync(json.jvmOutOfSync);
}
if (json.jvmRetransformClassesSupported != null) {
builder.jvmRetransformClassesSupported(json.jvmRetransformClassesSupported);
}
return builder.build();
}
/**
* Creates immutable copy of {@link LiveWeavingService.GlobalMeta}.
* 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 GlobalMeta instance
*/
public static ImmutableGlobalMeta copyOf(LiveWeavingService.GlobalMeta instance) {
if (instance instanceof ImmutableGlobalMeta) {
return (ImmutableGlobalMeta) instance;
}
return ImmutableGlobalMeta.builder()
.copyFrom(instance)
.build();
}
/**
* Creates builder for {@link org.glowroot.common.live.ImmutableGlobalMeta ImmutableGlobalMeta}.
* @return new ImmutableGlobalMeta builder
*/
public static ImmutableGlobalMeta.Builder builder() {
return new ImmutableGlobalMeta.Builder();
}
/**
* Builds instances of {@link org.glowroot.common.live.ImmutableGlobalMeta ImmutableGlobalMeta}.
* 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_JVM_OUT_OF_SYNC = 0x1L;
private static final long INIT_BIT_JVM_RETRANSFORM_CLASSES_SUPPORTED = 0x2L;
private long initBits = 0x3;
private boolean jvmOutOfSync;
private boolean jvmRetransformClassesSupported;
private Builder() {}
/**
* Fill builder with attribute values from provided {@link LiveWeavingService.GlobalMeta} 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(LiveWeavingService.GlobalMeta instance) {
Preconditions.checkNotNull(instance);
jvmOutOfSync(instance.jvmOutOfSync());
jvmRetransformClassesSupported(instance.jvmRetransformClassesSupported());
return this;
}
/**
* Initializes value for {@link LiveWeavingService.GlobalMeta#jvmOutOfSync() jvmOutOfSync}.
* @param jvmOutOfSync value for jvmOutOfSync
* @return {@code this} builder for chained invocation
*/
public final Builder jvmOutOfSync(boolean jvmOutOfSync) {
this.jvmOutOfSync = jvmOutOfSync;
initBits &= ~INIT_BIT_JVM_OUT_OF_SYNC;
return this;
}
/**
* Initializes value for {@link LiveWeavingService.GlobalMeta#jvmRetransformClassesSupported() jvmRetransformClassesSupported}.
* @param jvmRetransformClassesSupported value for jvmRetransformClassesSupported
* @return {@code this} builder for chained invocation
*/
public final Builder jvmRetransformClassesSupported(boolean jvmRetransformClassesSupported) {
this.jvmRetransformClassesSupported = jvmRetransformClassesSupported;
initBits &= ~INIT_BIT_JVM_RETRANSFORM_CLASSES_SUPPORTED;
return this;
}
/**
* Builds new {@link org.glowroot.common.live.ImmutableGlobalMeta ImmutableGlobalMeta}.
* @return immutable instance of GlobalMeta
* @throws exception {@code java.lang.IllegalStateException} if any required attributes are missing
*/
public ImmutableGlobalMeta build()
throws IllegalStateException {
checkRequiredAttributes();
return new ImmutableGlobalMeta(jvmOutOfSync, jvmRetransformClassesSupported);
}
private boolean jvmOutOfSyncIsSet() {
return (initBits & INIT_BIT_JVM_OUT_OF_SYNC) == 0;
}
private boolean jvmRetransformClassesSupportedIsSet() {
return (initBits & INIT_BIT_JVM_RETRANSFORM_CLASSES_SUPPORTED) == 0;
}
private void checkRequiredAttributes() throws IllegalStateException {
if (initBits != 0) {
throw new IllegalStateException(formatRequiredAttributesMessage());
}
}
private String formatRequiredAttributesMessage() {
List attributes = Lists.newArrayList();
if (!jvmOutOfSyncIsSet()) attributes.add("jvmOutOfSync");
if (!jvmRetransformClassesSupportedIsSet()) attributes.add("jvmRetransformClassesSupported");
return "Cannot build GlobalMeta, some of required attributes are not set " + attributes;
}
}
}