
org.glowroot.ui.ImmutableJsonServiceMatcher 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.Lists;
import java.util.List;
import java.util.regex.Matcher;
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 HttpServerHandler.JsonServiceMatcher}.
*
* Use builder to create immutable instances:
* {@code ImmutableJsonServiceMatcher.builder()}.
* Use static factory method to create immutable instances:
* {@code ImmutableJsonServiceMatcher.of()}.
*/
@SuppressWarnings("all")
@ParametersAreNonnullByDefault
@Generated({"Immutables.generator", "HttpServerHandler.JsonServiceMatcher"})
@Immutable
final class ImmutableJsonServiceMatcher implements HttpServerHandler.JsonServiceMatcher {
private final HttpServerHandler.JsonServiceMapping jsonServiceMapping;
private final Matcher matcher;
private ImmutableJsonServiceMatcher(
HttpServerHandler.JsonServiceMapping jsonServiceMapping,
Matcher matcher) {
this.jsonServiceMapping = Preconditions.checkNotNull(jsonServiceMapping);
this.matcher = Preconditions.checkNotNull(matcher);
}
private ImmutableJsonServiceMatcher(
ImmutableJsonServiceMatcher original,
HttpServerHandler.JsonServiceMapping jsonServiceMapping,
Matcher matcher) {
this.jsonServiceMapping = jsonServiceMapping;
this.matcher = matcher;
}
/**
* @return value of {@code jsonServiceMapping} attribute
*/
@JsonProperty
@Override
public HttpServerHandler.JsonServiceMapping jsonServiceMapping() {
return jsonServiceMapping;
}
/**
* @return value of {@code matcher} attribute
*/
@JsonProperty
@Override
public Matcher matcher() {
return matcher;
}
/**
* Copy current immutable object by setting value for {@link HttpServerHandler.JsonServiceMatcher#jsonServiceMapping() jsonServiceMapping}.
* Shallow reference equality check is used to prevent copying of the same value by returning {@code this}.
* @param value new value for jsonServiceMapping
* @return modified copy of the {@code this} object
*/
public final ImmutableJsonServiceMatcher withJsonServiceMapping(HttpServerHandler.JsonServiceMapping value) {
if (this.jsonServiceMapping == value) return this;
HttpServerHandler.JsonServiceMapping newValue = Preconditions.checkNotNull(value);
return new ImmutableJsonServiceMatcher(this, newValue, this.matcher);
}
/**
* Copy current immutable object by setting value for {@link HttpServerHandler.JsonServiceMatcher#matcher() matcher}.
* Shallow reference equality check is used to prevent copying of the same value by returning {@code this}.
* @param value new value for matcher
* @return modified copy of the {@code this} object
*/
public final ImmutableJsonServiceMatcher withMatcher(Matcher value) {
if (this.matcher == value) return this;
Matcher newValue = Preconditions.checkNotNull(value);
return new ImmutableJsonServiceMatcher(this, this.jsonServiceMapping, newValue);
}
/**
* This instance is equal to instances of {@code ImmutableJsonServiceMatcher} 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 ImmutableJsonServiceMatcher
&& equalTo((ImmutableJsonServiceMatcher) another);
}
private boolean equalTo(ImmutableJsonServiceMatcher another) {
return jsonServiceMapping.equals(another.jsonServiceMapping)
&& matcher.equals(another.matcher);
}
/**
* Computes hash code from attributes: {@code jsonServiceMapping}, {@code matcher}.
* @return hashCode value
*/
@Override
public int hashCode() {
int h = 31;
h = h * 17 + jsonServiceMapping.hashCode();
h = h * 17 + matcher.hashCode();
return h;
}
/**
* Prints immutable value {@code JsonServiceMatcher...} with attribute values,
* excluding any non-generated and auxiliary attributes.
* @return string representation of value
*/
@Override
public String toString() {
return MoreObjects.toStringHelper("JsonServiceMatcher")
.add("jsonServiceMapping", jsonServiceMapping)
.add("matcher", matcher)
.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 HttpServerHandler.JsonServiceMapping jsonServiceMapping;
@JsonProperty
@Nullable Matcher matcher;
}
/**
* @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 ImmutableJsonServiceMatcher fromJson(Json json) {
ImmutableJsonServiceMatcher.Builder builder = ImmutableJsonServiceMatcher.builder();
if (json.jsonServiceMapping != null) {
builder.jsonServiceMapping(json.jsonServiceMapping);
}
if (json.matcher != null) {
builder.matcher(json.matcher);
}
return builder.build();
}
/**
* Construct new immutable {@code JsonServiceMatcher} instance.
* @param jsonServiceMapping value for {@code jsonServiceMapping}
* @param matcher value for {@code matcher}
* @return immutable JsonServiceMatcher instance
*/
public static ImmutableJsonServiceMatcher of(HttpServerHandler.JsonServiceMapping jsonServiceMapping, Matcher matcher) {
return new ImmutableJsonServiceMatcher(jsonServiceMapping, matcher);
}
/**
* Creates immutable copy of {@link HttpServerHandler.JsonServiceMatcher}.
* 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 JsonServiceMatcher instance
*/
static ImmutableJsonServiceMatcher copyOf(HttpServerHandler.JsonServiceMatcher instance) {
if (instance instanceof ImmutableJsonServiceMatcher) {
return (ImmutableJsonServiceMatcher) instance;
}
return ImmutableJsonServiceMatcher.builder()
.copyFrom(instance)
.build();
}
/**
* Creates builder for {@link org.glowroot.ui.ImmutableJsonServiceMatcher ImmutableJsonServiceMatcher}.
* @return new ImmutableJsonServiceMatcher builder
*/
static ImmutableJsonServiceMatcher.Builder builder() {
return new ImmutableJsonServiceMatcher.Builder();
}
/**
* Builds instances of {@link org.glowroot.ui.ImmutableJsonServiceMatcher ImmutableJsonServiceMatcher}.
* 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_JSON_SERVICE_MAPPING = 0x1L;
private static final long INIT_BIT_MATCHER = 0x2L;
private long initBits = 0x3;
private @Nullable HttpServerHandler.JsonServiceMapping jsonServiceMapping;
private @Nullable Matcher matcher;
private Builder() {}
/**
* Fill builder with attribute values from provided {@link HttpServerHandler.JsonServiceMatcher} 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(HttpServerHandler.JsonServiceMatcher instance) {
Preconditions.checkNotNull(instance);
jsonServiceMapping(instance.jsonServiceMapping());
matcher(instance.matcher());
return this;
}
/**
* Initializes value for {@link HttpServerHandler.JsonServiceMatcher#jsonServiceMapping() jsonServiceMapping}.
* @param jsonServiceMapping value for jsonServiceMapping
* @return {@code this} builder for chained invocation
*/
public final Builder jsonServiceMapping(HttpServerHandler.JsonServiceMapping jsonServiceMapping) {
this.jsonServiceMapping = Preconditions.checkNotNull(jsonServiceMapping);
initBits &= ~INIT_BIT_JSON_SERVICE_MAPPING;
return this;
}
/**
* Initializes value for {@link HttpServerHandler.JsonServiceMatcher#matcher() matcher}.
* @param matcher value for matcher
* @return {@code this} builder for chained invocation
*/
public final Builder matcher(Matcher matcher) {
this.matcher = Preconditions.checkNotNull(matcher);
initBits &= ~INIT_BIT_MATCHER;
return this;
}
/**
* Builds new {@link org.glowroot.ui.ImmutableJsonServiceMatcher ImmutableJsonServiceMatcher}.
* @return immutable instance of JsonServiceMatcher
* @throws exception {@code java.lang.IllegalStateException} if any required attributes are missing
*/
public ImmutableJsonServiceMatcher build()
throws IllegalStateException {
checkRequiredAttributes();
return new ImmutableJsonServiceMatcher(null, jsonServiceMapping, matcher);
}
private boolean jsonServiceMappingIsSet() {
return (initBits & INIT_BIT_JSON_SERVICE_MAPPING) == 0;
}
private boolean matcherIsSet() {
return (initBits & INIT_BIT_MATCHER) == 0;
}
private void checkRequiredAttributes() throws IllegalStateException {
if (initBits != 0) {
throw new IllegalStateException(formatRequiredAttributesMessage());
}
}
private String formatRequiredAttributesMessage() {
List attributes = Lists.newArrayList();
if (!jsonServiceMappingIsSet()) attributes.add("jsonServiceMapping");
if (!matcherIsSet()) attributes.add("matcher");
return "Cannot build JsonServiceMatcher, some of required attributes are not set " + attributes;
}
}
}