
io.github.emm035.openapi.immutables.v3.security.flows.ImplicitFlow Maven / Gradle / Ivy
package io.github.emm035.openapi.immutables.v3.security.flows;
import com.fasterxml.jackson.annotation.JsonAutoDetect;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.google.common.base.MoreObjects;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Lists;
import com.google.errorprone.annotations.CanIgnoreReturnValue;
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 ImplicitFlowIF}.
*
* Use the builder to create immutable instances:
* {@code ImplicitFlow.builder()}.
*/
@SuppressWarnings({"all"})
@ParametersAreNonnullByDefault
@Immutable
@CheckReturnValue
public final class ImplicitFlow
implements ImplicitFlowIF {
private final String authorizationUrl;
private final @Nullable String refreshUrl;
private final ImmutableMap scopes;
private ImplicitFlow(
String authorizationUrl,
@Nullable String refreshUrl,
ImmutableMap scopes) {
this.authorizationUrl = authorizationUrl;
this.refreshUrl = refreshUrl;
this.scopes = scopes;
}
/**
* @return The value of the {@code authorizationUrl} attribute
*/
@JsonProperty("authorizationUrl")
@Override
public String getAuthorizationUrl() {
return authorizationUrl;
}
/**
* @return The value of the {@code refreshUrl} attribute
*/
@JsonProperty("refreshUrl")
@Override
public Optional getRefreshUrl() {
return Optional.ofNullable(refreshUrl);
}
/**
* @return The value of the {@code scopes} attribute
*/
@JsonProperty("scopes")
@Override
public ImmutableMap getScopes() {
return scopes;
}
/**
* Copy the current immutable object by setting a value for the {@link ImplicitFlowIF#getAuthorizationUrl() authorizationUrl} attribute.
* An equals check used to prevent copying of the same value by returning {@code this}.
* @param value A new value for authorizationUrl
* @return A modified copy of the {@code this} object
*/
public final ImplicitFlow withAuthorizationUrl(String value) {
if (this.authorizationUrl.equals(value)) return this;
String newValue = Objects.requireNonNull(value, "authorizationUrl");
return new ImplicitFlow(newValue, this.refreshUrl, this.scopes);
}
/**
* Copy the current immutable object by setting a present value for the optional {@link ImplicitFlowIF#getRefreshUrl() refreshUrl} attribute.
* @param value The value for refreshUrl, {@code null} is accepted as {@code java.util.Optional.empty()}
* @return A modified copy of {@code this} object
*/
public final ImplicitFlow withRefreshUrl(@Nullable String value) {
@Nullable String newValue = value;
if (Objects.equals(this.refreshUrl, newValue)) return this;
return new ImplicitFlow(this.authorizationUrl, newValue, this.scopes);
}
/**
* Copy the current immutable object by setting an optional value for the {@link ImplicitFlowIF#getRefreshUrl() refreshUrl} 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 refreshUrl
* @return A modified copy of {@code this} object
*/
public final ImplicitFlow withRefreshUrl(Optional optional) {
@Nullable String value = optional.orElse(null);
if (Objects.equals(this.refreshUrl, value)) return this;
return new ImplicitFlow(this.authorizationUrl, value, this.scopes);
}
/**
* Copy the current immutable object by replacing the {@link ImplicitFlowIF#getScopes() scopes} 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 scopes map
* @return A modified copy of {@code this} object
*/
public final ImplicitFlow withScopes(Map entries) {
if (this.scopes == entries) return this;
ImmutableMap newValue = ImmutableMap.copyOf(entries);
return new ImplicitFlow(this.authorizationUrl, this.refreshUrl, newValue);
}
/**
* This instance is equal to all instances of {@code ImplicitFlow} 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 ImplicitFlow
&& equalTo((ImplicitFlow) another);
}
private boolean equalTo(ImplicitFlow another) {
return authorizationUrl.equals(another.authorizationUrl)
&& Objects.equals(refreshUrl, another.refreshUrl)
&& scopes.equals(another.scopes);
}
/**
* Computes a hash code from attributes: {@code authorizationUrl}, {@code refreshUrl}, {@code scopes}.
* @return hashCode value
*/
@Override
public int hashCode() {
int h = 5381;
h += (h << 5) + authorizationUrl.hashCode();
h += (h << 5) + Objects.hashCode(refreshUrl);
h += (h << 5) + scopes.hashCode();
return h;
}
/**
* Prints the immutable value {@code ImplicitFlow} with attribute values.
* @return A string representation of the value
*/
@Override
public String toString() {
return MoreObjects.toStringHelper("ImplicitFlow")
.omitNullValues()
.add("authorizationUrl", authorizationUrl)
.add("refreshUrl", refreshUrl)
.add("scopes", scopes)
.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
@JsonAutoDetect(fieldVisibility = JsonAutoDetect.Visibility.NONE)
static final class Json implements ImplicitFlowIF {
@Nullable String authorizationUrl;
@Nullable Optional refreshUrl = Optional.empty();
@Nullable Map scopes = ImmutableMap.of();
@JsonProperty("authorizationUrl")
public void setAuthorizationUrl(String authorizationUrl) {
this.authorizationUrl = authorizationUrl;
}
@JsonProperty("refreshUrl")
public void setRefreshUrl(Optional refreshUrl) {
this.refreshUrl = refreshUrl;
}
@JsonProperty("scopes")
public void setScopes(Map scopes) {
this.scopes = scopes;
}
@Override
public String getAuthorizationUrl() { throw new UnsupportedOperationException(); }
@Override
public Optional getRefreshUrl() { throw new UnsupportedOperationException(); }
@Override
public Map getScopes() { 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 ImplicitFlow fromJson(Json json) {
ImplicitFlow.Builder builder = ImplicitFlow.builder();
if (json.authorizationUrl != null) {
builder.setAuthorizationUrl(json.authorizationUrl);
}
if (json.refreshUrl != null) {
builder.setRefreshUrl(json.refreshUrl);
}
if (json.scopes != null) {
builder.putAllScopes(json.scopes);
}
return builder.build();
}
/**
* Creates an immutable copy of a {@link ImplicitFlowIF} 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 ImplicitFlow instance
*/
public static ImplicitFlow copyOf(ImplicitFlowIF instance) {
if (instance instanceof ImplicitFlow) {
return (ImplicitFlow) instance;
}
return ImplicitFlow.builder()
.from(instance)
.build();
}
/**
* Creates a builder for {@link ImplicitFlow ImplicitFlow}.
* @return A new ImplicitFlow builder
*/
public static ImplicitFlow.Builder builder() {
return new ImplicitFlow.Builder();
}
/**
* Builds instances of type {@link ImplicitFlow ImplicitFlow}.
* 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_AUTHORIZATION_URL = 0x1L;
private long initBits = 0x1L;
private @Nullable String authorizationUrl;
private @Nullable String refreshUrl;
private ImmutableMap.Builder scopes = ImmutableMap.builder();
private Builder() {
}
/**
* Fill a builder with attribute values from the provided {@code ImplicitFlowIF} instance.
* Regular attribute values will be replaced with those from the given instance.
* Absent optional values will not replace present values.
* Collection elements and entries will be added, not replaced.
* @param instance The instance from which to copy values
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final Builder from(ImplicitFlowIF instance) {
Objects.requireNonNull(instance, "instance");
setAuthorizationUrl(instance.getAuthorizationUrl());
Optional refreshUrlOptional = instance.getRefreshUrl();
if (refreshUrlOptional.isPresent()) {
setRefreshUrl(refreshUrlOptional);
}
putAllScopes(instance.getScopes());
return this;
}
/**
* Initializes the value for the {@link ImplicitFlowIF#getAuthorizationUrl() authorizationUrl} attribute.
* @param authorizationUrl The value for authorizationUrl
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final Builder setAuthorizationUrl(String authorizationUrl) {
this.authorizationUrl = Objects.requireNonNull(authorizationUrl, "authorizationUrl");
initBits &= ~INIT_BIT_AUTHORIZATION_URL;
return this;
}
/**
* Initializes the optional value {@link ImplicitFlowIF#getRefreshUrl() refreshUrl} to refreshUrl.
* @param refreshUrl The value for refreshUrl, {@code null} is accepted as {@code java.util.Optional.empty()}
* @return {@code this} builder for chained invocation
*/
@CanIgnoreReturnValue
public final Builder setRefreshUrl(@Nullable String refreshUrl) {
this.refreshUrl = refreshUrl;
return this;
}
/**
* Initializes the optional value {@link ImplicitFlowIF#getRefreshUrl() refreshUrl} to refreshUrl.
* @param refreshUrl The value for refreshUrl
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final Builder setRefreshUrl(Optional refreshUrl) {
this.refreshUrl = refreshUrl.orElse(null);
return this;
}
/**
* Put one entry to the {@link ImplicitFlowIF#getScopes() scopes} map.
* @param key The key in the scopes map
* @param value The associated value in the scopes map
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final Builder putScopes(String key, String value) {
this.scopes.put(key, value);
return this;
}
/**
* Put one entry to the {@link ImplicitFlowIF#getScopes() scopes} 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 putScopes(Map.Entry entry) {
this.scopes.put(entry);
return this;
}
/**
* Sets or replaces all mappings from the specified map as entries for the {@link ImplicitFlowIF#getScopes() scopes} map. Nulls are not permitted
* @param scopes The entries that will be added to the scopes map
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final Builder setScopes(Map scopes) {
this.scopes = ImmutableMap.builder();
return putAllScopes(scopes);
}
/**
* Put all mappings from the specified map as entries to {@link ImplicitFlowIF#getScopes() scopes} map. Nulls are not permitted
* @param scopes The entries that will be added to the scopes map
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final Builder putAllScopes(Map scopes) {
this.scopes.putAll(scopes);
return this;
}
/**
* Builds a new {@link ImplicitFlow ImplicitFlow}.
* @return An immutable instance of ImplicitFlow
* @throws java.lang.IllegalStateException if any required attributes are missing
*/
public ImplicitFlow build() {
if (initBits != 0) {
throw new IllegalStateException(formatRequiredAttributesMessage());
}
return new ImplicitFlow(authorizationUrl, refreshUrl, scopes.build());
}
private String formatRequiredAttributesMessage() {
List attributes = Lists.newArrayList();
if ((initBits & INIT_BIT_AUTHORIZATION_URL) != 0) attributes.add("authorizationUrl");
return "Cannot build ImplicitFlow, some of required attributes are not set " + attributes;
}
}
}