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

io.protostuff.generator.html.json.service.ImmutableServiceMethod Maven / Gradle / Ivy

There is a newer version: 3.1.40
Show newest version
package io.protostuff.generator.html.json.service;

import com.fasterxml.jackson.annotation.JsonAutoDetect;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.google.common.base.MoreObjects;
import com.google.common.base.Objects;
import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Lists;
import com.google.errorprone.annotations.CanIgnoreReturnValue;
import java.util.List;
import java.util.Map;
import javax.annotation.CheckReturnValue;
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 ServiceMethod}.
 * 

* Use the builder to create immutable instances: * {@code ImmutableServiceMethod.builder()}. */ @SuppressWarnings({"all"}) @ParametersAreNonnullByDefault @Generated({"Immutables.generator", "ServiceMethod"}) @Immutable @CheckReturnValue public final class ImmutableServiceMethod implements ServiceMethod { private final String name; private final @Nullable String description; private final String argTypeId; private final String returnTypeId; private final ImmutableMap options; private ImmutableServiceMethod( String name, @Nullable String description, String argTypeId, String returnTypeId, ImmutableMap options) { this.name = name; this.description = description; this.argTypeId = argTypeId; this.returnTypeId = returnTypeId; this.options = options; } /** * @return The value of the {@code name} attribute */ @JsonProperty("name") @Override public String name() { return name; } /** * @return The value of the {@code description} attribute */ @JsonProperty("description") @Override public @Nullable String description() { return description; } /** * @return The value of the {@code argTypeId} attribute */ @JsonProperty("argTypeId") @Override public String argTypeId() { return argTypeId; } /** * @return The value of the {@code returnTypeId} attribute */ @JsonProperty("returnTypeId") @Override public String returnTypeId() { return returnTypeId; } /** * @return The value of the {@code options} attribute */ @JsonProperty("options") @Override public ImmutableMap options() { return options; } /** * Copy the current immutable object by setting a value for the {@link ServiceMethod#name() name} attribute. * An equals check used to prevent copying of the same value by returning {@code this}. * @param value A new value for name * @return A modified copy of the {@code this} object */ public final ImmutableServiceMethod withName(String value) { if (this.name.equals(value)) return this; String newValue = Preconditions.checkNotNull(value, "name"); return new ImmutableServiceMethod(newValue, this.description, this.argTypeId, this.returnTypeId, this.options); } /** * Copy the current immutable object by setting a value for the {@link ServiceMethod#description() description} attribute. * An equals check used to prevent copying of the same value by returning {@code this}. * @param value A new value for description (can be {@code null}) * @return A modified copy of the {@code this} object */ public final ImmutableServiceMethod withDescription(@Nullable String value) { if (Objects.equal(this.description, value)) return this; return new ImmutableServiceMethod(this.name, value, this.argTypeId, this.returnTypeId, this.options); } /** * Copy the current immutable object by setting a value for the {@link ServiceMethod#argTypeId() argTypeId} attribute. * An equals check used to prevent copying of the same value by returning {@code this}. * @param value A new value for argTypeId * @return A modified copy of the {@code this} object */ public final ImmutableServiceMethod withArgTypeId(String value) { if (this.argTypeId.equals(value)) return this; String newValue = Preconditions.checkNotNull(value, "argTypeId"); return new ImmutableServiceMethod(this.name, this.description, newValue, this.returnTypeId, this.options); } /** * Copy the current immutable object by setting a value for the {@link ServiceMethod#returnTypeId() returnTypeId} attribute. * An equals check used to prevent copying of the same value by returning {@code this}. * @param value A new value for returnTypeId * @return A modified copy of the {@code this} object */ public final ImmutableServiceMethod withReturnTypeId(String value) { if (this.returnTypeId.equals(value)) return this; String newValue = Preconditions.checkNotNull(value, "returnTypeId"); return new ImmutableServiceMethod(this.name, this.description, this.argTypeId, newValue, this.options); } /** * Copy the current immutable object by replacing the {@link ServiceMethod#options() options} map with the specified map. * Nulls are not permitted as keys or values. * A shallow reference equality check is used to prevent copying of the same value by returning {@code this}. * @param entries The entries to be added to the options map * @return A modified copy of {@code this} object */ public final ImmutableServiceMethod withOptions(Map entries) { if (this.options == entries) return this; ImmutableMap newValue = ImmutableMap.copyOf(entries); return new ImmutableServiceMethod(this.name, this.description, this.argTypeId, this.returnTypeId, newValue); } /** * This instance is equal to all instances of {@code ImmutableServiceMethod} that have 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 ImmutableServiceMethod && equalTo((ImmutableServiceMethod) another); } private boolean equalTo(ImmutableServiceMethod another) { return name.equals(another.name) && Objects.equal(description, another.description) && argTypeId.equals(another.argTypeId) && returnTypeId.equals(another.returnTypeId) && options.equals(another.options); } /** * Computes a hash code from attributes: {@code name}, {@code description}, {@code argTypeId}, {@code returnTypeId}, {@code options}. * @return hashCode value */ @Override public int hashCode() { int h = 5381; h += (h << 5) + name.hashCode(); h += (h << 5) + Objects.hashCode(description); h += (h << 5) + argTypeId.hashCode(); h += (h << 5) + returnTypeId.hashCode(); h += (h << 5) + options.hashCode(); return h; } /** * Prints the immutable value {@code ServiceMethod} with attribute values. * @return A string representation of the value */ @Override public String toString() { return MoreObjects.toStringHelper("ServiceMethod") .omitNullValues() .add("name", name) .add("description", description) .add("argTypeId", argTypeId) .add("returnTypeId", returnTypeId) .add("options", options) .toString(); } /** * Utility type used to correctly read immutable object from JSON representation. * @deprecated Do not use this type directly, it exists only for the Jackson-binding infrastructure */ @Deprecated @JsonDeserialize @JsonAutoDetect(fieldVisibility = JsonAutoDetect.Visibility.NONE) static final class Json implements ServiceMethod { @Nullable String name; @Nullable String description; @Nullable String argTypeId; @Nullable String returnTypeId; @Nullable Map options; @JsonProperty("name") public void setName(String name) { this.name = name; } @JsonProperty("description") public void setDescription(@Nullable String description) { this.description = description; } @JsonProperty("argTypeId") public void setArgTypeId(String argTypeId) { this.argTypeId = argTypeId; } @JsonProperty("returnTypeId") public void setReturnTypeId(String returnTypeId) { this.returnTypeId = returnTypeId; } @JsonProperty("options") public void setOptions(Map options) { this.options = options; } @Override public String name() { throw new UnsupportedOperationException(); } @Override public String description() { throw new UnsupportedOperationException(); } @Override public String argTypeId() { throw new UnsupportedOperationException(); } @Override public String returnTypeId() { throw new UnsupportedOperationException(); } @Override public Map options() { throw new UnsupportedOperationException(); } } /** * @param json A JSON-bindable data structure * @return An immutable value type * @deprecated Do not use this method directly, it exists only for the Jackson-binding infrastructure */ @Deprecated @JsonCreator(mode = JsonCreator.Mode.DELEGATING) static ImmutableServiceMethod fromJson(Json json) { ImmutableServiceMethod.Builder builder = ImmutableServiceMethod.builder(); if (json.name != null) { builder.name(json.name); } if (json.description != null) { builder.description(json.description); } if (json.argTypeId != null) { builder.argTypeId(json.argTypeId); } if (json.returnTypeId != null) { builder.returnTypeId(json.returnTypeId); } if (json.options != null) { builder.putAllOptions(json.options); } return builder.build(); } /** * Creates an immutable copy of a {@link ServiceMethod} value. * Uses accessors to get values to initialize the new immutable instance. * If an instance is already immutable, it is returned as is. * @param instance The instance to copy * @return A copied immutable ServiceMethod instance */ public static ImmutableServiceMethod copyOf(ServiceMethod instance) { if (instance instanceof ImmutableServiceMethod) { return (ImmutableServiceMethod) instance; } return ImmutableServiceMethod.builder() .from(instance) .build(); } /** * Creates a builder for {@link ImmutableServiceMethod ImmutableServiceMethod}. * @return A new ImmutableServiceMethod builder */ public static ImmutableServiceMethod.Builder builder() { return new ImmutableServiceMethod.Builder(); } /** * Builds instances of type {@link ImmutableServiceMethod ImmutableServiceMethod}. * Initialize attributes and then invoke the {@link #build()} method to create an * immutable instance. *

{@code Builder} is not thread-safe and generally should not be stored in a field or collection, * but instead used immediately to create instances. */ @NotThreadSafe public static final class Builder { private static final long INIT_BIT_NAME = 0x1L; private static final long INIT_BIT_ARG_TYPE_ID = 0x2L; private static final long INIT_BIT_RETURN_TYPE_ID = 0x4L; private long initBits = 0x7L; private @Nullable String name; private @Nullable String description; private @Nullable String argTypeId; private @Nullable String returnTypeId; private ImmutableMap.Builder options = ImmutableMap.builder(); private Builder() { } /** * Fill a builder with attribute values from the provided {@code ServiceMethod} instance. * Regular attribute values will be replaced with those from the given instance. * Absent optional values will not replace present values. * Collection elements and entries will be added, not replaced. * @param instance The instance from which to copy values * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue public final Builder from(ServiceMethod instance) { Preconditions.checkNotNull(instance, "instance"); name(instance.name()); @Nullable String descriptionValue = instance.description(); if (descriptionValue != null) { description(descriptionValue); } argTypeId(instance.argTypeId()); returnTypeId(instance.returnTypeId()); putAllOptions(instance.options()); return this; } /** * Initializes the value for the {@link ServiceMethod#name() name} attribute. * @param name The value for name * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue @JsonProperty("name") public final Builder name(String name) { this.name = Preconditions.checkNotNull(name, "name"); initBits &= ~INIT_BIT_NAME; return this; } /** * Initializes the value for the {@link ServiceMethod#description() description} attribute. * @param description The value for description (can be {@code null}) * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue @JsonProperty("description") public final Builder description(@Nullable String description) { this.description = description; return this; } /** * Initializes the value for the {@link ServiceMethod#argTypeId() argTypeId} attribute. * @param argTypeId The value for argTypeId * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue @JsonProperty("argTypeId") public final Builder argTypeId(String argTypeId) { this.argTypeId = Preconditions.checkNotNull(argTypeId, "argTypeId"); initBits &= ~INIT_BIT_ARG_TYPE_ID; return this; } /** * Initializes the value for the {@link ServiceMethod#returnTypeId() returnTypeId} attribute. * @param returnTypeId The value for returnTypeId * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue @JsonProperty("returnTypeId") public final Builder returnTypeId(String returnTypeId) { this.returnTypeId = Preconditions.checkNotNull(returnTypeId, "returnTypeId"); initBits &= ~INIT_BIT_RETURN_TYPE_ID; return this; } /** * Put one entry to the {@link ServiceMethod#options() options} map. * @param key The key in the options map * @param value The associated value in the options map * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue public final Builder putOptions(String key, Object value) { this.options.put(key, value); return this; } /** * Put one entry to the {@link ServiceMethod#options() options} map. Nulls are not permitted * @param entry The key and value entry * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue public final Builder putOptions(Map.Entry entry) { this.options.put(entry); return this; } /** * Sets or replaces all mappings from the specified map as entries for the {@link ServiceMethod#options() options} map. Nulls are not permitted * @param options The entries that will be added to the options map * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue @JsonProperty("options") public final Builder options(Map options) { this.options = ImmutableMap.builder(); return putAllOptions(options); } /** * Put all mappings from the specified map as entries to {@link ServiceMethod#options() options} map. Nulls are not permitted * @param options The entries that will be added to the options map * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue public final Builder putAllOptions(Map options) { this.options.putAll(options); return this; } /** * Builds a new {@link ImmutableServiceMethod ImmutableServiceMethod}. * @return An immutable instance of ServiceMethod * @throws java.lang.IllegalStateException if any required attributes are missing */ public ImmutableServiceMethod build() { if (initBits != 0) { throw new IllegalStateException(formatRequiredAttributesMessage()); } return new ImmutableServiceMethod(name, description, argTypeId, returnTypeId, options.build()); } private String formatRequiredAttributesMessage() { List attributes = Lists.newArrayList(); if ((initBits & INIT_BIT_NAME) != 0) attributes.add("name"); if ((initBits & INIT_BIT_ARG_TYPE_ID) != 0) attributes.add("argTypeId"); if ((initBits & INIT_BIT_RETURN_TYPE_ID) != 0) attributes.add("returnTypeId"); return "Cannot build ServiceMethod, some of required attributes are not set " + attributes; } } }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy