com.mercateo.eventstore.domain.ImmutableEventStreamId Maven / Gradle / Ivy
Show all versions of client-common Show documentation
package com.mercateo.eventstore.domain;
import java.util.Objects;
import javax.annotation.Generated;
import javax.annotation.Nullable;
import javax.annotation.ParametersAreNonnullByDefault;
import javax.annotation.concurrent.Immutable;
/**
* Immutable implementation of {@link EventStreamId}.
*
* Use the static factory method to create immutable instances:
* {@code ImmutableEventStreamId.of()}.
*/
@SuppressWarnings({"all"})
@ParametersAreNonnullByDefault
@Generated({"Immutables.generator", "EventStreamId"})
@Immutable
public final class ImmutableEventStreamId extends EventStreamId {
private final EventStoreName eventStoreName;
private final EventStreamName eventStreamName;
private ImmutableEventStreamId(
EventStoreName eventStoreName,
EventStreamName eventStreamName) {
this.eventStoreName = Objects.requireNonNull(eventStoreName, "eventStoreName");
this.eventStreamName = Objects.requireNonNull(eventStreamName, "eventStreamName");
}
private ImmutableEventStreamId(
ImmutableEventStreamId original,
EventStoreName eventStoreName,
EventStreamName eventStreamName) {
this.eventStoreName = eventStoreName;
this.eventStreamName = eventStreamName;
}
/**
* @return The value of the {@code eventStoreName} attribute
*/
@Override
public EventStoreName eventStoreName() {
return eventStoreName;
}
/**
* @return The value of the {@code eventStreamName} attribute
*/
@Override
public EventStreamName eventStreamName() {
return eventStreamName;
}
/**
* Copy the current immutable object by setting a value for the {@link EventStreamId#eventStoreName() eventStoreName} 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 eventStoreName
* @return A modified copy of the {@code this} object
*/
public final ImmutableEventStreamId withEventStoreName(EventStoreName value) {
if (this.eventStoreName == value) return this;
EventStoreName newValue = Objects.requireNonNull(value, "eventStoreName");
return new ImmutableEventStreamId(this, newValue, this.eventStreamName);
}
/**
* Copy the current immutable object by setting a value for the {@link EventStreamId#eventStreamName() eventStreamName} 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 eventStreamName
* @return A modified copy of the {@code this} object
*/
public final ImmutableEventStreamId withEventStreamName(EventStreamName value) {
if (this.eventStreamName == value) return this;
EventStreamName newValue = Objects.requireNonNull(value, "eventStreamName");
return new ImmutableEventStreamId(this, this.eventStoreName, newValue);
}
/**
* This instance is equal to all instances of {@code ImmutableEventStreamId} 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 ImmutableEventStreamId
&& equalTo((ImmutableEventStreamId) another);
}
private boolean equalTo(ImmutableEventStreamId another) {
return eventStoreName.equals(another.eventStoreName)
&& eventStreamName.equals(another.eventStreamName);
}
/**
* Computes a hash code from attributes: {@code eventStoreName}, {@code eventStreamName}.
* @return hashCode value
*/
@Override
public int hashCode() {
int h = 5381;
h += (h << 5) + eventStoreName.hashCode();
h += (h << 5) + eventStreamName.hashCode();
return h;
}
/**
* Construct a new immutable {@code EventStreamId} instance.
* @param eventStoreName The value for the {@code eventStoreName} attribute
* @param eventStreamName The value for the {@code eventStreamName} attribute
* @return An immutable EventStreamId instance
*/
public static ImmutableEventStreamId of(EventStoreName eventStoreName, EventStreamName eventStreamName) {
return new ImmutableEventStreamId(eventStoreName, eventStreamName);
}
/**
* Creates an immutable copy of a {@link EventStreamId} 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 EventStreamId instance
*/
public static ImmutableEventStreamId copyOf(EventStreamId instance) {
if (instance instanceof ImmutableEventStreamId) {
return (ImmutableEventStreamId) instance;
}
return ImmutableEventStreamId.of(instance.eventStoreName(), instance.eventStreamName());
}
}