
com.arakelian.faker.model.ImmutableAddress Maven / Gradle / Ivy
package com.arakelian.faker.model;
import com.arakelian.store.feature.HasId;
import com.arakelian.store.feature.HasTimestamp;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
import com.google.common.base.MoreObjects;
import com.google.errorprone.annotations.CanIgnoreReturnValue;
import com.google.errorprone.annotations.Var;
import java.time.ZonedDateTime;
import java.util.ArrayList;
import java.util.List;
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;
import org.immutables.value.Generated;
/**
* Immutable implementation of {@link Address}.
*
* Use the builder to create immutable instances:
* {@code ImmutableAddress.builder()}.
*/
@Generated(from = "Address", generator = "Immutables")
@SuppressWarnings({"all"})
@ParametersAreNonnullByDefault
@javax.annotation.Generated("org.immutables.processor.ProxyProcessor")
@Immutable
@CheckReturnValue
public final class ImmutableAddress extends Address {
private final String city;
private final String postalCode;
private final String state;
private final String street;
private final ZonedDateTime created;
private final String id;
private final ZonedDateTime updated;
private ImmutableAddress(ImmutableAddress.Builder builder) {
this.city = builder.city;
this.postalCode = builder.postalCode;
this.state = builder.state;
this.street = builder.street;
if (builder.created != null) {
initShim.created(builder.created);
}
if (builder.id != null) {
initShim.id(builder.id);
}
if (builder.updated != null) {
initShim.updated(builder.updated);
}
this.created = initShim.getCreated();
this.id = initShim.getId();
this.updated = initShim.getUpdated();
this.initShim = null;
}
private ImmutableAddress(
String city,
String postalCode,
String state,
String street,
ZonedDateTime created,
String id,
ZonedDateTime updated) {
this.city = city;
this.postalCode = postalCode;
this.state = state;
this.street = street;
this.created = created;
this.id = id;
this.updated = updated;
this.initShim = null;
}
private static final byte STAGE_INITIALIZING = -1;
private static final byte STAGE_UNINITIALIZED = 0;
private static final byte STAGE_INITIALIZED = 1;
@SuppressWarnings("Immutable")
private transient volatile InitShim initShim = new InitShim();
@Generated(from = "Address", generator = "Immutables")
private final class InitShim {
private byte createdBuildStage = STAGE_UNINITIALIZED;
private ZonedDateTime created;
ZonedDateTime getCreated() {
if (createdBuildStage == STAGE_INITIALIZING) throw new IllegalStateException(formatInitCycleMessage());
if (createdBuildStage == STAGE_UNINITIALIZED) {
createdBuildStage = STAGE_INITIALIZING;
this.created = Objects.requireNonNull(ImmutableAddress.super.getCreated(), "created");
createdBuildStage = STAGE_INITIALIZED;
}
return this.created;
}
void created(ZonedDateTime created) {
this.created = created;
createdBuildStage = STAGE_INITIALIZED;
}
private byte idBuildStage = STAGE_UNINITIALIZED;
private String id;
String getId() {
if (idBuildStage == STAGE_INITIALIZING) throw new IllegalStateException(formatInitCycleMessage());
if (idBuildStage == STAGE_UNINITIALIZED) {
idBuildStage = STAGE_INITIALIZING;
this.id = Objects.requireNonNull(ImmutableAddress.super.getId(), "id");
idBuildStage = STAGE_INITIALIZED;
}
return this.id;
}
void id(String id) {
this.id = id;
idBuildStage = STAGE_INITIALIZED;
}
private byte updatedBuildStage = STAGE_UNINITIALIZED;
private ZonedDateTime updated;
ZonedDateTime getUpdated() {
if (updatedBuildStage == STAGE_INITIALIZING) throw new IllegalStateException(formatInitCycleMessage());
if (updatedBuildStage == STAGE_UNINITIALIZED) {
updatedBuildStage = STAGE_INITIALIZING;
this.updated = Objects.requireNonNull(ImmutableAddress.super.getUpdated(), "updated");
updatedBuildStage = STAGE_INITIALIZED;
}
return this.updated;
}
void updated(ZonedDateTime updated) {
this.updated = updated;
updatedBuildStage = STAGE_INITIALIZED;
}
private String formatInitCycleMessage() {
List attributes = new ArrayList<>();
if (createdBuildStage == STAGE_INITIALIZING) attributes.add("created");
if (idBuildStage == STAGE_INITIALIZING) attributes.add("id");
if (updatedBuildStage == STAGE_INITIALIZING) attributes.add("updated");
return "Cannot build Address, attribute initializers form cycle " + attributes;
}
}
/**
* @return The value of the {@code city} attribute
*/
@JsonProperty("city")
@Override
public String getCity() {
return city;
}
/**
* @return The value of the {@code postalCode} attribute
*/
@JsonProperty("postalCode")
@Override
public String getPostalCode() {
return postalCode;
}
/**
* @return The value of the {@code state} attribute
*/
@JsonProperty("state")
@Override
public String getState() {
return state;
}
/**
* @return The value of the {@code street} attribute
*/
@JsonProperty("street")
@Override
public String getStreet() {
return street;
}
/**
* @return The value of the {@code created} attribute
*/
@JsonProperty("created")
@Override
public ZonedDateTime getCreated() {
InitShim shim = this.initShim;
return shim != null
? shim.getCreated()
: this.created;
}
/**
* @return The value of the {@code id} attribute
*/
@JsonProperty("id")
@Override
public String getId() {
InitShim shim = this.initShim;
return shim != null
? shim.getId()
: this.id;
}
/**
* @return The value of the {@code updated} attribute
*/
@JsonProperty("updated")
@Override
public ZonedDateTime getUpdated() {
InitShim shim = this.initShim;
return shim != null
? shim.getUpdated()
: this.updated;
}
/**
* Copy the current immutable object by setting a value for the {@link Address#getCity() city} attribute.
* An equals check used to prevent copying of the same value by returning {@code this}.
* @param value A new value for city
* @return A modified copy of the {@code this} object
*/
public final ImmutableAddress withCity(String value) {
String newValue = Objects.requireNonNull(value, "city");
if (this.city.equals(newValue)) return this;
return new ImmutableAddress(newValue, this.postalCode, this.state, this.street, this.created, this.id, this.updated);
}
/**
* Copy the current immutable object by setting a value for the {@link Address#getPostalCode() postalCode} attribute.
* An equals check used to prevent copying of the same value by returning {@code this}.
* @param value A new value for postalCode
* @return A modified copy of the {@code this} object
*/
public final ImmutableAddress withPostalCode(String value) {
String newValue = Objects.requireNonNull(value, "postalCode");
if (this.postalCode.equals(newValue)) return this;
return new ImmutableAddress(this.city, newValue, this.state, this.street, this.created, this.id, this.updated);
}
/**
* Copy the current immutable object by setting a value for the {@link Address#getState() state} attribute.
* An equals check used to prevent copying of the same value by returning {@code this}.
* @param value A new value for state
* @return A modified copy of the {@code this} object
*/
public final ImmutableAddress withState(String value) {
String newValue = Objects.requireNonNull(value, "state");
if (this.state.equals(newValue)) return this;
return new ImmutableAddress(this.city, this.postalCode, newValue, this.street, this.created, this.id, this.updated);
}
/**
* Copy the current immutable object by setting a value for the {@link Address#getStreet() street} attribute.
* An equals check used to prevent copying of the same value by returning {@code this}.
* @param value A new value for street
* @return A modified copy of the {@code this} object
*/
public final ImmutableAddress withStreet(String value) {
String newValue = Objects.requireNonNull(value, "street");
if (this.street.equals(newValue)) return this;
return new ImmutableAddress(this.city, this.postalCode, this.state, newValue, this.created, this.id, this.updated);
}
/**
* Copy the current immutable object by setting a value for the {@link Address#getCreated() created} 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 created
* @return A modified copy of the {@code this} object
*/
public final ImmutableAddress withCreated(ZonedDateTime value) {
if (this.created == value) return this;
ZonedDateTime newValue = Objects.requireNonNull(value, "created");
return new ImmutableAddress(this.city, this.postalCode, this.state, this.street, newValue, this.id, this.updated);
}
/**
* Copy the current immutable object by setting a value for the {@link Address#getId() id} attribute.
* An equals check used to prevent copying of the same value by returning {@code this}.
* @param value A new value for id
* @return A modified copy of the {@code this} object
*/
public final ImmutableAddress withId(String value) {
String newValue = Objects.requireNonNull(value, "id");
if (this.id.equals(newValue)) return this;
return new ImmutableAddress(this.city, this.postalCode, this.state, this.street, this.created, newValue, this.updated);
}
/**
* Copy the current immutable object by setting a value for the {@link Address#getUpdated() updated} 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 updated
* @return A modified copy of the {@code this} object
*/
public final ImmutableAddress withUpdated(ZonedDateTime value) {
if (this.updated == value) return this;
ZonedDateTime newValue = Objects.requireNonNull(value, "updated");
return new ImmutableAddress(this.city, this.postalCode, this.state, this.street, this.created, this.id, newValue);
}
/**
* This instance is equal to all instances of {@code ImmutableAddress} 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 ImmutableAddress
&& equalTo((ImmutableAddress) another);
}
private boolean equalTo(ImmutableAddress another) {
return city.equals(another.city)
&& postalCode.equals(another.postalCode)
&& state.equals(another.state)
&& street.equals(another.street)
&& created.equals(another.created)
&& id.equals(another.id)
&& updated.equals(another.updated);
}
/**
* Computes a hash code from attributes: {@code city}, {@code postalCode}, {@code state}, {@code street}, {@code created}, {@code id}, {@code updated}.
* @return hashCode value
*/
@Override
public int hashCode() {
@Var int h = 5381;
h += (h << 5) + city.hashCode();
h += (h << 5) + postalCode.hashCode();
h += (h << 5) + state.hashCode();
h += (h << 5) + street.hashCode();
h += (h << 5) + created.hashCode();
h += (h << 5) + id.hashCode();
h += (h << 5) + updated.hashCode();
return h;
}
/**
* Prints the immutable value {@code Address} with attribute values.
* @return A string representation of the value
*/
@Override
public String toString() {
return MoreObjects.toStringHelper("Address")
.omitNullValues()
.add("city", city)
.add("postalCode", postalCode)
.add("state", state)
.add("street", street)
.add("created", created)
.add("id", id)
.add("updated", updated)
.toString();
}
/**
* Creates an immutable copy of a {@link Address} 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 Address instance
*/
public static ImmutableAddress copyOf(Address instance) {
if (instance instanceof ImmutableAddress) {
return (ImmutableAddress) instance;
}
return ImmutableAddress.builder()
.from(instance)
.build();
}
/**
* Creates a builder for {@link ImmutableAddress ImmutableAddress}.
* @return A new ImmutableAddress builder
*/
public static ImmutableAddress.Builder builder() {
return new ImmutableAddress.Builder();
}
/**
* Builds instances of type {@link ImmutableAddress ImmutableAddress}.
* 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 = "Address", generator = "Immutables")
@NotThreadSafe
@JsonPropertyOrder({"id", "street", "city", "state", "postalCode", "created", "updated"})
public static final class Builder {
private static final long INIT_BIT_CITY = 0x1L;
private static final long INIT_BIT_POSTAL_CODE = 0x2L;
private static final long INIT_BIT_STATE = 0x4L;
private static final long INIT_BIT_STREET = 0x8L;
private long initBits = 0xfL;
private @Nullable String city;
private @Nullable String postalCode;
private @Nullable String state;
private @Nullable String street;
private @Nullable ZonedDateTime created;
private @Nullable String id;
private @Nullable ZonedDateTime updated;
private Builder() {
}
/**
* Fill a builder with attribute values from the provided {@code com.arakelian.store.feature.HasId} 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(HasId instance) {
Objects.requireNonNull(instance, "instance");
from((Object) instance);
return this;
}
/**
* Fill a builder with attribute values from the provided {@code com.arakelian.faker.model.AbstractModel} 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(AbstractModel instance) {
Objects.requireNonNull(instance, "instance");
from((Object) instance);
return this;
}
/**
* Fill a builder with attribute values from the provided {@code com.arakelian.store.feature.HasTimestamp} 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(HasTimestamp instance) {
Objects.requireNonNull(instance, "instance");
from((Object) instance);
return this;
}
/**
* Fill a builder with attribute values from the provided {@code com.arakelian.faker.model.Address} 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(Address instance) {
Objects.requireNonNull(instance, "instance");
from((Object) instance);
return this;
}
private void from(Object object) {
@Var long bits = 0;
if (object instanceof HasId) {
HasId instance = (HasId) object;
if ((bits & 0x2L) == 0) {
id(instance.getId());
bits |= 0x2L;
}
}
if (object instanceof AbstractModel) {
AbstractModel instance = (AbstractModel) object;
if ((bits & 0x4L) == 0) {
updated(instance.getUpdated());
bits |= 0x4L;
}
if ((bits & 0x1L) == 0) {
created(instance.getCreated());
bits |= 0x1L;
}
if ((bits & 0x2L) == 0) {
id(instance.getId());
bits |= 0x2L;
}
}
if (object instanceof HasTimestamp) {
HasTimestamp instance = (HasTimestamp) object;
if ((bits & 0x4L) == 0) {
updated(instance.getUpdated());
bits |= 0x4L;
}
if ((bits & 0x1L) == 0) {
created(instance.getCreated());
bits |= 0x1L;
}
}
if (object instanceof Address) {
Address instance = (Address) object;
state(instance.getState());
city(instance.getCity());
street(instance.getStreet());
postalCode(instance.getPostalCode());
}
}
/**
* Initializes the value for the {@link Address#getCity() city} attribute.
* @param city The value for city
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
@JsonProperty("city")
public final Builder city(String city) {
this.city = Objects.requireNonNull(city, "city");
initBits &= ~INIT_BIT_CITY;
return this;
}
/**
* Initializes the value for the {@link Address#getPostalCode() postalCode} attribute.
* @param postalCode The value for postalCode
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
@JsonProperty("postalCode")
public final Builder postalCode(String postalCode) {
this.postalCode = Objects.requireNonNull(postalCode, "postalCode");
initBits &= ~INIT_BIT_POSTAL_CODE;
return this;
}
/**
* Initializes the value for the {@link Address#getState() state} attribute.
* @param state The value for state
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
@JsonProperty("state")
public final Builder state(String state) {
this.state = Objects.requireNonNull(state, "state");
initBits &= ~INIT_BIT_STATE;
return this;
}
/**
* Initializes the value for the {@link Address#getStreet() street} attribute.
* @param street The value for street
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
@JsonProperty("street")
public final Builder street(String street) {
this.street = Objects.requireNonNull(street, "street");
initBits &= ~INIT_BIT_STREET;
return this;
}
/**
* Initializes the value for the {@link Address#getCreated() created} attribute.
*
If not set, this attribute will have a default value as returned by the initializer of {@link Address#getCreated() created}.
* @param created The value for created
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
@JsonProperty("created")
public final Builder created(ZonedDateTime created) {
this.created = Objects.requireNonNull(created, "created");
return this;
}
/**
* Initializes the value for the {@link Address#getId() id} attribute.
*
If not set, this attribute will have a default value as returned by the initializer of {@link Address#getId() id}.
* @param id The value for id
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
@JsonProperty("id")
public final Builder id(String id) {
this.id = Objects.requireNonNull(id, "id");
return this;
}
/**
* Initializes the value for the {@link Address#getUpdated() updated} attribute.
*
If not set, this attribute will have a default value as returned by the initializer of {@link Address#getUpdated() updated}.
* @param updated The value for updated
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
@JsonProperty("updated")
public final Builder updated(ZonedDateTime updated) {
this.updated = Objects.requireNonNull(updated, "updated");
return this;
}
/**
* Builds a new {@link ImmutableAddress ImmutableAddress}.
* @return An immutable instance of Address
* @throws java.lang.IllegalStateException if any required attributes are missing
*/
public ImmutableAddress build() {
if (initBits != 0) {
throw new IllegalStateException(formatRequiredAttributesMessage());
}
return new ImmutableAddress(this);
}
private String formatRequiredAttributesMessage() {
List attributes = new ArrayList<>();
if ((initBits & INIT_BIT_CITY) != 0) attributes.add("city");
if ((initBits & INIT_BIT_POSTAL_CODE) != 0) attributes.add("postalCode");
if ((initBits & INIT_BIT_STATE) != 0) attributes.add("state");
if ((initBits & INIT_BIT_STREET) != 0) attributes.add("street");
return "Cannot build Address, some of required attributes are not set " + attributes;
}
}
}