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

org.cloudfoundry.multiapps.controller.persistence.model.ImmutableProgressMessage Maven / Gradle / Ivy

There is a newer version: 1.176.0
Show newest version
package org.cloudfoundry.multiapps.controller.persistence.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 java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Objects;

/**
 * Immutable implementation of {@link ProgressMessage}.
 * 

* Use the builder to create immutable instances: * {@code ImmutableProgressMessage.builder()}. */ @SuppressWarnings({"all"}) public final class ImmutableProgressMessage implements ProgressMessage { private final long id; private final String processId; private final String taskId; private final ProgressMessage.ProgressMessageType type; private final String text; private final Date timestamp; private ImmutableProgressMessage(ImmutableProgressMessage.Builder builder) { this.processId = builder.processId; this.taskId = builder.taskId; this.type = builder.type; this.text = builder.text; if (builder.idIsSet()) { initShim.id(builder.id); } if (builder.timestamp != null) { initShim.timestamp(builder.timestamp); } this.id = initShim.getId(); this.timestamp = initShim.getTimestamp(); this.initShim = null; } private ImmutableProgressMessage( long id, String processId, String taskId, ProgressMessage.ProgressMessageType type, String text, Date timestamp) { this.id = id; this.processId = processId; this.taskId = taskId; this.type = type; this.text = text; this.timestamp = timestamp; this.initShim = null; } private static final byte STAGE_INITIALIZING = -1; private static final byte STAGE_UNINITIALIZED = 0; private static final byte STAGE_INITIALIZED = 1; private transient volatile InitShim initShim = new InitShim(); private final class InitShim { private byte idBuildStage = STAGE_UNINITIALIZED; private long id; long getId() { if (idBuildStage == STAGE_INITIALIZING) throw new IllegalStateException(formatInitCycleMessage()); if (idBuildStage == STAGE_UNINITIALIZED) { idBuildStage = STAGE_INITIALIZING; this.id = getIdInitialize(); idBuildStage = STAGE_INITIALIZED; } return this.id; } void id(long id) { this.id = id; idBuildStage = STAGE_INITIALIZED; } private byte timestampBuildStage = STAGE_UNINITIALIZED; private Date timestamp; Date getTimestamp() { if (timestampBuildStage == STAGE_INITIALIZING) throw new IllegalStateException(formatInitCycleMessage()); if (timestampBuildStage == STAGE_UNINITIALIZED) { timestampBuildStage = STAGE_INITIALIZING; this.timestamp = Objects.requireNonNull(getTimestampInitialize(), "timestamp"); timestampBuildStage = STAGE_INITIALIZED; } return this.timestamp; } void timestamp(Date timestamp) { this.timestamp = timestamp; timestampBuildStage = STAGE_INITIALIZED; } private String formatInitCycleMessage() { List attributes = new ArrayList<>(); if (idBuildStage == STAGE_INITIALIZING) attributes.add("id"); if (timestampBuildStage == STAGE_INITIALIZING) attributes.add("timestamp"); return "Cannot build ProgressMessage, attribute initializers form cycle " + attributes; } } private long getIdInitialize() { return ProgressMessage.super.getId(); } private Date getTimestampInitialize() { return ProgressMessage.super.getTimestamp(); } /** * @return The value of the {@code id} attribute */ @JsonProperty("id") @Override public long getId() { InitShim shim = this.initShim; return shim != null ? shim.getId() : this.id; } /** * @return The value of the {@code processId} attribute */ @JsonProperty("processId") @Override public String getProcessId() { return processId; } /** * @return The value of the {@code taskId} attribute */ @JsonProperty("taskId") @Override public String getTaskId() { return taskId; } /** * @return The value of the {@code type} attribute */ @JsonProperty("type") @Override public ProgressMessage.ProgressMessageType getType() { return type; } /** * @return The value of the {@code text} attribute */ @JsonProperty("text") @Override public String getText() { return text; } /** * @return The value of the {@code timestamp} attribute */ @JsonProperty("timestamp") @Override public Date getTimestamp() { InitShim shim = this.initShim; return shim != null ? shim.getTimestamp() : this.timestamp; } /** * Copy the current immutable object by setting a value for the {@link ProgressMessage#getId() id} attribute. * A value equality check is 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 ImmutableProgressMessage withId(long value) { if (this.id == value) return this; return new ImmutableProgressMessage(value, this.processId, this.taskId, this.type, this.text, this.timestamp); } /** * Copy the current immutable object by setting a value for the {@link ProgressMessage#getProcessId() processId} attribute. * An equals check used to prevent copying of the same value by returning {@code this}. * @param value A new value for processId * @return A modified copy of the {@code this} object */ public final ImmutableProgressMessage withProcessId(String value) { String newValue = Objects.requireNonNull(value, "processId"); if (this.processId.equals(newValue)) return this; return new ImmutableProgressMessage(this.id, newValue, this.taskId, this.type, this.text, this.timestamp); } /** * Copy the current immutable object by setting a value for the {@link ProgressMessage#getTaskId() taskId} attribute. * An equals check used to prevent copying of the same value by returning {@code this}. * @param value A new value for taskId * @return A modified copy of the {@code this} object */ public final ImmutableProgressMessage withTaskId(String value) { String newValue = Objects.requireNonNull(value, "taskId"); if (this.taskId.equals(newValue)) return this; return new ImmutableProgressMessage(this.id, this.processId, newValue, this.type, this.text, this.timestamp); } /** * Copy the current immutable object by setting a value for the {@link ProgressMessage#getType() type} attribute. * A value equality check is used to prevent copying of the same value by returning {@code this}. * @param value A new value for type * @return A modified copy of the {@code this} object */ public final ImmutableProgressMessage withType(ProgressMessage.ProgressMessageType value) { ProgressMessage.ProgressMessageType newValue = Objects.requireNonNull(value, "type"); if (this.type == newValue) return this; return new ImmutableProgressMessage(this.id, this.processId, this.taskId, newValue, this.text, this.timestamp); } /** * Copy the current immutable object by setting a value for the {@link ProgressMessage#getText() text} attribute. * An equals check used to prevent copying of the same value by returning {@code this}. * @param value A new value for text * @return A modified copy of the {@code this} object */ public final ImmutableProgressMessage withText(String value) { String newValue = Objects.requireNonNull(value, "text"); if (this.text.equals(newValue)) return this; return new ImmutableProgressMessage(this.id, this.processId, this.taskId, this.type, newValue, this.timestamp); } /** * Copy the current immutable object by setting a value for the {@link ProgressMessage#getTimestamp() timestamp} 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 timestamp * @return A modified copy of the {@code this} object */ public final ImmutableProgressMessage withTimestamp(Date value) { if (this.timestamp == value) return this; Date newValue = Objects.requireNonNull(value, "timestamp"); return new ImmutableProgressMessage(this.id, this.processId, this.taskId, this.type, this.text, newValue); } /** * This instance is equal to all instances of {@code ImmutableProgressMessage} that have equal attribute values. * @return {@code true} if {@code this} is equal to {@code another} instance */ @Override public boolean equals(Object another) { if (this == another) return true; return another instanceof ImmutableProgressMessage && equalTo(0, (ImmutableProgressMessage) another); } private boolean equalTo(int synthetic, ImmutableProgressMessage another) { return id == another.id && processId.equals(another.processId) && taskId.equals(another.taskId) && type.equals(another.type) && text.equals(another.text) && timestamp.equals(another.timestamp); } /** * Computes a hash code from attributes: {@code id}, {@code processId}, {@code taskId}, {@code type}, {@code text}, {@code timestamp}. * @return hashCode value */ @Override public int hashCode() { int h = 5381; h += (h << 5) + Long.hashCode(id); h += (h << 5) + processId.hashCode(); h += (h << 5) + taskId.hashCode(); h += (h << 5) + type.hashCode(); h += (h << 5) + text.hashCode(); h += (h << 5) + timestamp.hashCode(); return h; } /** * Prints the immutable value {@code ProgressMessage} with attribute values. * @return A string representation of the value */ @Override public String toString() { return "ProgressMessage{" + "id=" + id + ", processId=" + processId + ", taskId=" + taskId + ", type=" + type + ", text=" + text + ", timestamp=" + timestamp + "}"; } /** * 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 ProgressMessage { long id; boolean idIsSet; String processId; String taskId; ProgressMessage.ProgressMessageType type; String text; Date timestamp; @JsonProperty("id") public void setId(long id) { this.id = id; this.idIsSet = true; } @JsonProperty("processId") public void setProcessId(String processId) { this.processId = processId; } @JsonProperty("taskId") public void setTaskId(String taskId) { this.taskId = taskId; } @JsonProperty("type") public void setType(ProgressMessage.ProgressMessageType type) { this.type = type; } @JsonProperty("text") public void setText(String text) { this.text = text; } @JsonProperty("timestamp") public void setTimestamp(Date timestamp) { this.timestamp = timestamp; } @Override public long getId() { throw new UnsupportedOperationException(); } @Override public String getProcessId() { throw new UnsupportedOperationException(); } @Override public String getTaskId() { throw new UnsupportedOperationException(); } @Override public ProgressMessage.ProgressMessageType getType() { throw new UnsupportedOperationException(); } @Override public String getText() { throw new UnsupportedOperationException(); } @Override public Date getTimestamp() { 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 ImmutableProgressMessage fromJson(Json json) { ImmutableProgressMessage.Builder builder = ImmutableProgressMessage.builder(); if (json.idIsSet) { builder.id(json.id); } if (json.processId != null) { builder.processId(json.processId); } if (json.taskId != null) { builder.taskId(json.taskId); } if (json.type != null) { builder.type(json.type); } if (json.text != null) { builder.text(json.text); } if (json.timestamp != null) { builder.timestamp(json.timestamp); } return builder.build(); } /** * Creates an immutable copy of a {@link ProgressMessage} 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 ProgressMessage instance */ public static ImmutableProgressMessage copyOf(ProgressMessage instance) { if (instance instanceof ImmutableProgressMessage) { return (ImmutableProgressMessage) instance; } return ImmutableProgressMessage.builder() .from(instance) .build(); } /** * Creates a builder for {@link ImmutableProgressMessage ImmutableProgressMessage}. *

   * ImmutableProgressMessage.builder()
   *    .id(long) // optional {@link ProgressMessage#getId() id}
   *    .processId(String) // required {@link ProgressMessage#getProcessId() processId}
   *    .taskId(String) // required {@link ProgressMessage#getTaskId() taskId}
   *    .type(org.cloudfoundry.multiapps.controller.persistence.model.ProgressMessage.ProgressMessageType) // required {@link ProgressMessage#getType() type}
   *    .text(String) // required {@link ProgressMessage#getText() text}
   *    .timestamp(Date) // optional {@link ProgressMessage#getTimestamp() timestamp}
   *    .build();
   * 
* @return A new ImmutableProgressMessage builder */ public static ImmutableProgressMessage.Builder builder() { return new ImmutableProgressMessage.Builder(); } /** * Builds instances of type {@link ImmutableProgressMessage ImmutableProgressMessage}. * 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. */ public static final class Builder { private static final long INIT_BIT_PROCESS_ID = 0x1L; private static final long INIT_BIT_TASK_ID = 0x2L; private static final long INIT_BIT_TYPE = 0x4L; private static final long INIT_BIT_TEXT = 0x8L; private static final long OPT_BIT_ID = 0x1L; private long initBits = 0xfL; private long optBits; private long id; private String processId; private String taskId; private ProgressMessage.ProgressMessageType type; private String text; private Date timestamp; private Builder() { } /** * Fill a builder with attribute values from the provided {@code ProgressMessage} 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(ProgressMessage instance) { Objects.requireNonNull(instance, "instance"); this.id(instance.getId()); this.processId(instance.getProcessId()); this.taskId(instance.getTaskId()); this.type(instance.getType()); this.text(instance.getText()); this.timestamp(instance.getTimestamp()); return this; } /** * Initializes the value for the {@link ProgressMessage#getId() id} attribute. *

If not set, this attribute will have a default value as returned by the initializer of {@link ProgressMessage#getId() id}. * @param id The value for id * @return {@code this} builder for use in a chained invocation */ @JsonProperty("id") public final Builder id(long id) { this.id = id; optBits |= OPT_BIT_ID; return this; } /** * Initializes the value for the {@link ProgressMessage#getProcessId() processId} attribute. * @param processId The value for processId * @return {@code this} builder for use in a chained invocation */ @JsonProperty("processId") public final Builder processId(String processId) { this.processId = Objects.requireNonNull(processId, "processId"); initBits &= ~INIT_BIT_PROCESS_ID; return this; } /** * Initializes the value for the {@link ProgressMessage#getTaskId() taskId} attribute. * @param taskId The value for taskId * @return {@code this} builder for use in a chained invocation */ @JsonProperty("taskId") public final Builder taskId(String taskId) { this.taskId = Objects.requireNonNull(taskId, "taskId"); initBits &= ~INIT_BIT_TASK_ID; return this; } /** * Initializes the value for the {@link ProgressMessage#getType() type} attribute. * @param type The value for type * @return {@code this} builder for use in a chained invocation */ @JsonProperty("type") public final Builder type(ProgressMessage.ProgressMessageType type) { this.type = Objects.requireNonNull(type, "type"); initBits &= ~INIT_BIT_TYPE; return this; } /** * Initializes the value for the {@link ProgressMessage#getText() text} attribute. * @param text The value for text * @return {@code this} builder for use in a chained invocation */ @JsonProperty("text") public final Builder text(String text) { this.text = Objects.requireNonNull(text, "text"); initBits &= ~INIT_BIT_TEXT; return this; } /** * Initializes the value for the {@link ProgressMessage#getTimestamp() timestamp} attribute. *

If not set, this attribute will have a default value as returned by the initializer of {@link ProgressMessage#getTimestamp() timestamp}. * @param timestamp The value for timestamp * @return {@code this} builder for use in a chained invocation */ @JsonProperty("timestamp") public final Builder timestamp(Date timestamp) { this.timestamp = Objects.requireNonNull(timestamp, "timestamp"); return this; } /** * Builds a new {@link ImmutableProgressMessage ImmutableProgressMessage}. * @return An immutable instance of ProgressMessage * @throws java.lang.IllegalStateException if any required attributes are missing */ public ImmutableProgressMessage build() { if (initBits != 0) { throw new IllegalStateException(formatRequiredAttributesMessage()); } return new ImmutableProgressMessage(this); } private boolean idIsSet() { return (optBits & OPT_BIT_ID) != 0; } private String formatRequiredAttributesMessage() { List attributes = new ArrayList<>(); if ((initBits & INIT_BIT_PROCESS_ID) != 0) attributes.add("processId"); if ((initBits & INIT_BIT_TASK_ID) != 0) attributes.add("taskId"); if ((initBits & INIT_BIT_TYPE) != 0) attributes.add("type"); if ((initBits & INIT_BIT_TEXT) != 0) attributes.add("text"); return "Cannot build ProgressMessage, some of required attributes are not set " + attributes; } } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy