
com.hubspot.slack.client.models.auth.OAuthV2Credentials Maven / Gradle / Ivy
package com.hubspot.slack.client.models.auth;
import com.fasterxml.jackson.annotation.JsonAutoDetect;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.hubspot.immutables.validation.InvalidImmutableStateException;
import com.hubspot.slack.client.models.teams.SlackTeamLite;
import com.hubspot.slack.client.models.users.SlackUserLite;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import javax.annotation.Nullable;
import javax.annotation.ParametersAreNonnullByDefault;
import javax.annotation.concurrent.Immutable;
import javax.annotation.concurrent.NotThreadSafe;
import org.immutables.value.Generated;
/**
* Immutable implementation of {@link OAuthV2CredentialsIF}.
*
* Use the builder to create immutable instances:
* {@code OAuthV2Credentials.builder()}.
*/
@Generated(from = "OAuthV2CredentialsIF", generator = "Immutables")
@SuppressWarnings({"all"})
@SuppressFBWarnings
@ParametersAreNonnullByDefault
@javax.annotation.processing.Generated("org.immutables.processor.ProxyProcessor")
@Immutable
public final class OAuthV2Credentials extends OAuthV2CredentialsIF {
private final String botAccessToken;
private final SlackTeamLite team;
private final @Nullable String scope;
private final SlackUserLite authedUser;
private final String botUserId;
private OAuthV2Credentials(
String botAccessToken,
SlackTeamLite team,
@Nullable String scope,
SlackUserLite authedUser,
String botUserId) {
this.botAccessToken = botAccessToken;
this.team = team;
this.scope = scope;
this.authedUser = authedUser;
this.botUserId = botUserId;
}
/**
* @return The value of the {@code botAccessToken} attribute
*/
@JsonProperty("access_token")
@Override
public String getBotAccessToken() {
return botAccessToken;
}
/**
* @return The value of the {@code team} attribute
*/
@JsonProperty
@Override
public SlackTeamLite getTeam() {
return team;
}
/**
* @return The value of the {@code scope} attribute
*/
@JsonProperty
@Override
public Optional getScope() {
return Optional.ofNullable(scope);
}
/**
* @return The value of the {@code authedUser} attribute
*/
@JsonProperty
@Override
public SlackUserLite getAuthedUser() {
return authedUser;
}
/**
* @return The value of the {@code botUserId} attribute
*/
@JsonProperty
@Override
public String getBotUserId() {
return botUserId;
}
/**
* Copy the current immutable object by setting a value for the {@link OAuthV2CredentialsIF#getBotAccessToken() botAccessToken} attribute.
* An equals check used to prevent copying of the same value by returning {@code this}.
* @param value A new value for botAccessToken
* @return A modified copy of the {@code this} object
*/
public final OAuthV2Credentials withBotAccessToken(String value) {
String newValue = Objects.requireNonNull(value, "botAccessToken");
if (this.botAccessToken.equals(newValue)) return this;
return new OAuthV2Credentials(newValue, this.team, this.scope, this.authedUser, this.botUserId);
}
/**
* Copy the current immutable object by setting a value for the {@link OAuthV2CredentialsIF#getTeam() team} 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 team
* @return A modified copy of the {@code this} object
*/
public final OAuthV2Credentials withTeam(SlackTeamLite value) {
if (this.team == value) return this;
SlackTeamLite newValue = Objects.requireNonNull(value, "team");
return new OAuthV2Credentials(this.botAccessToken, newValue, this.scope, this.authedUser, this.botUserId);
}
/**
* Copy the current immutable object by setting a present value for the optional {@link OAuthV2CredentialsIF#getScope() scope} attribute.
* @param value The value for scope, {@code null} is accepted as {@code java.util.Optional.empty()}
* @return A modified copy of {@code this} object
*/
public final OAuthV2Credentials withScope(@Nullable String value) {
@Nullable String newValue = value;
if (Objects.equals(this.scope, newValue)) return this;
return new OAuthV2Credentials(this.botAccessToken, this.team, newValue, this.authedUser, this.botUserId);
}
/**
* Copy the current immutable object by setting an optional value for the {@link OAuthV2CredentialsIF#getScope() scope} 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 scope
* @return A modified copy of {@code this} object
*/
public final OAuthV2Credentials withScope(Optional optional) {
@Nullable String value = optional.orElse(null);
if (Objects.equals(this.scope, value)) return this;
return new OAuthV2Credentials(this.botAccessToken, this.team, value, this.authedUser, this.botUserId);
}
/**
* Copy the current immutable object by setting a value for the {@link OAuthV2CredentialsIF#getAuthedUser() authedUser} 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 authedUser
* @return A modified copy of the {@code this} object
*/
public final OAuthV2Credentials withAuthedUser(SlackUserLite value) {
if (this.authedUser == value) return this;
SlackUserLite newValue = Objects.requireNonNull(value, "authedUser");
return new OAuthV2Credentials(this.botAccessToken, this.team, this.scope, newValue, this.botUserId);
}
/**
* Copy the current immutable object by setting a value for the {@link OAuthV2CredentialsIF#getBotUserId() botUserId} attribute.
* An equals check used to prevent copying of the same value by returning {@code this}.
* @param value A new value for botUserId
* @return A modified copy of the {@code this} object
*/
public final OAuthV2Credentials withBotUserId(String value) {
String newValue = Objects.requireNonNull(value, "botUserId");
if (this.botUserId.equals(newValue)) return this;
return new OAuthV2Credentials(this.botAccessToken, this.team, this.scope, this.authedUser, newValue);
}
/**
* This instance is equal to all instances of {@code OAuthV2Credentials} 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 OAuthV2Credentials
&& equalTo(0, (OAuthV2Credentials) another);
}
private boolean equalTo(int synthetic, OAuthV2Credentials another) {
return botAccessToken.equals(another.botAccessToken)
&& team.equals(another.team)
&& Objects.equals(scope, another.scope)
&& authedUser.equals(another.authedUser)
&& botUserId.equals(another.botUserId);
}
/**
* Computes a hash code from attributes: {@code botAccessToken}, {@code team}, {@code scope}, {@code authedUser}, {@code botUserId}.
* @return hashCode value
*/
@Override
public int hashCode() {
int h = 5381;
h += (h << 5) + botAccessToken.hashCode();
h += (h << 5) + team.hashCode();
h += (h << 5) + Objects.hashCode(scope);
h += (h << 5) + authedUser.hashCode();
h += (h << 5) + botUserId.hashCode();
return h;
}
/**
* Prints the immutable value {@code OAuthV2Credentials} with attribute values.
* @return A string representation of the value
*/
@Override
public String toString() {
StringBuilder builder = new StringBuilder("OAuthV2Credentials{");
builder.append("botAccessToken=").append(botAccessToken);
builder.append(", ");
builder.append("team=").append(team);
if (scope != null) {
builder.append(", ");
builder.append("scope=").append(scope);
}
builder.append(", ");
builder.append("authedUser=").append(authedUser);
builder.append(", ");
builder.append("botUserId=").append(botUserId);
return builder.append("}").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
*/
@Generated(from = "OAuthV2CredentialsIF", generator = "Immutables")
@Deprecated
@JsonAutoDetect(fieldVisibility = JsonAutoDetect.Visibility.NONE)
static final class Json extends OAuthV2CredentialsIF {
@Nullable String botAccessToken;
@Nullable SlackTeamLite team;
@Nullable Optional scope = Optional.empty();
@Nullable SlackUserLite authedUser;
@Nullable String botUserId;
@JsonProperty("access_token")
public void setBotAccessToken(String botAccessToken) {
this.botAccessToken = botAccessToken;
}
@JsonProperty
public void setTeam(SlackTeamLite team) {
this.team = team;
}
@JsonProperty
public void setScope(Optional scope) {
this.scope = scope;
}
@JsonProperty
public void setAuthedUser(SlackUserLite authedUser) {
this.authedUser = authedUser;
}
@JsonProperty
public void setBotUserId(String botUserId) {
this.botUserId = botUserId;
}
@Override
public String getBotAccessToken() { throw new UnsupportedOperationException(); }
@Override
public SlackTeamLite getTeam() { throw new UnsupportedOperationException(); }
@Override
public Optional getScope() { throw new UnsupportedOperationException(); }
@Override
public SlackUserLite getAuthedUser() { throw new UnsupportedOperationException(); }
@Override
public String getBotUserId() { 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 OAuthV2Credentials fromJson(Json json) {
OAuthV2Credentials.Builder builder = OAuthV2Credentials.builder();
if (json.botAccessToken != null) {
builder.setBotAccessToken(json.botAccessToken);
}
if (json.team != null) {
builder.setTeam(json.team);
}
if (json.scope != null) {
builder.setScope(json.scope);
}
if (json.authedUser != null) {
builder.setAuthedUser(json.authedUser);
}
if (json.botUserId != null) {
builder.setBotUserId(json.botUserId);
}
return builder.build();
}
/**
* Creates an immutable copy of a {@link OAuthV2CredentialsIF} 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 OAuthV2Credentials instance
*/
public static OAuthV2Credentials copyOf(OAuthV2CredentialsIF instance) {
if (instance instanceof OAuthV2Credentials) {
return (OAuthV2Credentials) instance;
}
return OAuthV2Credentials.builder()
.from(instance)
.build();
}
/**
* Creates a builder for {@link OAuthV2Credentials OAuthV2Credentials}.
*
* OAuthV2Credentials.builder()
* .setBotAccessToken(String) // required {@link OAuthV2CredentialsIF#getBotAccessToken() botAccessToken}
* .setTeam(com.hubspot.slack.client.models.teams.SlackTeamLite) // required {@link OAuthV2CredentialsIF#getTeam() team}
* .setScope(String) // optional {@link OAuthV2CredentialsIF#getScope() scope}
* .setAuthedUser(com.hubspot.slack.client.models.users.SlackUserLite) // required {@link OAuthV2CredentialsIF#getAuthedUser() authedUser}
* .setBotUserId(String) // required {@link OAuthV2CredentialsIF#getBotUserId() botUserId}
* .build();
*
* @return A new OAuthV2Credentials builder
*/
public static OAuthV2Credentials.Builder builder() {
return new OAuthV2Credentials.Builder();
}
/**
* Builds instances of type {@link OAuthV2Credentials OAuthV2Credentials}.
* 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.
*/
@Generated(from = "OAuthV2CredentialsIF", generator = "Immutables")
@NotThreadSafe
public static final class Builder {
private static final long INIT_BIT_BOT_ACCESS_TOKEN = 0x1L;
private static final long INIT_BIT_TEAM = 0x2L;
private static final long INIT_BIT_AUTHED_USER = 0x4L;
private static final long INIT_BIT_BOT_USER_ID = 0x8L;
private long initBits = 0xfL;
private @Nullable String botAccessToken;
private @Nullable SlackTeamLite team;
private @Nullable String scope;
private @Nullable SlackUserLite authedUser;
private @Nullable String botUserId;
private Builder() {
}
/**
* Fill a builder with attribute values from the provided {@code OAuthV2CredentialsIF} instance.
* Regular attribute values will be replaced with those from the given instance.
* Absent optional values will not replace present values.
* @param instance The instance from which to copy values
* @return {@code this} builder for use in a chained invocation
*/
public final Builder from(OAuthV2CredentialsIF instance) {
Objects.requireNonNull(instance, "instance");
this.setBotAccessToken(instance.getBotAccessToken());
this.setTeam(instance.getTeam());
Optional scopeOptional = instance.getScope();
if (scopeOptional.isPresent()) {
setScope(scopeOptional);
}
this.setAuthedUser(instance.getAuthedUser());
this.setBotUserId(instance.getBotUserId());
return this;
}
/**
* Initializes the value for the {@link OAuthV2CredentialsIF#getBotAccessToken() botAccessToken} attribute.
* @param botAccessToken The value for botAccessToken
* @return {@code this} builder for use in a chained invocation
*/
public final Builder setBotAccessToken(String botAccessToken) {
this.botAccessToken = Objects.requireNonNull(botAccessToken, "botAccessToken");
initBits &= ~INIT_BIT_BOT_ACCESS_TOKEN;
return this;
}
/**
* Initializes the value for the {@link OAuthV2CredentialsIF#getTeam() team} attribute.
* @param team The value for team
* @return {@code this} builder for use in a chained invocation
*/
public final Builder setTeam(SlackTeamLite team) {
this.team = Objects.requireNonNull(team, "team");
initBits &= ~INIT_BIT_TEAM;
return this;
}
/**
* Initializes the optional value {@link OAuthV2CredentialsIF#getScope() scope} to scope.
* @param scope The value for scope, {@code null} is accepted as {@code java.util.Optional.empty()}
* @return {@code this} builder for chained invocation
*/
public final Builder setScope(@Nullable String scope) {
this.scope = scope;
return this;
}
/**
* Initializes the optional value {@link OAuthV2CredentialsIF#getScope() scope} to scope.
* @param scope The value for scope
* @return {@code this} builder for use in a chained invocation
*/
public final Builder setScope(Optional scope) {
this.scope = scope.orElse(null);
return this;
}
/**
* Initializes the value for the {@link OAuthV2CredentialsIF#getAuthedUser() authedUser} attribute.
* @param authedUser The value for authedUser
* @return {@code this} builder for use in a chained invocation
*/
public final Builder setAuthedUser(SlackUserLite authedUser) {
this.authedUser = Objects.requireNonNull(authedUser, "authedUser");
initBits &= ~INIT_BIT_AUTHED_USER;
return this;
}
/**
* Initializes the value for the {@link OAuthV2CredentialsIF#getBotUserId() botUserId} attribute.
* @param botUserId The value for botUserId
* @return {@code this} builder for use in a chained invocation
*/
public final Builder setBotUserId(String botUserId) {
this.botUserId = Objects.requireNonNull(botUserId, "botUserId");
initBits &= ~INIT_BIT_BOT_USER_ID;
return this;
}
/**
* Builds a new {@link OAuthV2Credentials OAuthV2Credentials}.
* @return An immutable instance of OAuthV2Credentials
* @throws com.hubspot.immutables.validation.InvalidImmutableStateException if any required attributes are missing
*/
public OAuthV2Credentials build() {
checkRequiredAttributes();
return new OAuthV2Credentials(botAccessToken, team, scope, authedUser, botUserId);
}
private boolean botAccessTokenIsSet() {
return (initBits & INIT_BIT_BOT_ACCESS_TOKEN) == 0;
}
private boolean teamIsSet() {
return (initBits & INIT_BIT_TEAM) == 0;
}
private boolean authedUserIsSet() {
return (initBits & INIT_BIT_AUTHED_USER) == 0;
}
private boolean botUserIdIsSet() {
return (initBits & INIT_BIT_BOT_USER_ID) == 0;
}
private void checkRequiredAttributes() {
if (initBits != 0) {
throw new InvalidImmutableStateException(formatRequiredAttributesMessage());
}
}
private String formatRequiredAttributesMessage() {
List attributes = new ArrayList<>();
if (!botAccessTokenIsSet()) attributes.add("botAccessToken");
if (!teamIsSet()) attributes.add("team");
if (!authedUserIsSet()) attributes.add("authedUser");
if (!botUserIdIsSet()) attributes.add("botUserId");
return "Cannot build OAuthV2Credentials, some of required attributes are not set " + attributes;
}
}
}