
io.github.emm035.openapi.immutables.v3.examples.ExternalExample Maven / Gradle / Ivy
package io.github.emm035.openapi.immutables.v3.examples;
import com.fasterxml.jackson.annotation.JsonAnyGetter;
import com.fasterxml.jackson.annotation.JsonAnySetter;
import com.fasterxml.jackson.annotation.JsonAutoDetect;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.google.common.base.MoreObjects;
import com.google.common.collect.ImmutableMap;
import com.google.common.primitives.Booleans;
import com.google.errorprone.annotations.CanIgnoreReturnValue;
import io.github.emm035.openapi.immutables.v3.shared.Describable;
import io.github.emm035.openapi.immutables.v3.shared.Extensible;
import io.github.emm035.openapi.immutables.v3.shared.Summarizable;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import javax.annotation.CheckReturnValue;
import javax.annotation.Nullable;
import javax.annotation.ParametersAreNonnullByDefault;
import javax.annotation.concurrent.Immutable;
import javax.annotation.concurrent.NotThreadSafe;
/**
* Immutable implementation of {@link AbstractExternalExample}.
*
* Use the builder to create immutable instances:
* {@code ExternalExample.builder()}.
*/
@SuppressWarnings({"all"})
@ParametersAreNonnullByDefault
@Immutable
@CheckReturnValue
public final class ExternalExample
extends AbstractExternalExample {
private final @Nullable String externalValue;
private final @Nullable String summary;
private final @Nullable String description;
private final ImmutableMap extensions;
private final boolean referential;
private ExternalExample(
@Nullable String externalValue,
@Nullable String summary,
@Nullable String description,
ImmutableMap extensions) {
this.externalValue = externalValue;
this.summary = summary;
this.description = description;
this.extensions = extensions;
this.referential = super.isReferential();
}
/**
* @return The value of the {@code externalValue} attribute
*/
@JsonProperty("externalValue")
@Override
public Optional getExternalValue() {
return Optional.ofNullable(externalValue);
}
/**
* @return The value of the {@code summary} attribute
*/
@JsonProperty("summary")
@Override
public Optional getSummary() {
return Optional.ofNullable(summary);
}
/**
* @return The value of the {@code description} attribute
*/
@JsonProperty("description")
@Override
public Optional getDescription() {
return Optional.ofNullable(description);
}
/**
* @return The value of the {@code extensions} attribute
*/
@JsonProperty("extensions")
@JsonAnyGetter
@Override
public ImmutableMap getExtensions() {
return extensions;
}
/**
* @return The computed-at-construction value of the {@code referential} attribute
*/
@JsonProperty("referential")
@JsonIgnore
@Override
public boolean isReferential() {
return referential;
}
/**
* Copy the current immutable object by setting a present value for the optional {@link AbstractExternalExample#getExternalValue() externalValue} attribute.
* @param value The value for externalValue, {@code null} is accepted as {@code java.util.Optional.empty()}
* @return A modified copy of {@code this} object
*/
public final ExternalExample withExternalValue(@Nullable String value) {
@Nullable String newValue = value;
if (Objects.equals(this.externalValue, newValue)) return this;
return validate(new ExternalExample(newValue, this.summary, this.description, this.extensions));
}
/**
* Copy the current immutable object by setting an optional value for the {@link AbstractExternalExample#getExternalValue() externalValue} attribute.
* An equality check is used on inner nullable value to prevent copying of the same value by returning {@code this}.
* @param optional A value for externalValue
* @return A modified copy of {@code this} object
*/
public final ExternalExample withExternalValue(Optional optional) {
@Nullable String value = optional.orElse(null);
if (Objects.equals(this.externalValue, value)) return this;
return validate(new ExternalExample(value, this.summary, this.description, this.extensions));
}
/**
* Copy the current immutable object by setting a present value for the optional {@link AbstractExternalExample#getSummary() summary} attribute.
* @param value The value for summary, {@code null} is accepted as {@code java.util.Optional.empty()}
* @return A modified copy of {@code this} object
*/
public final ExternalExample withSummary(@Nullable String value) {
@Nullable String newValue = value;
if (Objects.equals(this.summary, newValue)) return this;
return validate(new ExternalExample(this.externalValue, newValue, this.description, this.extensions));
}
/**
* Copy the current immutable object by setting an optional value for the {@link AbstractExternalExample#getSummary() summary} attribute.
* An equality check is used on inner nullable value to prevent copying of the same value by returning {@code this}.
* @param optional A value for summary
* @return A modified copy of {@code this} object
*/
public final ExternalExample withSummary(Optional optional) {
@Nullable String value = optional.orElse(null);
if (Objects.equals(this.summary, value)) return this;
return validate(new ExternalExample(this.externalValue, value, this.description, this.extensions));
}
/**
* Copy the current immutable object by setting a present value for the optional {@link AbstractExternalExample#getDescription() description} attribute.
* @param value The value for description, {@code null} is accepted as {@code java.util.Optional.empty()}
* @return A modified copy of {@code this} object
*/
public final ExternalExample withDescription(@Nullable String value) {
@Nullable String newValue = value;
if (Objects.equals(this.description, newValue)) return this;
return validate(new ExternalExample(this.externalValue, this.summary, newValue, this.extensions));
}
/**
* Copy the current immutable object by setting an optional value for the {@link AbstractExternalExample#getDescription() description} attribute.
* An equality check is used on inner nullable value to prevent copying of the same value by returning {@code this}.
* @param optional A value for description
* @return A modified copy of {@code this} object
*/
public final ExternalExample withDescription(Optional optional) {
@Nullable String value = optional.orElse(null);
if (Objects.equals(this.description, value)) return this;
return validate(new ExternalExample(this.externalValue, this.summary, value, this.extensions));
}
/**
* Copy the current immutable object by replacing the {@link AbstractExternalExample#getExtensions() extensions} 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 extensions map
* @return A modified copy of {@code this} object
*/
public final ExternalExample withExtensions(Map entries) {
if (this.extensions == entries) return this;
ImmutableMap newValue = ImmutableMap.copyOf(entries);
return validate(new ExternalExample(this.externalValue, this.summary, this.description, newValue));
}
/**
* This instance is equal to all instances of {@code ExternalExample} 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 ExternalExample
&& equalTo((ExternalExample) another);
}
private boolean equalTo(ExternalExample another) {
return Objects.equals(externalValue, another.externalValue)
&& Objects.equals(summary, another.summary)
&& Objects.equals(description, another.description)
&& extensions.equals(another.extensions)
&& referential == another.referential;
}
/**
* Computes a hash code from attributes: {@code externalValue}, {@code summary}, {@code description}, {@code extensions}, {@code referential}.
* @return hashCode value
*/
@Override
public int hashCode() {
int h = 5381;
h += (h << 5) + Objects.hashCode(externalValue);
h += (h << 5) + Objects.hashCode(summary);
h += (h << 5) + Objects.hashCode(description);
h += (h << 5) + extensions.hashCode();
h += (h << 5) + Booleans.hashCode(referential);
return h;
}
/**
* Prints the immutable value {@code ExternalExample} with attribute values.
* @return A string representation of the value
*/
@Override
public String toString() {
return MoreObjects.toStringHelper("ExternalExample")
.omitNullValues()
.add("externalValue", externalValue)
.add("summary", summary)
.add("description", description)
.add("extensions", extensions)
.add("referential", referential)
.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 extends AbstractExternalExample {
@Nullable Optional externalValue = Optional.empty();
@Nullable Optional summary = Optional.empty();
@Nullable Optional description = Optional.empty();
final Map extensions = new HashMap();
@JsonProperty("externalValue")
public void setExternalValue(Optional externalValue) {
this.externalValue = externalValue;
}
@JsonProperty("summary")
public void setSummary(Optional summary) {
this.summary = summary;
}
@JsonProperty("description")
public void setDescription(Optional description) {
this.description = description;
}
@JsonAnySetter
public void setExtensions(String key, Object value) {
this.extensions.put(key, value);
}
@Override
public Optional getExternalValue() { throw new UnsupportedOperationException(); }
@Override
public Optional getSummary() { throw new UnsupportedOperationException(); }
@Override
public Optional getDescription() { throw new UnsupportedOperationException(); }
@Override
public Map getExtensions() { throw new UnsupportedOperationException(); }
@Override
public boolean isReferential() { 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 ExternalExample fromJson(Json json) {
ExternalExample.Builder builder = ExternalExample.builder();
if (json.externalValue != null) {
builder.setExternalValue(json.externalValue);
}
if (json.summary != null) {
builder.setSummary(json.summary);
}
if (json.description != null) {
builder.setDescription(json.description);
}
if (json.extensions != null) {
builder.putAllExtensions(json.extensions);
}
return builder.build();
}
private static ExternalExample validate(ExternalExample instance) {
instance = (ExternalExample) instance.normalizeExtensions();
return instance;
}
/**
* Creates an immutable copy of a {@link AbstractExternalExample} 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 ExternalExample instance
*/
public static ExternalExample copyOf(AbstractExternalExample instance) {
if (instance instanceof ExternalExample) {
return (ExternalExample) instance;
}
return ExternalExample.builder()
.from(instance)
.build();
}
/**
* Creates a builder for {@link ExternalExample ExternalExample}.
* @return A new ExternalExample builder
*/
public static ExternalExample.Builder builder() {
return new ExternalExample.Builder();
}
/**
* Builds instances of type {@link ExternalExample ExternalExample}.
* 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 @Nullable String externalValue;
private @Nullable String summary;
private @Nullable String description;
private ImmutableMap.Builder extensions = ImmutableMap.builder();
private Builder() {
}
/**
* Fill a builder with attribute values from the provided {@code io.github.emm035.openapi.immutables.v3.shared.Summarizable} instance.
* @param instance The instance from which to copy values
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final Builder from(Summarizable instance) {
Objects.requireNonNull(instance, "instance");
from((Object) instance);
return this;
}
/**
* Fill a builder with attribute values from the provided {@code io.github.emm035.openapi.immutables.v3.examples.AbstractExternalExample} instance.
* @param instance The instance from which to copy values
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final Builder from(AbstractExternalExample instance) {
Objects.requireNonNull(instance, "instance");
from((Object) instance);
return this;
}
/**
* Fill a builder with attribute values from the provided {@code io.github.emm035.openapi.immutables.v3.shared.Extensible} instance.
* @param instance The instance from which to copy values
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final Builder from(Extensible instance) {
Objects.requireNonNull(instance, "instance");
from((Object) instance);
return this;
}
/**
* Fill a builder with attribute values from the provided {@code io.github.emm035.openapi.immutables.v3.shared.Describable} instance.
* @param instance The instance from which to copy values
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final Builder from(Describable instance) {
Objects.requireNonNull(instance, "instance");
from((Object) instance);
return this;
}
private void from(Object object) {
if (object instanceof Summarizable) {
Summarizable instance = (Summarizable) object;
Optional summaryOptional = instance.getSummary();
if (summaryOptional.isPresent()) {
setSummary(summaryOptional);
}
}
if (object instanceof AbstractExternalExample) {
AbstractExternalExample instance = (AbstractExternalExample) object;
Optional externalValueOptional = instance.getExternalValue();
if (externalValueOptional.isPresent()) {
setExternalValue(externalValueOptional);
}
}
if (object instanceof Extensible) {
Extensible instance = (Extensible) object;
putAllExtensions(instance.getExtensions());
}
if (object instanceof Describable) {
Describable instance = (Describable) object;
Optional descriptionOptional = instance.getDescription();
if (descriptionOptional.isPresent()) {
setDescription(descriptionOptional);
}
}
}
/**
* Initializes the optional value {@link AbstractExternalExample#getExternalValue() externalValue} to externalValue.
* @param externalValue The value for externalValue, {@code null} is accepted as {@code java.util.Optional.empty()}
* @return {@code this} builder for chained invocation
*/
@CanIgnoreReturnValue
public final Builder setExternalValue(@Nullable String externalValue) {
this.externalValue = externalValue;
return this;
}
/**
* Initializes the optional value {@link AbstractExternalExample#getExternalValue() externalValue} to externalValue.
* @param externalValue The value for externalValue
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
@JsonProperty("externalValue")
public final Builder setExternalValue(Optional externalValue) {
this.externalValue = externalValue.orElse(null);
return this;
}
/**
* Initializes the optional value {@link AbstractExternalExample#getSummary() summary} to summary.
* @param summary The value for summary, {@code null} is accepted as {@code java.util.Optional.empty()}
* @return {@code this} builder for chained invocation
*/
@CanIgnoreReturnValue
public final Builder setSummary(@Nullable String summary) {
this.summary = summary;
return this;
}
/**
* Initializes the optional value {@link AbstractExternalExample#getSummary() summary} to summary.
* @param summary The value for summary
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
@JsonProperty("summary")
public final Builder setSummary(Optional summary) {
this.summary = summary.orElse(null);
return this;
}
/**
* Initializes the optional value {@link AbstractExternalExample#getDescription() description} to description.
* @param description The value for description, {@code null} is accepted as {@code java.util.Optional.empty()}
* @return {@code this} builder for chained invocation
*/
@CanIgnoreReturnValue
public final Builder setDescription(@Nullable String description) {
this.description = description;
return this;
}
/**
* Initializes the optional value {@link AbstractExternalExample#getDescription() description} to description.
* @param description The value for description
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
@JsonProperty("description")
public final Builder setDescription(Optional description) {
this.description = description.orElse(null);
return this;
}
/**
* Put one entry to the {@link AbstractExternalExample#getExtensions() extensions} map.
* @param key The key in the extensions map
* @param value The associated value in the extensions map
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
@JsonAnySetter
public final Builder putExtensions(String key, Object value) {
this.extensions.put(key, value);
return this;
}
/**
* Put one entry to the {@link AbstractExternalExample#getExtensions() extensions} 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 putExtensions(Map.Entry entry) {
this.extensions.put(entry);
return this;
}
/**
* Sets or replaces all mappings from the specified map as entries for the {@link AbstractExternalExample#getExtensions() extensions} map. Nulls are not permitted
* @param extensions The entries that will be added to the extensions map
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
@JsonProperty("extensions")
public final Builder setExtensions(Map extensions) {
this.extensions = ImmutableMap.builder();
return putAllExtensions(extensions);
}
/**
* Put all mappings from the specified map as entries to {@link AbstractExternalExample#getExtensions() extensions} map. Nulls are not permitted
* @param extensions The entries that will be added to the extensions map
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final Builder putAllExtensions(Map extensions) {
this.extensions.putAll(extensions);
return this;
}
/**
* Builds a new {@link ExternalExample ExternalExample}.
* @return An immutable instance of ExternalExample
* @throws java.lang.IllegalStateException if any required attributes are missing
*/
public ExternalExample build() {
return ExternalExample.validate(new ExternalExample(externalValue, summary, description, extensions.build()));
}
}
}