Please wait. This can take some minutes ...
Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance.
Project price only 1 $
You can buy this project and download/modify it how often you want.
io.github.emm035.openapi.immutables.v3.links.IdLink Maven / Gradle / Ivy
package io.github.emm035.openapi.immutables.v3.links;
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.collect.Lists;
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 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 AbstractIdLink}.
*
* Use the builder to create immutable instances:
* {@code IdLink.builder()}.
*/
@SuppressWarnings({"all"})
@ParametersAreNonnullByDefault
@Immutable
@CheckReturnValue
public final class IdLink extends AbstractIdLink {
private final String operationId;
private final ImmutableMap parameters;
private final @Nullable Object requestBody;
private final boolean referential;
private final ImmutableMap extensions;
private final @Nullable String description;
private IdLink(
String operationId,
ImmutableMap parameters,
@Nullable Object requestBody,
ImmutableMap extensions,
@Nullable String description) {
this.operationId = operationId;
this.parameters = parameters;
this.requestBody = requestBody;
this.extensions = extensions;
this.description = description;
this.referential = super.isReferential();
}
/**
* @return The value of the {@code operationId} attribute
*/
@JsonProperty("operationId")
@Override
public String getOperationId() {
return operationId;
}
/**
* @return The value of the {@code parameters} attribute
*/
@JsonProperty("parameters")
@Override
public ImmutableMap getParameters() {
return parameters;
}
/**
* @return The value of the {@code requestBody} attribute
*/
@JsonProperty("requestBody")
@Override
public Optional getRequestBody() {
return Optional.ofNullable(requestBody);
}
/**
* @return The computed-at-construction value of the {@code referential} attribute
*/
@JsonProperty("referential")
@JsonIgnore
@Override
public boolean isReferential() {
return referential;
}
/**
* @return The value of the {@code extensions} attribute
*/
@JsonProperty("extensions")
@JsonAnyGetter
@Override
public ImmutableMap getExtensions() {
return extensions;
}
/**
* @return The value of the {@code description} attribute
*/
@JsonProperty("description")
@Override
public Optional getDescription() {
return Optional.ofNullable(description);
}
/**
* Copy the current immutable object by setting a value for the {@link AbstractIdLink#getOperationId() operationId} attribute.
* An equals check used to prevent copying of the same value by returning {@code this}.
* @param value A new value for operationId
* @return A modified copy of the {@code this} object
*/
public final IdLink withOperationId(String value) {
if (this.operationId.equals(value)) return this;
String newValue = Objects.requireNonNull(value, "operationId");
return validate(new IdLink(newValue, this.parameters, this.requestBody, this.extensions, this.description));
}
/**
* Copy the current immutable object by replacing the {@link AbstractIdLink#getParameters() parameters} 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 parameters map
* @return A modified copy of {@code this} object
*/
public final IdLink withParameters(Map entries) {
if (this.parameters == entries) return this;
ImmutableMap newValue = ImmutableMap.copyOf(entries);
return validate(new IdLink(this.operationId, newValue, this.requestBody, this.extensions, this.description));
}
/**
* Copy the current immutable object by setting a present value for the optional {@link AbstractIdLink#getRequestBody() requestBody} attribute.
* @param value The value for requestBody, {@code null} is accepted as {@code java.util.Optional.empty()}
* @return A modified copy of {@code this} object
*/
public final IdLink withRequestBody(@Nullable Object value) {
@Nullable Object newValue = value;
if (this.requestBody == newValue) return this;
return validate(new IdLink(this.operationId, this.parameters, newValue, this.extensions, this.description));
}
/**
* Copy the current immutable object by setting an optional value for the {@link AbstractIdLink#getRequestBody() requestBody} 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 requestBody
* @return A modified copy of {@code this} object
*/
public final IdLink withRequestBody(Optional extends Object> optional) {
@Nullable Object value = optional.orElse(null);
if (this.requestBody == value) return this;
return validate(new IdLink(this.operationId, this.parameters, value, this.extensions, this.description));
}
/**
* Copy the current immutable object by replacing the {@link AbstractIdLink#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 IdLink withExtensions(Map entries) {
if (this.extensions == entries) return this;
ImmutableMap newValue = ImmutableMap.copyOf(entries);
return validate(new IdLink(this.operationId, this.parameters, this.requestBody, newValue, this.description));
}
/**
* Copy the current immutable object by setting a present value for the optional {@link AbstractIdLink#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 IdLink withDescription(@Nullable String value) {
@Nullable String newValue = value;
if (Objects.equals(this.description, newValue)) return this;
return validate(new IdLink(this.operationId, this.parameters, this.requestBody, this.extensions, newValue));
}
/**
* Copy the current immutable object by setting an optional value for the {@link AbstractIdLink#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 IdLink withDescription(Optional optional) {
@Nullable String value = optional.orElse(null);
if (Objects.equals(this.description, value)) return this;
return validate(new IdLink(this.operationId, this.parameters, this.requestBody, this.extensions, value));
}
/**
* This instance is equal to all instances of {@code IdLink} 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 IdLink
&& equalTo((IdLink) another);
}
private boolean equalTo(IdLink another) {
return operationId.equals(another.operationId)
&& parameters.equals(another.parameters)
&& Objects.equals(requestBody, another.requestBody)
&& referential == another.referential
&& extensions.equals(another.extensions)
&& Objects.equals(description, another.description);
}
/**
* Computes a hash code from attributes: {@code operationId}, {@code parameters}, {@code requestBody}, {@code referential}, {@code extensions}, {@code description}.
* @return hashCode value
*/
@Override
public int hashCode() {
int h = 5381;
h += (h << 5) + operationId.hashCode();
h += (h << 5) + parameters.hashCode();
h += (h << 5) + Objects.hashCode(requestBody);
h += (h << 5) + Booleans.hashCode(referential);
h += (h << 5) + extensions.hashCode();
h += (h << 5) + Objects.hashCode(description);
return h;
}
/**
* Prints the immutable value {@code IdLink} with attribute values.
* @return A string representation of the value
*/
@Override
public String toString() {
return MoreObjects.toStringHelper("IdLink")
.omitNullValues()
.add("operationId", operationId)
.add("parameters", parameters)
.add("requestBody", requestBody)
.add("referential", referential)
.add("extensions", extensions)
.add("description", description)
.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 AbstractIdLink {
@Nullable String operationId;
@Nullable Map parameters = ImmutableMap.of();
@Nullable Optional requestBody = Optional.empty();
@Nullable Optional description = Optional.empty();
final Map extensions = new HashMap();
@JsonProperty("operationId")
public void setOperationId(String operationId) {
this.operationId = operationId;
}
@JsonProperty("parameters")
public void setParameters(Map parameters) {
this.parameters = parameters;
}
@JsonProperty("requestBody")
public void setRequestBody(Optional requestBody) {
this.requestBody = requestBody;
}
@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 String getOperationId() { throw new UnsupportedOperationException(); }
@Override
public Map getParameters() { throw new UnsupportedOperationException(); }
@Override
public Optional getRequestBody() { throw new UnsupportedOperationException(); }
@Override
public boolean isReferential() { throw new UnsupportedOperationException(); }
@Override
public Map getExtensions() { throw new UnsupportedOperationException(); }
@Override
public Optional getDescription() { 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 IdLink fromJson(Json json) {
IdLink.Builder builder = IdLink.builder();
if (json.operationId != null) {
builder.setOperationId(json.operationId);
}
if (json.parameters != null) {
builder.putAllParameters(json.parameters);
}
if (json.requestBody != null) {
builder.setRequestBody(json.requestBody);
}
if (json.extensions != null) {
builder.putAllExtensions(json.extensions);
}
if (json.description != null) {
builder.setDescription(json.description);
}
return builder.build();
}
private static IdLink validate(IdLink instance) {
instance = (IdLink) instance.normalizeExtensions();
return instance;
}
/**
* Creates an immutable copy of a {@link AbstractIdLink} 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 IdLink instance
*/
public static IdLink copyOf(AbstractIdLink instance) {
if (instance instanceof IdLink) {
return (IdLink) instance;
}
return IdLink.builder()
.from(instance)
.build();
}
/**
* Creates a builder for {@link IdLink IdLink}.
* @return A new IdLink builder
*/
public static IdLink.Builder builder() {
return new IdLink.Builder();
}
/**
* Builds instances of type {@link IdLink IdLink}.
* 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_OPERATION_ID = 0x1L;
private long initBits = 0x1L;
private @Nullable String operationId;
private ImmutableMap.Builder parameters = ImmutableMap.builder();
private @Nullable Object requestBody;
private ImmutableMap.Builder extensions = ImmutableMap.builder();
private @Nullable String description;
private Builder() {
}
/**
* Fill a builder with attribute values from the provided {@code io.github.emm035.openapi.immutables.v3.links.AbstractIdLink} 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(AbstractIdLink 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 AbstractIdLink) {
AbstractIdLink instance = (AbstractIdLink) object;
Optional requestBodyOptional = instance.getRequestBody();
if (requestBodyOptional.isPresent()) {
setRequestBody(requestBodyOptional);
}
setOperationId(instance.getOperationId());
putAllParameters(instance.getParameters());
}
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 value for the {@link AbstractIdLink#getOperationId() operationId} attribute.
* @param operationId The value for operationId
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
@JsonProperty("operationId")
public final Builder setOperationId(String operationId) {
this.operationId = Objects.requireNonNull(operationId, "operationId");
initBits &= ~INIT_BIT_OPERATION_ID;
return this;
}
/**
* Put one entry to the {@link AbstractIdLink#getParameters() parameters} map.
* @param key The key in the parameters map
* @param value The associated value in the parameters map
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final Builder putParameters(String key, Object value) {
this.parameters.put(key, value);
return this;
}
/**
* Put one entry to the {@link AbstractIdLink#getParameters() parameters} 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 putParameters(Map.Entry entry) {
this.parameters.put(entry);
return this;
}
/**
* Sets or replaces all mappings from the specified map as entries for the {@link AbstractIdLink#getParameters() parameters} map. Nulls are not permitted
* @param parameters The entries that will be added to the parameters map
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
@JsonProperty("parameters")
public final Builder setParameters(Map parameters) {
this.parameters = ImmutableMap.builder();
return putAllParameters(parameters);
}
/**
* Put all mappings from the specified map as entries to {@link AbstractIdLink#getParameters() parameters} map. Nulls are not permitted
* @param parameters The entries that will be added to the parameters map
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final Builder putAllParameters(Map parameters) {
this.parameters.putAll(parameters);
return this;
}
/**
* Initializes the optional value {@link AbstractIdLink#getRequestBody() requestBody} to requestBody.
* @param requestBody The value for requestBody, {@code null} is accepted as {@code java.util.Optional.empty()}
* @return {@code this} builder for chained invocation
*/
@CanIgnoreReturnValue
public final Builder setRequestBody(@Nullable Object requestBody) {
this.requestBody = requestBody;
return this;
}
/**
* Initializes the optional value {@link AbstractIdLink#getRequestBody() requestBody} to requestBody.
* @param requestBody The value for requestBody
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
@JsonProperty("requestBody")
public final Builder setRequestBody(Optional extends Object> requestBody) {
this.requestBody = requestBody.orElse(null);
return this;
}
/**
* Put one entry to the {@link AbstractIdLink#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 AbstractIdLink#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 AbstractIdLink#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 AbstractIdLink#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;
}
/**
* Initializes the optional value {@link AbstractIdLink#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 AbstractIdLink#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;
}
/**
* Builds a new {@link IdLink IdLink}.
* @return An immutable instance of IdLink
* @throws java.lang.IllegalStateException if any required attributes are missing
*/
public IdLink build() {
if (initBits != 0) {
throw new IllegalStateException(formatRequiredAttributesMessage());
}
return IdLink.validate(new IdLink(operationId, parameters.build(), requestBody, extensions.build(), description));
}
private String formatRequiredAttributesMessage() {
List attributes = Lists.newArrayList();
if ((initBits & INIT_BIT_OPERATION_ID) != 0) attributes.add("operationId");
return "Cannot build IdLink, some of required attributes are not set " + attributes;
}
}
}