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

com.mercateo.eventstore.data.ImmutableCausalityData Maven / Gradle / Ivy

There is a newer version: 0.3.5
Show newest version
package com.mercateo.eventstore.data;

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 java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.UUID;
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 CausalityData}.
 * 

* Use the builder to create immutable instances: * {@code ImmutableCausalityData.builder()}. */ @SuppressWarnings({"all"}) @ParametersAreNonnullByDefault @Generated({"Immutables.generator", "CausalityData"}) @Immutable public final class ImmutableCausalityData implements CausalityData { private final UUID eventId; private final String eventType; private ImmutableCausalityData(UUID eventId, String eventType) { this.eventId = eventId; this.eventType = eventType; } /** * @return The value of the {@code eventId} attribute */ @JsonProperty("eventId") @Override public UUID eventId() { return eventId; } /** * @return The value of the {@code eventType} attribute */ @JsonProperty("eventType") @Override public String eventType() { return eventType; } /** * Copy the current immutable object by setting a value for the {@link CausalityData#eventId() eventId} 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 eventId * @return A modified copy of the {@code this} object */ public final ImmutableCausalityData withEventId(UUID value) { if (this.eventId == value) return this; UUID newValue = Objects.requireNonNull(value, "eventId"); return new ImmutableCausalityData(newValue, this.eventType); } /** * Copy the current immutable object by setting a value for the {@link CausalityData#eventType() eventType} attribute. * An equals check used to prevent copying of the same value by returning {@code this}. * @param value A new value for eventType * @return A modified copy of the {@code this} object */ public final ImmutableCausalityData withEventType(String value) { if (this.eventType.equals(value)) return this; String newValue = Objects.requireNonNull(value, "eventType"); return new ImmutableCausalityData(this.eventId, newValue); } /** * This instance is equal to all instances of {@code ImmutableCausalityData} 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 ImmutableCausalityData && equalTo((ImmutableCausalityData) another); } private boolean equalTo(ImmutableCausalityData another) { return eventId.equals(another.eventId) && eventType.equals(another.eventType); } /** * Computes a hash code from attributes: {@code eventId}, {@code eventType}. * @return hashCode value */ @Override public int hashCode() { int h = 5381; h += (h << 5) + eventId.hashCode(); h += (h << 5) + eventType.hashCode(); return h; } /** * Prints the immutable value {@code CausalityData} with attribute values. * @return A string representation of the value */ @Override public String toString() { return "CausalityData{" + "eventId=" + eventId + ", eventType=" + eventType + "}"; } /** * 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 implements CausalityData { @Nullable UUID eventId; @Nullable String eventType; @JsonProperty("eventId") public void setEventId(UUID eventId) { this.eventId = eventId; } @JsonProperty("eventType") public void setEventType(String eventType) { this.eventType = eventType; } @Override public UUID eventId() { throw new UnsupportedOperationException(); } @Override public String eventType() { 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 ImmutableCausalityData fromJson(Json json) { ImmutableCausalityData.Builder builder = ImmutableCausalityData.builder(); if (json.eventId != null) { builder.eventId(json.eventId); } if (json.eventType != null) { builder.eventType(json.eventType); } return builder.build(); } /** * Creates an immutable copy of a {@link CausalityData} 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 CausalityData instance */ public static ImmutableCausalityData copyOf(CausalityData instance) { if (instance instanceof ImmutableCausalityData) { return (ImmutableCausalityData) instance; } return ImmutableCausalityData.builder() .from(instance) .build(); } /** * Creates a builder for {@link ImmutableCausalityData ImmutableCausalityData}. * @return A new ImmutableCausalityData builder */ public static ImmutableCausalityData.Builder builder() { return new ImmutableCausalityData.Builder(); } /** * Builds instances of type {@link ImmutableCausalityData ImmutableCausalityData}. * 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 public static final class Builder { private static final long INIT_BIT_EVENT_ID = 0x1L; private static final long INIT_BIT_EVENT_TYPE = 0x2L; private long initBits = 0x3L; private @Nullable UUID eventId; private @Nullable String eventType; private Builder() { } /** * Fill a builder with attribute values from the provided {@code CausalityData} 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(CausalityData instance) { Objects.requireNonNull(instance, "instance"); eventId(instance.eventId()); eventType(instance.eventType()); return this; } /** * Initializes the value for the {@link CausalityData#eventId() eventId} attribute. * @param eventId The value for eventId * @return {@code this} builder for use in a chained invocation */ @JsonProperty("eventId") public final Builder eventId(UUID eventId) { this.eventId = Objects.requireNonNull(eventId, "eventId"); initBits &= ~INIT_BIT_EVENT_ID; return this; } /** * Initializes the value for the {@link CausalityData#eventType() eventType} attribute. * @param eventType The value for eventType * @return {@code this} builder for use in a chained invocation */ @JsonProperty("eventType") public final Builder eventType(String eventType) { this.eventType = Objects.requireNonNull(eventType, "eventType"); initBits &= ~INIT_BIT_EVENT_TYPE; return this; } /** * Builds a new {@link ImmutableCausalityData ImmutableCausalityData}. * @return An immutable instance of CausalityData * @throws java.lang.IllegalStateException if any required attributes are missing */ public ImmutableCausalityData build() { if (initBits != 0) { throw new IllegalStateException(formatRequiredAttributesMessage()); } return new ImmutableCausalityData(eventId, eventType); } private String formatRequiredAttributesMessage() { List attributes = new ArrayList(); if ((initBits & INIT_BIT_EVENT_ID) != 0) attributes.add("eventId"); if ((initBits & INIT_BIT_EVENT_TYPE) != 0) attributes.add("eventType"); return "Cannot build CausalityData, some of required attributes are not set " + attributes; } } }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy