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

io.github.emm035.openapi.immutables.v3.Paths Maven / Gradle / Ivy

The newest version!
package io.github.emm035.openapi.immutables.v3;

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 AbstractPaths}.
 * 

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





© 2015 - 2025 Weber Informatics LLC | Privacy Policy