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

org.glowroot.ui.ImmutablePluginResponse Maven / Gradle / Ivy

There is a newer version: 0.9.28
Show newest version
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.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 ConfigJsonService.PluginResponse}.
 * 

* Use builder to create immutable instances: * {@code ImmutablePluginResponse.builder()}. */ @SuppressWarnings("all") @ParametersAreNonnullByDefault @Generated({"Immutables.generator", "ConfigJsonService.PluginResponse"}) @Immutable final class ImmutablePluginResponse implements ConfigJsonService.PluginResponse { private final String id; private final String name; private final boolean enabled; private ImmutablePluginResponse(String id, String name, boolean enabled) { this.id = id; this.name = name; this.enabled = enabled; } /** * @return value of {@code id} attribute */ @JsonProperty @Override public String id() { return id; } /** * @return value of {@code name} attribute */ @JsonProperty @Override public String name() { return name; } /** * @return value of {@code enabled} attribute */ @JsonProperty @Override public boolean enabled() { return enabled; } /** * Copy current immutable object by setting value for {@link ConfigJsonService.PluginResponse#id() id}. * Shallow reference equality check is used to prevent copying of the same value by returning {@code this}. * @param value new value for id * @return modified copy of the {@code this} object */ public final ImmutablePluginResponse withId(String value) { if (this.id == value) return this; String newValue = Preconditions.checkNotNull(value); return new ImmutablePluginResponse(newValue, this.name, this.enabled); } /** * Copy current immutable object by setting value for {@link ConfigJsonService.PluginResponse#name() name}. * Shallow reference equality check is used to prevent copying of the same value by returning {@code this}. * @param value new value for name * @return modified copy of the {@code this} object */ public final ImmutablePluginResponse withName(String value) { if (this.name == value) return this; String newValue = Preconditions.checkNotNull(value); return new ImmutablePluginResponse(this.id, newValue, this.enabled); } /** * Copy current immutable object by setting value for {@link ConfigJsonService.PluginResponse#enabled() enabled}. * Value equality check is used to prevent copying of the same value by returning {@code this}. * @param value new value for enabled * @return modified copy of the {@code this} object */ public final ImmutablePluginResponse withEnabled(boolean value) { if (this.enabled == value) return this; boolean newValue = value; return new ImmutablePluginResponse(this.id, this.name, newValue); } /** * This instance is equal to instances of {@code ImmutablePluginResponse} 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 ImmutablePluginResponse && equalTo((ImmutablePluginResponse) another); } private boolean equalTo(ImmutablePluginResponse another) { return id.equals(another.id) && name.equals(another.name) && enabled == another.enabled; } /** * Computes hash code from attributes: {@code id}, {@code name}, {@code enabled}. * @return hashCode value */ @Override public int hashCode() { int h = 31; h = h * 17 + id.hashCode(); h = h * 17 + name.hashCode(); h = h * 17 + Booleans.hashCode(enabled); return h; } /** * Prints immutable value {@code PluginResponse...} with attribute values, * excluding any non-generated and auxiliary attributes. * @return string representation of value */ @Override public String toString() { return MoreObjects.toStringHelper("PluginResponse") .add("id", id) .add("name", name) .add("enabled", enabled) .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 String id; @JsonProperty @Nullable String name; @JsonProperty @Nullable Boolean enabled; } /** * @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 ImmutablePluginResponse fromJson(Json json) { ImmutablePluginResponse.Builder builder = ImmutablePluginResponse.builder(); if (json.id != null) { builder.id(json.id); } if (json.name != null) { builder.name(json.name); } if (json.enabled != null) { builder.enabled(json.enabled); } return builder.build(); } /** * Creates immutable copy of {@link ConfigJsonService.PluginResponse}. * 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 PluginResponse instance */ static ImmutablePluginResponse copyOf(ConfigJsonService.PluginResponse instance) { if (instance instanceof ImmutablePluginResponse) { return (ImmutablePluginResponse) instance; } return ImmutablePluginResponse.builder() .copyFrom(instance) .build(); } /** * Creates builder for {@link org.glowroot.ui.ImmutablePluginResponse ImmutablePluginResponse}. * @return new ImmutablePluginResponse builder */ static ImmutablePluginResponse.Builder builder() { return new ImmutablePluginResponse.Builder(); } /** * Builds instances of {@link org.glowroot.ui.ImmutablePluginResponse ImmutablePluginResponse}. * 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_ID = 0x1L; private static final long INIT_BIT_NAME = 0x2L; private static final long INIT_BIT_ENABLED = 0x4L; private long initBits = 0x7; private @Nullable String id; private @Nullable String name; private boolean enabled; private Builder() {} /** * Fill builder with attribute values from provided {@link ConfigJsonService.PluginResponse} 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(ConfigJsonService.PluginResponse instance) { Preconditions.checkNotNull(instance); id(instance.id()); name(instance.name()); enabled(instance.enabled()); return this; } /** * Initializes value for {@link ConfigJsonService.PluginResponse#id() id}. * @param id value for id * @return {@code this} builder for chained invocation */ public final Builder id(String id) { this.id = Preconditions.checkNotNull(id); initBits &= ~INIT_BIT_ID; return this; } /** * Initializes value for {@link ConfigJsonService.PluginResponse#name() name}. * @param name value for name * @return {@code this} builder for chained invocation */ public final Builder name(String name) { this.name = Preconditions.checkNotNull(name); initBits &= ~INIT_BIT_NAME; return this; } /** * Initializes value for {@link ConfigJsonService.PluginResponse#enabled() enabled}. * @param enabled value for enabled * @return {@code this} builder for chained invocation */ public final Builder enabled(boolean enabled) { this.enabled = enabled; initBits &= ~INIT_BIT_ENABLED; return this; } /** * Builds new {@link org.glowroot.ui.ImmutablePluginResponse ImmutablePluginResponse}. * @return immutable instance of PluginResponse * @throws exception {@code java.lang.IllegalStateException} if any required attributes are missing */ public ImmutablePluginResponse build() throws IllegalStateException { checkRequiredAttributes(); return new ImmutablePluginResponse(id, name, enabled); } private boolean idIsSet() { return (initBits & INIT_BIT_ID) == 0; } private boolean nameIsSet() { return (initBits & INIT_BIT_NAME) == 0; } private boolean enabledIsSet() { return (initBits & INIT_BIT_ENABLED) == 0; } private void checkRequiredAttributes() throws IllegalStateException { if (initBits != 0) { throw new IllegalStateException(formatRequiredAttributesMessage()); } } private String formatRequiredAttributesMessage() { List attributes = Lists.newArrayList(); if (!idIsSet()) attributes.add("id"); if (!nameIsSet()) attributes.add("name"); if (!enabledIsSet()) attributes.add("enabled"); return "Cannot build PluginResponse, some of required attributes are not set " + attributes; } } }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy