com.treasuredata.client.model.ImmutableTDApiKey Maven / Gradle / Ivy
Show all versions of td-client Show documentation
package com.treasuredata.client.model;
import com.fasterxml.jackson.annotation.JsonAutoDetect;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.google.common.base.MoreObjects;
import com.google.common.base.Preconditions;
import com.google.common.collect.Lists;
import com.google.common.primitives.Booleans;
import java.util.List;
import javax.annotation.Generated;
import javax.annotation.Nullable;
import javax.annotation.ParametersAreNonnullByDefault;
import javax.annotation.concurrent.Immutable;
import javax.annotation.concurrent.NotThreadSafe;
/**
* Immutable implementation of {@link TDApiKey}.
*
* Use the builder to create immutable instances:
* {@code ImmutableTDApiKey.builder()}.
*/
@SuppressWarnings("all")
@ParametersAreNonnullByDefault
@Generated({"Immutables.generator", "TDApiKey"})
@Immutable
final class ImmutableTDApiKey extends TDApiKey {
private final String keyType;
private final Integer accountId;
private final Integer userId;
private final boolean isAdministrator;
private ImmutableTDApiKey(
String keyType,
Integer accountId,
Integer userId,
boolean isAdministrator) {
this.keyType = keyType;
this.accountId = accountId;
this.userId = userId;
this.isAdministrator = isAdministrator;
}
/**
* @return The value of the {@code keyType} attribute
*/
@JsonProperty("key_type")
@Override
public String getKeyType() {
return keyType;
}
/**
* @return The value of the {@code accountId} attribute
*/
@JsonProperty("account_id")
@Override
public Integer getAccountId() {
return accountId;
}
/**
* @return The value of the {@code userId} attribute
*/
@JsonProperty("user_id")
@Override
public Integer getUserId() {
return userId;
}
/**
* @return The value of the {@code isAdministrator} attribute
*/
@JsonProperty("administrator")
@Override
public boolean isAdministrator() {
return isAdministrator;
}
/**
* Copy the current immutable object by setting a value for the {@link TDApiKey#getKeyType() keyType} attribute.
* An equals check used to prevent copying of the same value by returning {@code this}.
* @param keyType A new value for keyType
* @return A modified copy of the {@code this} object
*/
public final ImmutableTDApiKey withKeyType(String keyType) {
if (this.keyType.equals(keyType)) return this;
String newValue = Preconditions.checkNotNull(keyType, "keyType");
return new ImmutableTDApiKey(newValue, this.accountId, this.userId, this.isAdministrator);
}
/**
* Copy the current immutable object by setting a value for the {@link TDApiKey#getAccountId() accountId} attribute.
* An equals check used to prevent copying of the same value by returning {@code this}.
* @param accountId A new value for accountId
* @return A modified copy of the {@code this} object
*/
public final ImmutableTDApiKey withAccountId(Integer accountId) {
if (this.accountId.equals(accountId)) return this;
Integer newValue = Preconditions.checkNotNull(accountId, "accountId");
return new ImmutableTDApiKey(this.keyType, newValue, this.userId, this.isAdministrator);
}
/**
* Copy the current immutable object by setting a value for the {@link TDApiKey#getUserId() userId} attribute.
* An equals check used to prevent copying of the same value by returning {@code this}.
* @param userId A new value for userId
* @return A modified copy of the {@code this} object
*/
public final ImmutableTDApiKey withUserId(Integer userId) {
if (this.userId.equals(userId)) return this;
Integer newValue = Preconditions.checkNotNull(userId, "userId");
return new ImmutableTDApiKey(this.keyType, this.accountId, newValue, this.isAdministrator);
}
/**
* Copy the current immutable object by setting a value for the {@link TDApiKey#isAdministrator() isAdministrator} attribute.
* A value equality check is used to prevent copying of the same value by returning {@code this}.
* @param isAdministrator A new value for isAdministrator
* @return A modified copy of the {@code this} object
*/
public final ImmutableTDApiKey withIsAdministrator(boolean isAdministrator) {
if (this.isAdministrator == isAdministrator) return this;
return new ImmutableTDApiKey(this.keyType, this.accountId, this.userId, isAdministrator);
}
/**
* This instance is equal to all instances of {@code ImmutableTDApiKey} 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 ImmutableTDApiKey
&& equalTo((ImmutableTDApiKey) another);
}
private boolean equalTo(ImmutableTDApiKey another) {
return keyType.equals(another.keyType)
&& accountId.equals(another.accountId)
&& userId.equals(another.userId)
&& isAdministrator == another.isAdministrator;
}
/**
* Computes a hash code from attributes: {@code keyType}, {@code accountId}, {@code userId}, {@code isAdministrator}.
* @return hashCode value
*/
@Override
public int hashCode() {
int h = 31;
h = h * 17 + keyType.hashCode();
h = h * 17 + accountId.hashCode();
h = h * 17 + userId.hashCode();
h = h * 17 + Booleans.hashCode(isAdministrator);
return h;
}
/**
* Prints the immutable value {@code TDApiKey} with attribute values.
* @return A string representation of the value
*/
@Override
public String toString() {
return MoreObjects.toStringHelper("TDApiKey")
.omitNullValues()
.add("keyType", keyType)
.add("accountId", accountId)
.add("userId", userId)
.add("isAdministrator", isAdministrator)
.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 TDApiKey {
@Nullable String keyType;
@Nullable Integer accountId;
@Nullable Integer userId;
boolean isAdministrator;
boolean isAdministratorIsSet;
@JsonProperty("key_type")
public void setKeyType(String keyType) {
this.keyType = keyType;
}
@JsonProperty("account_id")
public void setAccountId(Integer accountId) {
this.accountId = accountId;
}
@JsonProperty("user_id")
public void setUserId(Integer userId) {
this.userId = userId;
}
@JsonProperty("administrator")
public void setIsAdministrator(boolean isAdministrator) {
this.isAdministrator = isAdministrator;
this.isAdministratorIsSet = true;
}
@Override
public String getKeyType() { throw new UnsupportedOperationException(); }
@Override
public Integer getAccountId() { throw new UnsupportedOperationException(); }
@Override
public Integer getUserId() { throw new UnsupportedOperationException(); }
@Override
public boolean isAdministrator() { 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
static ImmutableTDApiKey fromJson(Json json) {
ImmutableTDApiKey.Builder builder = ImmutableTDApiKey.builder();
if (json.keyType != null) {
builder.keyType(json.keyType);
}
if (json.accountId != null) {
builder.accountId(json.accountId);
}
if (json.userId != null) {
builder.userId(json.userId);
}
if (json.isAdministratorIsSet) {
builder.isAdministrator(json.isAdministrator);
}
return builder.build();
}
/**
* Creates an immutable copy of a {@link TDApiKey} 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 TDApiKey instance
*/
public static ImmutableTDApiKey copyOf(TDApiKey instance) {
if (instance instanceof ImmutableTDApiKey) {
return (ImmutableTDApiKey) instance;
}
return ImmutableTDApiKey.builder()
.from(instance)
.build();
}
/**
* Creates a builder for {@link ImmutableTDApiKey ImmutableTDApiKey}.
* @return A new ImmutableTDApiKey builder
*/
public static ImmutableTDApiKey.Builder builder() {
return new ImmutableTDApiKey.Builder();
}
/**
* Builds instances of type {@link ImmutableTDApiKey ImmutableTDApiKey}.
* 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
static final class Builder
implements TDApiKey.Builder {
private static final long INIT_BIT_KEY_TYPE = 0x1L;
private static final long INIT_BIT_ACCOUNT_ID = 0x2L;
private static final long INIT_BIT_USER_ID = 0x4L;
private static final long INIT_BIT_IS_ADMINISTRATOR = 0x8L;
private long initBits = 0xfL;
private @Nullable String keyType;
private @Nullable Integer accountId;
private @Nullable Integer userId;
private boolean isAdministrator;
private Builder() {
}
/**
* Fill a builder with attribute values from the provided {@code TDApiKey} 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(TDApiKey instance) {
Preconditions.checkNotNull(instance, "instance");
keyType(instance.getKeyType());
accountId(instance.getAccountId());
userId(instance.getUserId());
isAdministrator(instance.isAdministrator());
return this;
}
/**
* Initializes the value for the {@link TDApiKey#getKeyType() keyType} attribute.
* @param keyType The value for keyType
* @return {@code this} builder for use in a chained invocation
*/
public final Builder keyType(String keyType) {
this.keyType = Preconditions.checkNotNull(keyType, "keyType");
initBits &= ~INIT_BIT_KEY_TYPE;
return this;
}
/**
* Initializes the value for the {@link TDApiKey#getAccountId() accountId} attribute.
* @param accountId The value for accountId
* @return {@code this} builder for use in a chained invocation
*/
public final Builder accountId(Integer accountId) {
this.accountId = Preconditions.checkNotNull(accountId, "accountId");
initBits &= ~INIT_BIT_ACCOUNT_ID;
return this;
}
/**
* Initializes the value for the {@link TDApiKey#getUserId() userId} attribute.
* @param userId The value for userId
* @return {@code this} builder for use in a chained invocation
*/
public final Builder userId(Integer userId) {
this.userId = Preconditions.checkNotNull(userId, "userId");
initBits &= ~INIT_BIT_USER_ID;
return this;
}
/**
* Initializes the value for the {@link TDApiKey#isAdministrator() isAdministrator} attribute.
* @param isAdministrator The value for isAdministrator
* @return {@code this} builder for use in a chained invocation
*/
public final Builder isAdministrator(boolean isAdministrator) {
this.isAdministrator = isAdministrator;
initBits &= ~INIT_BIT_IS_ADMINISTRATOR;
return this;
}
/**
* Builds a new {@link ImmutableTDApiKey ImmutableTDApiKey}.
* @return An immutable instance of TDApiKey
* @throws java.lang.IllegalStateException if any required attributes are missing
*/
public ImmutableTDApiKey build() {
if (initBits != 0) {
throw new IllegalStateException(formatRequiredAttributesMessage());
}
return new ImmutableTDApiKey(keyType, accountId, userId, isAdministrator);
}
private String formatRequiredAttributesMessage() {
List attributes = Lists.newArrayList();
if ((initBits & INIT_BIT_KEY_TYPE) != 0) attributes.add("keyType");
if ((initBits & INIT_BIT_ACCOUNT_ID) != 0) attributes.add("accountId");
if ((initBits & INIT_BIT_USER_ID) != 0) attributes.add("userId");
if ((initBits & INIT_BIT_IS_ADMINISTRATOR) != 0) attributes.add("isAdministrator");
return "Cannot build TDApiKey, some of required attributes are not set " + attributes;
}
}
}