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

io.github.emm035.openapi.immutables.v3.content.Content Maven / Gradle / Ivy

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

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.JsonProperty;
import com.fasterxml.jackson.annotation.JsonUnwrapped;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.google.common.base.MoreObjects;
import com.google.common.collect.ImmutableMap;
import com.google.errorprone.annotations.CanIgnoreReturnValue;
import io.github.emm035.openapi.immutables.v3.shared.Extensible;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
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 AbstractContent}.
 * 

* Use the builder to create immutable instances: * {@code Content.builder()}. */ @SuppressWarnings({"all"}) @ParametersAreNonnullByDefault @Immutable @CheckReturnValue public final class Content extends AbstractContent { private final ImmutableMap mediaTypes; private final ImmutableMap extensions; private Content( ImmutableMap mediaTypes, ImmutableMap extensions) { this.mediaTypes = mediaTypes; this.extensions = extensions; } /** * @return The value of the {@code mediaTypes} attribute */ @JsonProperty("mediaTypes") @JsonUnwrapped @Override public ImmutableMap getMediaTypes() { return mediaTypes; } /** * @return The value of the {@code extensions} attribute */ @JsonProperty("extensions") @JsonAnyGetter @Override public ImmutableMap getExtensions() { return extensions; } /** * Copy the current immutable object by replacing the {@link AbstractContent#getMediaTypes() mediaTypes} 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 mediaTypes map * @return A modified copy of {@code this} object */ public final Content withMediaTypes(Map entries) { if (this.mediaTypes == entries) return this; ImmutableMap newValue = ImmutableMap.copyOf(entries); return new Content(newValue, this.extensions); } /** * Copy the current immutable object by replacing the {@link AbstractContent#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 Content withExtensions(Map entries) { if (this.extensions == entries) return this; ImmutableMap newValue = ImmutableMap.copyOf(entries); return new Content(this.mediaTypes, newValue); } /** * This instance is equal to all instances of {@code Content} 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 Content && equalTo((Content) another); } private boolean equalTo(Content another) { return mediaTypes.equals(another.mediaTypes) && extensions.equals(another.extensions); } /** * Computes a hash code from attributes: {@code mediaTypes}, {@code extensions}. * @return hashCode value */ @Override public int hashCode() { int h = 5381; h += (h << 5) + mediaTypes.hashCode(); h += (h << 5) + extensions.hashCode(); return h; } /** * Prints the immutable value {@code Content} with attribute values. * @return A string representation of the value */ @Override public String toString() { return MoreObjects.toStringHelper("Content") .omitNullValues() .add("mediaTypes", mediaTypes) .add("extensions", extensions) .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 AbstractContent { @Nullable Map mediaTypes = ImmutableMap.of(); final Map extensions = new HashMap(); @JsonProperty("mediaTypes") @JsonUnwrapped public void setMediaTypes(Map mediaTypes) { this.mediaTypes = mediaTypes; } @JsonAnySetter public void setExtensions(String key, Object value) { this.extensions.put(key, value); } @Override public Map getMediaTypes() { throw new UnsupportedOperationException(); } @Override public Map getExtensions() { 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 Content fromJson(Json json) { Content.Builder builder = Content.builder(); if (json.mediaTypes != null) { builder.putAllMediaTypes(json.mediaTypes); } if (json.extensions != null) { builder.putAllExtensions(json.extensions); } return builder.build(); } /** * Creates an immutable copy of a {@link AbstractContent} 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 Content instance */ public static Content copyOf(AbstractContent instance) { if (instance instanceof Content) { return (Content) instance; } return Content.builder() .from(instance) .build(); } /** * Creates a builder for {@link Content Content}. * @return A new Content builder */ public static Content.Builder builder() { return new Content.Builder(); } /** * Builds instances of type {@link Content Content}. * 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 ImmutableMap.Builder mediaTypes = ImmutableMap.builder(); private ImmutableMap.Builder extensions = ImmutableMap.builder(); private Builder() { } /** * Fill a builder with attribute values from the provided {@code io.github.emm035.openapi.immutables.v3.content.AbstractContent} 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(AbstractContent 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; } private void from(Object object) { if (object instanceof AbstractContent) { AbstractContent instance = (AbstractContent) object; putAllMediaTypes(instance.getMediaTypes()); } if (object instanceof Extensible) { Extensible instance = (Extensible) object; putAllExtensions(instance.getExtensions()); } } /** * Put one entry to the {@link AbstractContent#getMediaTypes() mediaTypes} map. * @param key The key in the mediaTypes map * @param value The associated value in the mediaTypes map * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue public final Builder putMediaTypes(String key, MediaType value) { this.mediaTypes.put(key, value); return this; } /** * Put one entry to the {@link AbstractContent#getMediaTypes() mediaTypes} 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 putMediaTypes(Map.Entry entry) { this.mediaTypes.put(entry); return this; } /** * Sets or replaces all mappings from the specified map as entries for the {@link AbstractContent#getMediaTypes() mediaTypes} map. Nulls are not permitted * @param mediaTypes The entries that will be added to the mediaTypes map * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue @JsonProperty("mediaTypes") @JsonUnwrapped public final Builder setMediaTypes(Map mediaTypes) { this.mediaTypes = ImmutableMap.builder(); return putAllMediaTypes(mediaTypes); } /** * Put all mappings from the specified map as entries to {@link AbstractContent#getMediaTypes() mediaTypes} map. Nulls are not permitted * @param mediaTypes The entries that will be added to the mediaTypes map * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue public final Builder putAllMediaTypes(Map mediaTypes) { this.mediaTypes.putAll(mediaTypes); return this; } /** * Put one entry to the {@link AbstractContent#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 AbstractContent#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 AbstractContent#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 AbstractContent#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 Content Content}. * @return An immutable instance of Content * @throws java.lang.IllegalStateException if any required attributes are missing */ public Content build() { return new Content(mediaTypes.build(), extensions.build()); } } }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy