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

io.github.emm035.openapi.immutables.v3.parameters.QueryParameter Maven / Gradle / Ivy

package io.github.emm035.openapi.immutables.v3.parameters;

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.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonTypeInfo;
import com.google.common.base.MoreObjects;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Lists;
import com.google.common.primitives.Booleans;
import com.google.errorprone.annotations.CanIgnoreReturnValue;
import io.github.emm035.openapi.immutables.v3.examples.Example;
import io.github.emm035.openapi.immutables.v3.references.Referenceable;
import io.github.emm035.openapi.immutables.v3.schemas.Schema;
import io.github.emm035.openapi.immutables.v3.shared.Deprecatable;
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.WithMultipleExamples;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
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 AbstractQueryParameter}.
 * 

* Use the builder to create immutable instances: * {@code QueryParameter.builder()}. */ @SuppressWarnings({"all"}) @ParametersAreNonnullByDefault @Immutable @CheckReturnValue public final class QueryParameter extends AbstractQueryParameter { private final Parameter.Location in; private final @Nullable Boolean required; private final @Nullable AbstractQueryParameter.Style style; private final @Nullable Boolean explode; private final boolean requiredOrDefault; private final AbstractQueryParameter.Style styleOrDefault; private final boolean explodeOrDefault; private final @Nullable Boolean allowReserved; private final @Nullable Boolean allowEmptyValue; private final String name; private final Referenceable schema; private final @Nullable Object getDefault; private final ImmutableMap examples; private final @Nullable Boolean deprecated; private final @Nullable String description; private final ImmutableMap extensions; private final boolean referential; private QueryParameter( @Nullable Boolean required, @Nullable AbstractQueryParameter.Style style, @Nullable Boolean explode, @Nullable Boolean allowReserved, @Nullable Boolean allowEmptyValue, String name, Referenceable schema, @Nullable Object getDefault, ImmutableMap examples, @Nullable Boolean deprecated, @Nullable String description, ImmutableMap extensions) { this.required = required; this.style = style; this.explode = explode; this.allowReserved = allowReserved; this.allowEmptyValue = allowEmptyValue; this.name = name; this.schema = schema; this.getDefault = getDefault; this.examples = examples; this.deprecated = deprecated; this.description = description; this.extensions = extensions; this.in = initShim.getIn(); this.requiredOrDefault = initShim.getRequiredOrDefault(); this.styleOrDefault = initShim.getStyleOrDefault(); this.explodeOrDefault = initShim.getExplodeOrDefault(); this.referential = initShim.isReferential(); this.initShim = null; } private static final int STAGE_INITIALIZING = -1; private static final int STAGE_UNINITIALIZED = 0; private static final int STAGE_INITIALIZED = 1; private transient volatile InitShim initShim = new InitShim(); private final class InitShim { private Parameter.Location in; private int inBuildStage; Parameter.Location getIn() { if (inBuildStage == STAGE_INITIALIZING) throw new IllegalStateException(formatInitCycleMessage()); if (inBuildStage == STAGE_UNINITIALIZED) { inBuildStage = STAGE_INITIALIZING; this.in = Objects.requireNonNull(QueryParameter.super.getIn(), "in"); inBuildStage = STAGE_INITIALIZED; } return this.in; } private boolean requiredOrDefault; private int requiredOrDefaultBuildStage; boolean getRequiredOrDefault() { if (requiredOrDefaultBuildStage == STAGE_INITIALIZING) throw new IllegalStateException(formatInitCycleMessage()); if (requiredOrDefaultBuildStage == STAGE_UNINITIALIZED) { requiredOrDefaultBuildStage = STAGE_INITIALIZING; this.requiredOrDefault = QueryParameter.super.getRequiredOrDefault(); requiredOrDefaultBuildStage = STAGE_INITIALIZED; } return this.requiredOrDefault; } private AbstractQueryParameter.Style styleOrDefault; private int styleOrDefaultBuildStage; AbstractQueryParameter.Style getStyleOrDefault() { if (styleOrDefaultBuildStage == STAGE_INITIALIZING) throw new IllegalStateException(formatInitCycleMessage()); if (styleOrDefaultBuildStage == STAGE_UNINITIALIZED) { styleOrDefaultBuildStage = STAGE_INITIALIZING; this.styleOrDefault = Objects.requireNonNull(QueryParameter.super.getStyleOrDefault(), "styleOrDefault"); styleOrDefaultBuildStage = STAGE_INITIALIZED; } return this.styleOrDefault; } private boolean explodeOrDefault; private int explodeOrDefaultBuildStage; boolean getExplodeOrDefault() { if (explodeOrDefaultBuildStage == STAGE_INITIALIZING) throw new IllegalStateException(formatInitCycleMessage()); if (explodeOrDefaultBuildStage == STAGE_UNINITIALIZED) { explodeOrDefaultBuildStage = STAGE_INITIALIZING; this.explodeOrDefault = QueryParameter.super.getExplodeOrDefault(); explodeOrDefaultBuildStage = STAGE_INITIALIZED; } return this.explodeOrDefault; } private boolean referential; private int referentialBuildStage; boolean isReferential() { if (referentialBuildStage == STAGE_INITIALIZING) throw new IllegalStateException(formatInitCycleMessage()); if (referentialBuildStage == STAGE_UNINITIALIZED) { referentialBuildStage = STAGE_INITIALIZING; this.referential = QueryParameter.super.isReferential(); referentialBuildStage = STAGE_INITIALIZED; } return this.referential; } private String formatInitCycleMessage() { ArrayList attributes = Lists.newArrayList(); if (inBuildStage == STAGE_INITIALIZING) attributes.add("in"); if (requiredOrDefaultBuildStage == STAGE_INITIALIZING) attributes.add("requiredOrDefault"); if (styleOrDefaultBuildStage == STAGE_INITIALIZING) attributes.add("styleOrDefault"); if (explodeOrDefaultBuildStage == STAGE_INITIALIZING) attributes.add("explodeOrDefault"); if (referentialBuildStage == STAGE_INITIALIZING) attributes.add("referential"); return "Cannot build QueryParameter, attribute initializers form cycle" + attributes; } } /** * @return The computed-at-construction value of the {@code in} attribute */ @JsonProperty("in") @Override public Parameter.Location getIn() { InitShim shim = this.initShim; return shim != null ? shim.getIn() : this.in; } /** * @return The value of the {@code required} attribute */ @JsonProperty("required") @Override public Optional getRequired() { return Optional.ofNullable(required); } /** * @return The value of the {@code style} attribute */ @JsonProperty("style") @Override public Optional getStyle() { return Optional.ofNullable(style); } /** * @return The value of the {@code explode} attribute */ @JsonProperty("explode") @Override public Optional getExplode() { return Optional.ofNullable(explode); } /** * @return The computed-at-construction value of the {@code requiredOrDefault} attribute */ @JsonProperty("requiredOrDefault") @JsonIgnore @Override public boolean getRequiredOrDefault() { InitShim shim = this.initShim; return shim != null ? shim.getRequiredOrDefault() : this.requiredOrDefault; } /** * @return The computed-at-construction value of the {@code styleOrDefault} attribute */ @JsonProperty("styleOrDefault") @JsonIgnore @Override public AbstractQueryParameter.Style getStyleOrDefault() { InitShim shim = this.initShim; return shim != null ? shim.getStyleOrDefault() : this.styleOrDefault; } /** * @return The computed-at-construction value of the {@code explodeOrDefault} attribute */ @JsonProperty("explodeOrDefault") @JsonIgnore @Override public boolean getExplodeOrDefault() { InitShim shim = this.initShim; return shim != null ? shim.getExplodeOrDefault() : this.explodeOrDefault; } /** * @return The value of the {@code allowReserved} attribute */ @JsonProperty("allowReserved") @Override public Optional getAllowReserved() { return Optional.ofNullable(allowReserved); } /** * @return The value of the {@code allowEmptyValue} attribute */ @JsonProperty("allowEmptyValue") @Override public Optional getAllowEmptyValue() { return Optional.ofNullable(allowEmptyValue); } /** * @return The value of the {@code name} attribute */ @JsonProperty("name") @Override public String getName() { return name; } /** * @return The value of the {@code schema} attribute */ @JsonProperty("schema") @Override public Referenceable getSchema() { return schema; } /** * @return The value of the {@code getDefault} attribute */ @JsonProperty("default") @Override public Optional getDefault() { return Optional.ofNullable(getDefault); } /** * @return The value of the {@code examples} attribute */ @JsonProperty("examples") @JsonInclude(JsonInclude.Include.NON_EMPTY) @Override public ImmutableMap getExamples() { return examples; } /** * @return The value of the {@code deprecated} attribute */ @JsonProperty("deprecated") @Override public Optional getDeprecated() { return Optional.ofNullable(deprecated); } /** * @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() { InitShim shim = this.initShim; return shim != null ? shim.isReferential() : this.referential; } /** * Copy the current immutable object by setting a present value for the optional {@link AbstractQueryParameter#getRequired() required} attribute. * @param value The value for required, {@code null} is accepted as {@code java.util.Optional.empty()} * @return A modified copy of {@code this} object */ public final QueryParameter withRequired(@Nullable Boolean value) { @Nullable Boolean newValue = value; if (Objects.equals(this.required, newValue)) return this; return validate(new QueryParameter( newValue, this.style, this.explode, this.allowReserved, this.allowEmptyValue, this.name, this.schema, this.getDefault, this.examples, this.deprecated, this.description, this.extensions)); } /** * Copy the current immutable object by setting an optional value for the {@link AbstractQueryParameter#getRequired() required} 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 required * @return A modified copy of {@code this} object */ public final QueryParameter withRequired(Optional optional) { @Nullable Boolean value = optional.orElse(null); if (Objects.equals(this.required, value)) return this; return validate(new QueryParameter( value, this.style, this.explode, this.allowReserved, this.allowEmptyValue, this.name, this.schema, this.getDefault, this.examples, this.deprecated, this.description, this.extensions)); } /** * Copy the current immutable object by setting a present value for the optional {@link AbstractQueryParameter#getStyle() style} attribute. * @param value The value for style, {@code null} is accepted as {@code java.util.Optional.empty()} * @return A modified copy of {@code this} object */ public final QueryParameter withStyle(@Nullable AbstractQueryParameter.Style value) { @Nullable AbstractQueryParameter.Style newValue = value; if (this.style == newValue) return this; return validate(new QueryParameter( this.required, newValue, this.explode, this.allowReserved, this.allowEmptyValue, this.name, this.schema, this.getDefault, this.examples, this.deprecated, this.description, this.extensions)); } /** * Copy the current immutable object by setting an optional value for the {@link AbstractQueryParameter#getStyle() style} 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 style * @return A modified copy of {@code this} object */ public final QueryParameter withStyle(Optional optional) { @Nullable AbstractQueryParameter.Style value = optional.orElse(null); if (Objects.equals(this.style, value)) return this; return validate(new QueryParameter( this.required, value, this.explode, this.allowReserved, this.allowEmptyValue, this.name, this.schema, this.getDefault, this.examples, this.deprecated, this.description, this.extensions)); } /** * Copy the current immutable object by setting a present value for the optional {@link AbstractQueryParameter#getExplode() explode} attribute. * @param value The value for explode, {@code null} is accepted as {@code java.util.Optional.empty()} * @return A modified copy of {@code this} object */ public final QueryParameter withExplode(@Nullable Boolean value) { @Nullable Boolean newValue = value; if (Objects.equals(this.explode, newValue)) return this; return validate(new QueryParameter( this.required, this.style, newValue, this.allowReserved, this.allowEmptyValue, this.name, this.schema, this.getDefault, this.examples, this.deprecated, this.description, this.extensions)); } /** * Copy the current immutable object by setting an optional value for the {@link AbstractQueryParameter#getExplode() explode} 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 explode * @return A modified copy of {@code this} object */ public final QueryParameter withExplode(Optional optional) { @Nullable Boolean value = optional.orElse(null); if (Objects.equals(this.explode, value)) return this; return validate(new QueryParameter( this.required, this.style, value, this.allowReserved, this.allowEmptyValue, this.name, this.schema, this.getDefault, this.examples, this.deprecated, this.description, this.extensions)); } /** * Copy the current immutable object by setting a present value for the optional {@link AbstractQueryParameter#getAllowReserved() allowReserved} attribute. * @param value The value for allowReserved, {@code null} is accepted as {@code java.util.Optional.empty()} * @return A modified copy of {@code this} object */ public final QueryParameter withAllowReserved(@Nullable Boolean value) { @Nullable Boolean newValue = value; if (Objects.equals(this.allowReserved, newValue)) return this; return validate(new QueryParameter( this.required, this.style, this.explode, newValue, this.allowEmptyValue, this.name, this.schema, this.getDefault, this.examples, this.deprecated, this.description, this.extensions)); } /** * Copy the current immutable object by setting an optional value for the {@link AbstractQueryParameter#getAllowReserved() allowReserved} 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 allowReserved * @return A modified copy of {@code this} object */ public final QueryParameter withAllowReserved(Optional optional) { @Nullable Boolean value = optional.orElse(null); if (Objects.equals(this.allowReserved, value)) return this; return validate(new QueryParameter( this.required, this.style, this.explode, value, this.allowEmptyValue, this.name, this.schema, this.getDefault, this.examples, this.deprecated, this.description, this.extensions)); } /** * Copy the current immutable object by setting a present value for the optional {@link AbstractQueryParameter#getAllowEmptyValue() allowEmptyValue} attribute. * @param value The value for allowEmptyValue, {@code null} is accepted as {@code java.util.Optional.empty()} * @return A modified copy of {@code this} object */ public final QueryParameter withAllowEmptyValue(@Nullable Boolean value) { @Nullable Boolean newValue = value; if (Objects.equals(this.allowEmptyValue, newValue)) return this; return validate(new QueryParameter( this.required, this.style, this.explode, this.allowReserved, newValue, this.name, this.schema, this.getDefault, this.examples, this.deprecated, this.description, this.extensions)); } /** * Copy the current immutable object by setting an optional value for the {@link AbstractQueryParameter#getAllowEmptyValue() allowEmptyValue} 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 allowEmptyValue * @return A modified copy of {@code this} object */ public final QueryParameter withAllowEmptyValue(Optional optional) { @Nullable Boolean value = optional.orElse(null); if (Objects.equals(this.allowEmptyValue, value)) return this; return validate(new QueryParameter( this.required, this.style, this.explode, this.allowReserved, value, this.name, this.schema, this.getDefault, this.examples, this.deprecated, this.description, this.extensions)); } /** * Copy the current immutable object by setting a value for the {@link AbstractQueryParameter#getName() 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 QueryParameter withName(String value) { if (this.name.equals(value)) return this; String newValue = Objects.requireNonNull(value, "name"); return validate(new QueryParameter( this.required, this.style, this.explode, this.allowReserved, this.allowEmptyValue, newValue, this.schema, this.getDefault, this.examples, this.deprecated, this.description, this.extensions)); } /** * Copy the current immutable object by setting a value for the {@link AbstractQueryParameter#getSchema() schema} attribute. * A shallow reference equality check is used to prevent copying of the same value by returning {@code this}. * @param value A new value for schema * @return A modified copy of the {@code this} object */ public final QueryParameter withSchema(Referenceable value) { if (this.schema == value) return this; Referenceable newValue = Objects.requireNonNull(value, "schema"); return validate(new QueryParameter( this.required, this.style, this.explode, this.allowReserved, this.allowEmptyValue, this.name, newValue, this.getDefault, this.examples, this.deprecated, this.description, this.extensions)); } /** * Copy the current immutable object by setting a present value for the optional {@link AbstractQueryParameter#getDefault() default} attribute. * @param value The value for getDefault, {@code null} is accepted as {@code java.util.Optional.empty()} * @return A modified copy of {@code this} object */ public final QueryParameter withDefault(@Nullable Object value) { @Nullable Object newValue = value; if (this.getDefault == newValue) return this; return validate(new QueryParameter( this.required, this.style, this.explode, this.allowReserved, this.allowEmptyValue, this.name, this.schema, newValue, this.examples, this.deprecated, this.description, this.extensions)); } /** * Copy the current immutable object by setting an optional value for the {@link AbstractQueryParameter#getDefault() default} attribute. * A shallow reference equality check is used on unboxed optional value to prevent copying of the same value by returning {@code this}. * @param optional A value for getDefault * @return A modified copy of {@code this} object */ public final QueryParameter withDefault(Optional optional) { @Nullable Object value = optional.orElse(null); if (this.getDefault == value) return this; return validate(new QueryParameter( this.required, this.style, this.explode, this.allowReserved, this.allowEmptyValue, this.name, this.schema, value, this.examples, this.deprecated, this.description, this.extensions)); } /** * Copy the current immutable object by replacing the {@link AbstractQueryParameter#getExamples() examples} 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 examples map * @return A modified copy of {@code this} object */ public final QueryParameter withExamples(Map entries) { if (this.examples == entries) return this; ImmutableMap newValue = ImmutableMap.copyOf(entries); return validate(new QueryParameter( this.required, this.style, this.explode, this.allowReserved, this.allowEmptyValue, this.name, this.schema, this.getDefault, newValue, this.deprecated, this.description, this.extensions)); } /** * Copy the current immutable object by setting a present value for the optional {@link AbstractQueryParameter#getDeprecated() deprecated} attribute. * @param value The value for deprecated, {@code null} is accepted as {@code java.util.Optional.empty()} * @return A modified copy of {@code this} object */ public final QueryParameter withDeprecated(@Nullable Boolean value) { @Nullable Boolean newValue = value; if (Objects.equals(this.deprecated, newValue)) return this; return validate(new QueryParameter( this.required, this.style, this.explode, this.allowReserved, this.allowEmptyValue, this.name, this.schema, this.getDefault, this.examples, newValue, this.description, this.extensions)); } /** * Copy the current immutable object by setting an optional value for the {@link AbstractQueryParameter#getDeprecated() deprecated} 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 deprecated * @return A modified copy of {@code this} object */ public final QueryParameter withDeprecated(Optional optional) { @Nullable Boolean value = optional.orElse(null); if (Objects.equals(this.deprecated, value)) return this; return validate(new QueryParameter( this.required, this.style, this.explode, this.allowReserved, this.allowEmptyValue, this.name, this.schema, this.getDefault, this.examples, value, this.description, this.extensions)); } /** * Copy the current immutable object by setting a present value for the optional {@link AbstractQueryParameter#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 QueryParameter withDescription(@Nullable String value) { @Nullable String newValue = value; if (Objects.equals(this.description, newValue)) return this; return validate(new QueryParameter( this.required, this.style, this.explode, this.allowReserved, this.allowEmptyValue, this.name, this.schema, this.getDefault, this.examples, this.deprecated, newValue, this.extensions)); } /** * Copy the current immutable object by setting an optional value for the {@link AbstractQueryParameter#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 QueryParameter withDescription(Optional optional) { @Nullable String value = optional.orElse(null); if (Objects.equals(this.description, value)) return this; return validate(new QueryParameter( this.required, this.style, this.explode, this.allowReserved, this.allowEmptyValue, this.name, this.schema, this.getDefault, this.examples, this.deprecated, value, this.extensions)); } /** * Copy the current immutable object by replacing the {@link AbstractQueryParameter#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 QueryParameter withExtensions(Map entries) { if (this.extensions == entries) return this; ImmutableMap newValue = ImmutableMap.copyOf(entries); return validate(new QueryParameter( this.required, this.style, this.explode, this.allowReserved, this.allowEmptyValue, this.name, this.schema, this.getDefault, this.examples, this.deprecated, this.description, newValue)); } /** * This instance is equal to all instances of {@code QueryParameter} 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 QueryParameter && equalTo((QueryParameter) another); } private boolean equalTo(QueryParameter another) { return in.equals(another.in) && Objects.equals(required, another.required) && Objects.equals(style, another.style) && Objects.equals(explode, another.explode) && requiredOrDefault == another.requiredOrDefault && styleOrDefault.equals(another.styleOrDefault) && explodeOrDefault == another.explodeOrDefault && Objects.equals(allowReserved, another.allowReserved) && Objects.equals(allowEmptyValue, another.allowEmptyValue) && name.equals(another.name) && schema.equals(another.schema) && Objects.equals(getDefault, another.getDefault) && examples.equals(another.examples) && Objects.equals(deprecated, another.deprecated) && Objects.equals(description, another.description) && extensions.equals(another.extensions) && referential == another.referential; } /** * Computes a hash code from attributes: {@code in}, {@code required}, {@code style}, {@code explode}, {@code requiredOrDefault}, {@code styleOrDefault}, {@code explodeOrDefault}, {@code allowReserved}, {@code allowEmptyValue}, {@code name}, {@code schema}, {@code getDefault}, {@code examples}, {@code deprecated}, {@code description}, {@code extensions}, {@code referential}. * @return hashCode value */ @Override public int hashCode() { int h = 5381; h += (h << 5) + in.hashCode(); h += (h << 5) + Objects.hashCode(required); h += (h << 5) + Objects.hashCode(style); h += (h << 5) + Objects.hashCode(explode); h += (h << 5) + Booleans.hashCode(requiredOrDefault); h += (h << 5) + styleOrDefault.hashCode(); h += (h << 5) + Booleans.hashCode(explodeOrDefault); h += (h << 5) + Objects.hashCode(allowReserved); h += (h << 5) + Objects.hashCode(allowEmptyValue); h += (h << 5) + name.hashCode(); h += (h << 5) + schema.hashCode(); h += (h << 5) + Objects.hashCode(getDefault); h += (h << 5) + examples.hashCode(); h += (h << 5) + Objects.hashCode(deprecated); h += (h << 5) + Objects.hashCode(description); h += (h << 5) + extensions.hashCode(); h += (h << 5) + Booleans.hashCode(referential); return h; } /** * Prints the immutable value {@code QueryParameter} with attribute values. * @return A string representation of the value */ @Override public String toString() { return MoreObjects.toStringHelper("QueryParameter") .omitNullValues() .add("in", in) .add("required", required) .add("style", style) .add("explode", explode) .add("requiredOrDefault", requiredOrDefault) .add("styleOrDefault", styleOrDefault) .add("explodeOrDefault", explodeOrDefault) .add("allowReserved", allowReserved) .add("allowEmptyValue", allowEmptyValue) .add("name", name) .add("schema", schema) .add("default", getDefault) .add("examples", examples) .add("deprecated", deprecated) .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 @JsonTypeInfo(use=JsonTypeInfo.Id.NONE) @JsonAutoDetect(fieldVisibility = JsonAutoDetect.Visibility.NONE) static final class Json extends AbstractQueryParameter { @Nullable Optional required = Optional.empty(); @Nullable Optional style = Optional.empty(); @Nullable Optional explode = Optional.empty(); @Nullable Optional allowReserved = Optional.empty(); @Nullable Optional allowEmptyValue = Optional.empty(); @Nullable String name; @Nullable Referenceable schema; @Nullable Optional getDefault = Optional.empty(); @Nullable Map examples = ImmutableMap.of(); @Nullable Optional deprecated = Optional.empty(); @Nullable Optional description = Optional.empty(); final Map extensions = new HashMap(); @JsonProperty("required") public void setRequired(Optional required) { this.required = required; } @JsonProperty("style") public void setStyle(Optional style) { this.style = style; } @JsonProperty("explode") public void setExplode(Optional explode) { this.explode = explode; } @JsonProperty("allowReserved") public void setAllowReserved(Optional allowReserved) { this.allowReserved = allowReserved; } @JsonProperty("allowEmptyValue") public void setAllowEmptyValue(Optional allowEmptyValue) { this.allowEmptyValue = allowEmptyValue; } @JsonProperty("name") public void setName(String name) { this.name = name; } @JsonProperty("schema") public void setSchema(Referenceable schema) { this.schema = schema; } @JsonProperty("default") public void setDefault(Optional getDefault) { this.getDefault = getDefault; } @JsonProperty("examples") @JsonInclude(JsonInclude.Include.NON_EMPTY) public void setExamples(Map examples) { this.examples = examples; } @JsonProperty("deprecated") public void setDeprecated(Optional deprecated) { this.deprecated = deprecated; } @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 Parameter.Location getIn() { throw new UnsupportedOperationException(); } @Override public Optional getRequired() { throw new UnsupportedOperationException(); } @Override public Optional getStyle() { throw new UnsupportedOperationException(); } @Override public Optional getExplode() { throw new UnsupportedOperationException(); } @Override public boolean getRequiredOrDefault() { throw new UnsupportedOperationException(); } @Override public AbstractQueryParameter.Style getStyleOrDefault() { throw new UnsupportedOperationException(); } @Override public boolean getExplodeOrDefault() { throw new UnsupportedOperationException(); } @Override public Optional getAllowReserved() { throw new UnsupportedOperationException(); } @Override public Optional getAllowEmptyValue() { throw new UnsupportedOperationException(); } @Override public String getName() { throw new UnsupportedOperationException(); } @Override public Referenceable getSchema() { throw new UnsupportedOperationException(); } @Override public Optional getDefault() { throw new UnsupportedOperationException(); } @Override public Map getExamples() { throw new UnsupportedOperationException(); } @Override public Optional getDeprecated() { 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 QueryParameter fromJson(Json json) { QueryParameter.Builder builder = QueryParameter.builder(); if (json.required != null) { builder.setRequired(json.required); } if (json.style != null) { builder.setStyle(json.style); } if (json.explode != null) { builder.setExplode(json.explode); } if (json.allowReserved != null) { builder.setAllowReserved(json.allowReserved); } if (json.allowEmptyValue != null) { builder.setAllowEmptyValue(json.allowEmptyValue); } if (json.name != null) { builder.setName(json.name); } if (json.schema != null) { builder.setSchema(json.schema); } if (json.getDefault != null) { builder.setDefault(json.getDefault); } if (json.examples != null) { builder.putAllExamples(json.examples); } if (json.deprecated != null) { builder.setDeprecated(json.deprecated); } if (json.description != null) { builder.setDescription(json.description); } if (json.extensions != null) { builder.putAllExtensions(json.extensions); } return builder.build(); } private static QueryParameter validate(QueryParameter instance) { instance = (QueryParameter) instance.normalizeExtensions(); return instance; } /** * Creates an immutable copy of a {@link AbstractQueryParameter} 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 QueryParameter instance */ public static QueryParameter copyOf(AbstractQueryParameter instance) { if (instance instanceof QueryParameter) { return (QueryParameter) instance; } return QueryParameter.builder() .from(instance) .build(); } /** * Creates a builder for {@link QueryParameter QueryParameter}. * @return A new QueryParameter builder */ public static QueryParameter.Builder builder() { return new QueryParameter.Builder(); } /** * Builds instances of type {@link QueryParameter QueryParameter}. * 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_SCHEMA = 0x2L; private long initBits = 0x3L; private @Nullable Boolean required; private @Nullable AbstractQueryParameter.Style style; private @Nullable Boolean explode; private @Nullable Boolean allowReserved; private @Nullable Boolean allowEmptyValue; private @Nullable String name; private @Nullable Referenceable schema; private @Nullable Object getDefault; private ImmutableMap.Builder examples = ImmutableMap.builder(); private @Nullable Boolean deprecated; 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.parameters.AbstractQueryParameter} 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(AbstractQueryParameter 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.WithMultipleExamples} 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(WithMultipleExamples 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.Deprecatable} 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(Deprecatable 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.parameters.Parameter} 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(Parameter 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) { long bits = 0; if (object instanceof AbstractQueryParameter) { AbstractQueryParameter instance = (AbstractQueryParameter) object; Optional styleOptional = instance.getStyle(); if (styleOptional.isPresent()) { setStyle(styleOptional); } Optional allowReservedOptional = instance.getAllowReserved(); if (allowReservedOptional.isPresent()) { setAllowReserved(allowReservedOptional); } Optional explodeOptional = instance.getExplode(); if (explodeOptional.isPresent()) { setExplode(explodeOptional); } if ((bits & 0x1L) == 0) { Optional requiredOptional = instance.getRequired(); if (requiredOptional.isPresent()) { setRequired(requiredOptional); } bits |= 0x1L; } Optional allowEmptyValueOptional = instance.getAllowEmptyValue(); if (allowEmptyValueOptional.isPresent()) { setAllowEmptyValue(allowEmptyValueOptional); } } if (object instanceof WithMultipleExamples) { WithMultipleExamples instance = (WithMultipleExamples) object; putAllExamples(instance.getExamples()); } if (object instanceof Deprecatable) { Deprecatable instance = (Deprecatable) object; Optional deprecatedOptional = instance.getDeprecated(); if (deprecatedOptional.isPresent()) { setDeprecated(deprecatedOptional); } } if (object instanceof Parameter) { Parameter instance = (Parameter) object; setSchema(instance.getSchema()); setName(instance.getName()); Optional getDefaultOptional = instance.getDefault(); if (getDefaultOptional.isPresent()) { setDefault(getDefaultOptional); } if ((bits & 0x1L) == 0) { Optional requiredOptional = instance.getRequired(); if (requiredOptional.isPresent()) { setRequired(requiredOptional); } bits |= 0x1L; } } 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 AbstractQueryParameter#getRequired() required} to required. * @param required The value for required, {@code null} is accepted as {@code java.util.Optional.empty()} * @return {@code this} builder for chained invocation */ @CanIgnoreReturnValue public final Builder setRequired(@Nullable Boolean required) { this.required = required; return this; } /** * Initializes the optional value {@link AbstractQueryParameter#getRequired() required} to required. * @param required The value for required * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue public final Builder setRequired(Optional required) { this.required = required.orElse(null); return this; } /** * Initializes the optional value {@link AbstractQueryParameter#getStyle() style} to style. * @param style The value for style, {@code null} is accepted as {@code java.util.Optional.empty()} * @return {@code this} builder for chained invocation */ @CanIgnoreReturnValue public final Builder setStyle(@Nullable AbstractQueryParameter.Style style) { this.style = style; return this; } /** * Initializes the optional value {@link AbstractQueryParameter#getStyle() style} to style. * @param style The value for style * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue public final Builder setStyle(Optional style) { this.style = style.orElse(null); return this; } /** * Initializes the optional value {@link AbstractQueryParameter#getExplode() explode} to explode. * @param explode The value for explode, {@code null} is accepted as {@code java.util.Optional.empty()} * @return {@code this} builder for chained invocation */ @CanIgnoreReturnValue public final Builder setExplode(@Nullable Boolean explode) { this.explode = explode; return this; } /** * Initializes the optional value {@link AbstractQueryParameter#getExplode() explode} to explode. * @param explode The value for explode * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue public final Builder setExplode(Optional explode) { this.explode = explode.orElse(null); return this; } /** * Initializes the optional value {@link AbstractQueryParameter#getAllowReserved() allowReserved} to allowReserved. * @param allowReserved The value for allowReserved, {@code null} is accepted as {@code java.util.Optional.empty()} * @return {@code this} builder for chained invocation */ @CanIgnoreReturnValue public final Builder setAllowReserved(@Nullable Boolean allowReserved) { this.allowReserved = allowReserved; return this; } /** * Initializes the optional value {@link AbstractQueryParameter#getAllowReserved() allowReserved} to allowReserved. * @param allowReserved The value for allowReserved * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue public final Builder setAllowReserved(Optional allowReserved) { this.allowReserved = allowReserved.orElse(null); return this; } /** * Initializes the optional value {@link AbstractQueryParameter#getAllowEmptyValue() allowEmptyValue} to allowEmptyValue. * @param allowEmptyValue The value for allowEmptyValue, {@code null} is accepted as {@code java.util.Optional.empty()} * @return {@code this} builder for chained invocation */ @CanIgnoreReturnValue public final Builder setAllowEmptyValue(@Nullable Boolean allowEmptyValue) { this.allowEmptyValue = allowEmptyValue; return this; } /** * Initializes the optional value {@link AbstractQueryParameter#getAllowEmptyValue() allowEmptyValue} to allowEmptyValue. * @param allowEmptyValue The value for allowEmptyValue * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue public final Builder setAllowEmptyValue(Optional allowEmptyValue) { this.allowEmptyValue = allowEmptyValue.orElse(null); return this; } /** * Initializes the value for the {@link AbstractQueryParameter#getName() name} attribute. * @param name The value for name * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue public final Builder setName(String name) { this.name = Objects.requireNonNull(name, "name"); initBits &= ~INIT_BIT_NAME; return this; } /** * Initializes the value for the {@link AbstractQueryParameter#getSchema() schema} attribute. * @param schema The value for schema * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue public final Builder setSchema(Referenceable schema) { this.schema = Objects.requireNonNull(schema, "schema"); initBits &= ~INIT_BIT_SCHEMA; return this; } /** * Initializes the optional value {@link AbstractQueryParameter#getDefault() default} to getDefault. * @param getDefault The value for getDefault, {@code null} is accepted as {@code java.util.Optional.empty()} * @return {@code this} builder for chained invocation */ @CanIgnoreReturnValue public final Builder setDefault(@Nullable Object getDefault) { this.getDefault = getDefault; return this; } /** * Initializes the optional value {@link AbstractQueryParameter#getDefault() default} to getDefault. * @param getDefault The value for getDefault * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue public final Builder setDefault(Optional getDefault) { this.getDefault = getDefault.orElse(null); return this; } /** * Put one entry to the {@link AbstractQueryParameter#getExamples() examples} map. * @param key The key in the examples map * @param value The associated value in the examples map * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue public final Builder putExamples(String key, Example value) { this.examples.put(key, value); return this; } /** * Put one entry to the {@link AbstractQueryParameter#getExamples() examples} 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 putExamples(Map.Entry entry) { this.examples.put(entry); return this; } /** * Sets or replaces all mappings from the specified map as entries for the {@link AbstractQueryParameter#getExamples() examples} map. Nulls are not permitted * @param examples The entries that will be added to the examples map * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue public final Builder setExamples(Map examples) { this.examples = ImmutableMap.builder(); return putAllExamples(examples); } /** * Put all mappings from the specified map as entries to {@link AbstractQueryParameter#getExamples() examples} map. Nulls are not permitted * @param examples The entries that will be added to the examples map * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue public final Builder putAllExamples(Map examples) { this.examples.putAll(examples); return this; } /** * Initializes the optional value {@link AbstractQueryParameter#getDeprecated() deprecated} to deprecated. * @param deprecated The value for deprecated, {@code null} is accepted as {@code java.util.Optional.empty()} * @return {@code this} builder for chained invocation */ @CanIgnoreReturnValue public final Builder setDeprecated(@Nullable Boolean deprecated) { this.deprecated = deprecated; return this; } /** * Initializes the optional value {@link AbstractQueryParameter#getDeprecated() deprecated} to deprecated. * @param deprecated The value for deprecated * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue public final Builder setDeprecated(Optional deprecated) { this.deprecated = deprecated.orElse(null); return this; } /** * Initializes the optional value {@link AbstractQueryParameter#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 AbstractQueryParameter#getDescription() description} to description. * @param description The value for description * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue public final Builder setDescription(Optional description) { this.description = description.orElse(null); return this; } /** * Put one entry to the {@link AbstractQueryParameter#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 AbstractQueryParameter#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 AbstractQueryParameter#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 setExtensions(Map extensions) { this.extensions = ImmutableMap.builder(); return putAllExtensions(extensions); } /** * Put all mappings from the specified map as entries to {@link AbstractQueryParameter#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 QueryParameter QueryParameter}. * @return An immutable instance of QueryParameter * @throws java.lang.IllegalStateException if any required attributes are missing */ public QueryParameter build() { if (initBits != 0) { throw new IllegalStateException(formatRequiredAttributesMessage()); } return QueryParameter.validate(new QueryParameter( required, style, explode, allowReserved, allowEmptyValue, name, schema, getDefault, examples.build(), deprecated, description, extensions.build())); } private String formatRequiredAttributesMessage() { List attributes = Lists.newArrayList(); if ((initBits & INIT_BIT_NAME) != 0) attributes.add("name"); if ((initBits & INIT_BIT_SCHEMA) != 0) attributes.add("schema"); return "Cannot build QueryParameter, some of required attributes are not set " + attributes; } } }