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

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

package org.cloudfoundry.multiapps.controller.persistence.model;

import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

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

* Use the builder to create immutable instances: * {@code ImmutableLockOwnerEntry.builder()}. */ @SuppressWarnings({"all"}) public final class ImmutableLockOwnerEntry implements LockOwnerEntry { private final long id; private final String lockOwner; private final LocalDateTime timestamp; private ImmutableLockOwnerEntry(ImmutableLockOwnerEntry.Builder builder) { this.lockOwner = builder.lockOwner; this.timestamp = builder.timestamp; this.id = builder.idIsSet() ? builder.id : LockOwnerEntry.super.getId(); } private ImmutableLockOwnerEntry(long id, String lockOwner, LocalDateTime timestamp) { this.id = id; this.lockOwner = lockOwner; this.timestamp = timestamp; } /** * @return The value of the {@code id} attribute */ @Override public long getId() { return id; } /** * @return The value of the {@code lockOwner} attribute */ @Override public String getLockOwner() { return lockOwner; } /** * @return The value of the {@code timestamp} attribute */ @Override public LocalDateTime getTimestamp() { return timestamp; } /** * Copy the current immutable object by setting a value for the {@link LockOwnerEntry#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 ImmutableLockOwnerEntry withId(long value) { if (this.id == value) return this; return new ImmutableLockOwnerEntry(value, this.lockOwner, this.timestamp); } /** * Copy the current immutable object by setting a value for the {@link LockOwnerEntry#getLockOwner() lockOwner} attribute. * An equals check used to prevent copying of the same value by returning {@code this}. * @param value A new value for lockOwner * @return A modified copy of the {@code this} object */ public final ImmutableLockOwnerEntry withLockOwner(String value) { String newValue = Objects.requireNonNull(value, "lockOwner"); if (this.lockOwner.equals(newValue)) return this; return new ImmutableLockOwnerEntry(this.id, newValue, this.timestamp); } /** * Copy the current immutable object by setting a value for the {@link LockOwnerEntry#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 ImmutableLockOwnerEntry withTimestamp(LocalDateTime value) { if (this.timestamp == value) return this; LocalDateTime newValue = Objects.requireNonNull(value, "timestamp"); return new ImmutableLockOwnerEntry(this.id, this.lockOwner, newValue); } /** * This instance is equal to all instances of {@code ImmutableLockOwnerEntry} 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 ImmutableLockOwnerEntry && equalTo(0, (ImmutableLockOwnerEntry) another); } private boolean equalTo(int synthetic, ImmutableLockOwnerEntry another) { return id == another.id && lockOwner.equals(another.lockOwner) && timestamp.equals(another.timestamp); } /** * Computes a hash code from attributes: {@code id}, {@code lockOwner}, {@code timestamp}. * @return hashCode value */ @Override public int hashCode() { int h = 5381; h += (h << 5) + Long.hashCode(id); h += (h << 5) + lockOwner.hashCode(); h += (h << 5) + timestamp.hashCode(); return h; } /** * Prints the immutable value {@code LockOwnerEntry} with attribute values. * @return A string representation of the value */ @Override public String toString() { return "LockOwnerEntry{" + "id=" + id + ", lockOwner=" + lockOwner + ", timestamp=" + timestamp + "}"; } /** * Creates an immutable copy of a {@link LockOwnerEntry} 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 LockOwnerEntry instance */ public static ImmutableLockOwnerEntry copyOf(LockOwnerEntry instance) { if (instance instanceof ImmutableLockOwnerEntry) { return (ImmutableLockOwnerEntry) instance; } return ImmutableLockOwnerEntry.builder() .from(instance) .build(); } /** * Creates a builder for {@link ImmutableLockOwnerEntry ImmutableLockOwnerEntry}. *

   * ImmutableLockOwnerEntry.builder()
   *    .id(long) // optional {@link LockOwnerEntry#getId() id}
   *    .lockOwner(String) // required {@link LockOwnerEntry#getLockOwner() lockOwner}
   *    .timestamp(java.time.LocalDateTime) // required {@link LockOwnerEntry#getTimestamp() timestamp}
   *    .build();
   * 
* @return A new ImmutableLockOwnerEntry builder */ public static ImmutableLockOwnerEntry.Builder builder() { return new ImmutableLockOwnerEntry.Builder(); } /** * Builds instances of type {@link ImmutableLockOwnerEntry ImmutableLockOwnerEntry}. * 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_LOCK_OWNER = 0x1L; private static final long INIT_BIT_TIMESTAMP = 0x2L; private static final long OPT_BIT_ID = 0x1L; private long initBits = 0x3L; private long optBits; private long id; private String lockOwner; private LocalDateTime timestamp; private Builder() { } /** * Fill a builder with attribute values from the provided {@code LockOwnerEntry} 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(LockOwnerEntry instance) { Objects.requireNonNull(instance, "instance"); this.id(instance.getId()); this.lockOwner(instance.getLockOwner()); this.timestamp(instance.getTimestamp()); return this; } /** * Initializes the value for the {@link LockOwnerEntry#getId() id} attribute. *

If not set, this attribute will have a default value as returned by the initializer of {@link LockOwnerEntry#getId() id}. * @param id The value for id * @return {@code this} builder for use in a chained invocation */ public final Builder id(long id) { this.id = id; optBits |= OPT_BIT_ID; return this; } /** * Initializes the value for the {@link LockOwnerEntry#getLockOwner() lockOwner} attribute. * @param lockOwner The value for lockOwner * @return {@code this} builder for use in a chained invocation */ public final Builder lockOwner(String lockOwner) { this.lockOwner = Objects.requireNonNull(lockOwner, "lockOwner"); initBits &= ~INIT_BIT_LOCK_OWNER; return this; } /** * Initializes the value for the {@link LockOwnerEntry#getTimestamp() timestamp} attribute. * @param timestamp The value for timestamp * @return {@code this} builder for use in a chained invocation */ public final Builder timestamp(LocalDateTime timestamp) { this.timestamp = Objects.requireNonNull(timestamp, "timestamp"); initBits &= ~INIT_BIT_TIMESTAMP; return this; } /** * Builds a new {@link ImmutableLockOwnerEntry ImmutableLockOwnerEntry}. * @return An immutable instance of LockOwnerEntry * @throws java.lang.IllegalStateException if any required attributes are missing */ public ImmutableLockOwnerEntry build() { if (initBits != 0) { throw new IllegalStateException(formatRequiredAttributesMessage()); } return new ImmutableLockOwnerEntry(this); } private boolean idIsSet() { return (optBits & OPT_BIT_ID) != 0; } private String formatRequiredAttributesMessage() { List attributes = new ArrayList<>(); if ((initBits & INIT_BIT_LOCK_OWNER) != 0) attributes.add("lockOwner"); if ((initBits & INIT_BIT_TIMESTAMP) != 0) attributes.add("timestamp"); return "Cannot build LockOwnerEntry, some of required attributes are not set " + attributes; } } }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy