All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.mercateo.eventstore.writer.ImmutableEventWriteData Maven / Gradle / Ivy

package com.mercateo.eventstore.writer;

import com.github.msemys.esjc.EventData;
import com.mercateo.eventstore.domain.EventStreamId;
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 EventWriteData}.
 * 

* Use the static factory method to create immutable instances: * {@code ImmutableEventWriteData.of()}. */ @SuppressWarnings({"all"}) @ParametersAreNonnullByDefault @Generated({"Immutables.generator", "EventWriteData"}) @Immutable public final class ImmutableEventWriteData implements EventWriteData { private final EventStreamId eventStreamId; private final Iterable eventData; private ImmutableEventWriteData( EventStreamId eventStreamId, Iterable eventData) { this.eventStreamId = Objects.requireNonNull(eventStreamId, "eventStreamId"); this.eventData = Objects.requireNonNull(eventData, "eventData"); } private ImmutableEventWriteData( ImmutableEventWriteData original, EventStreamId eventStreamId, Iterable eventData) { this.eventStreamId = eventStreamId; this.eventData = eventData; } /** * @return The value of the {@code eventStreamId} attribute */ @Override public EventStreamId eventStreamId() { return eventStreamId; } /** * @return The value of the {@code eventData} attribute */ @Override public Iterable eventData() { return eventData; } /** * Copy the current immutable object by setting a value for the {@link EventWriteData#eventStreamId() eventStreamId} 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 eventStreamId * @return A modified copy of the {@code this} object */ public final ImmutableEventWriteData withEventStreamId(EventStreamId value) { if (this.eventStreamId == value) return this; EventStreamId newValue = Objects.requireNonNull(value, "eventStreamId"); return new ImmutableEventWriteData(this, newValue, this.eventData); } /** * Copy the current immutable object by setting a value for the {@link EventWriteData#eventData() eventData} 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 eventData * @return A modified copy of the {@code this} object */ public final ImmutableEventWriteData withEventData(Iterable value) { if (this.eventData == value) return this; Iterable newValue = Objects.requireNonNull(value, "eventData"); return new ImmutableEventWriteData(this, this.eventStreamId, newValue); } /** * This instance is equal to all instances of {@code ImmutableEventWriteData} 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 ImmutableEventWriteData && equalTo((ImmutableEventWriteData) another); } private boolean equalTo(ImmutableEventWriteData another) { return eventStreamId.equals(another.eventStreamId) && eventData.equals(another.eventData); } /** * Computes a hash code from attributes: {@code eventStreamId}, {@code eventData}. * @return hashCode value */ @Override public int hashCode() { int h = 5381; h += (h << 5) + eventStreamId.hashCode(); h += (h << 5) + eventData.hashCode(); return h; } /** * Prints the immutable value {@code EventWriteData} with attribute values. * @return A string representation of the value */ @Override public String toString() { return "EventWriteData{" + "eventStreamId=" + eventStreamId + ", eventData=" + eventData + "}"; } /** * Construct a new immutable {@code EventWriteData} instance. * @param eventStreamId The value for the {@code eventStreamId} attribute * @param eventData The value for the {@code eventData} attribute * @return An immutable EventWriteData instance */ public static ImmutableEventWriteData of(EventStreamId eventStreamId, Iterable eventData) { return new ImmutableEventWriteData(eventStreamId, eventData); } /** * Creates an immutable copy of a {@link EventWriteData} 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 EventWriteData instance */ public static ImmutableEventWriteData copyOf(EventWriteData instance) { if (instance instanceof ImmutableEventWriteData) { return (ImmutableEventWriteData) instance; } return ImmutableEventWriteData.of(instance.eventStreamId(), instance.eventData()); } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy