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

io.syndesis.common.model.bulletin.ImmutableConnectionBulletinBoard Maven / Gradle / Ivy

There is a newer version: 1.13.2
Show newest version
/*
 * Copyright (C) 2016 Red Hat, Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package io.syndesis.common.model.bulletin;

import com.fasterxml.jackson.annotation.JsonProperty;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import io.syndesis.common.model.WithMetadata;
import io.syndesis.common.model.WithModificationTimestamps;
import io.syndesis.common.model.WithResourceId;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.OptionalInt;
import java.util.Set;
import javax.annotation.Generated;
import javax.validation.ConstraintViolation;
import javax.validation.ConstraintViolationException;
import javax.validation.Validation;
import javax.validation.Validator;

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

* Use the builder to create immutable instances: * {@code new ConnectionBulletinBoard.Builder()}. * Use the static factory method to create immutable instances: * {@code ImmutableConnectionBulletinBoard.of()}. */ @SuppressWarnings({"all"}) @SuppressFBWarnings @Generated({"Immutables.generator", "ConnectionBulletinBoard"}) final class ImmutableConnectionBulletinBoard implements ConnectionBulletinBoard { private final String id; private final String targetResourceId; private final Integer notices; private final Integer warnings; private final Integer errors; private final Map metadata; private final List messages; private final long createdAt; private final long updatedAt; private ImmutableConnectionBulletinBoard( Optional id, String targetResourceId, OptionalInt notices, OptionalInt warnings, OptionalInt errors, Map metadata, Iterable messages, long createdAt, long updatedAt) { this.id = id.orElse(null); this.targetResourceId = targetResourceId; this.notices = notices.isPresent() ? notices.getAsInt() : null; this.warnings = warnings.isPresent() ? warnings.getAsInt() : null; this.errors = errors.isPresent() ? errors.getAsInt() : null; this.metadata = createUnmodifiableMap(true, false, metadata); this.messages = createUnmodifiableList(false, createSafeList(messages, true, false)); this.createdAt = createdAt; this.updatedAt = updatedAt; initShim.metadata(this.metadata); initShim.messages(this.messages); initShim.createdAt(this.createdAt); initShim.updatedAt(this.updatedAt); this.initShim = null; } private ImmutableConnectionBulletinBoard(ImmutableConnectionBulletinBoard.Builder builder) { this.id = builder.id; this.targetResourceId = builder.targetResourceId; this.notices = builder.notices; this.warnings = builder.warnings; this.errors = builder.errors; if (builder.metadataIsSet()) { initShim.metadata(createUnmodifiableMap(false, false, builder.metadata)); } if (builder.messagesIsSet()) { initShim.messages(createUnmodifiableList(true, builder.messages)); } if (builder.createdAtIsSet()) { initShim.createdAt(builder.createdAt); } if (builder.updatedAtIsSet()) { initShim.updatedAt(builder.updatedAt); } this.metadata = initShim.getMetadata(); this.messages = initShim.getMessages(); this.createdAt = initShim.getCreatedAt(); this.updatedAt = initShim.getUpdatedAt(); this.initShim = null; } private ImmutableConnectionBulletinBoard( ImmutableConnectionBulletinBoard original, String id, String targetResourceId, Integer notices, Integer warnings, Integer errors, Map metadata, List messages, long createdAt, long updatedAt) { this.id = id; this.targetResourceId = targetResourceId; this.notices = notices; this.warnings = warnings; this.errors = errors; this.metadata = metadata; this.messages = messages; this.createdAt = createdAt; this.updatedAt = updatedAt; this.initShim = null; } private static final int STAGE_INITIALIZING = -1; private static final int STAGE_UNINITIALIZED = 0; private static final int STAGE_INITIALIZED = 1; private transient volatile InitShim initShim = new InitShim(); private final class InitShim { private Map metadata; private int metadataBuildStage; Map getMetadata() { if (metadataBuildStage == STAGE_INITIALIZING) throw new IllegalStateException(formatInitCycleMessage()); if (metadataBuildStage == STAGE_UNINITIALIZED) { metadataBuildStage = STAGE_INITIALIZING; this.metadata = createUnmodifiableMap(true, false, getMetadataInitialize()); metadataBuildStage = STAGE_INITIALIZED; } return this.metadata; } void metadata(Map metadata) { this.metadata = metadata; metadataBuildStage = STAGE_INITIALIZED; } private List messages; private int messagesBuildStage; List getMessages() { if (messagesBuildStage == STAGE_INITIALIZING) throw new IllegalStateException(formatInitCycleMessage()); if (messagesBuildStage == STAGE_UNINITIALIZED) { messagesBuildStage = STAGE_INITIALIZING; this.messages = createUnmodifiableList(false, createSafeList(getMessagesInitialize(), true, false)); messagesBuildStage = STAGE_INITIALIZED; } return this.messages; } void messages(List messages) { this.messages = messages; messagesBuildStage = STAGE_INITIALIZED; } private long createdAt; private int createdAtBuildStage; long getCreatedAt() { if (createdAtBuildStage == STAGE_INITIALIZING) throw new IllegalStateException(formatInitCycleMessage()); if (createdAtBuildStage == STAGE_UNINITIALIZED) { createdAtBuildStage = STAGE_INITIALIZING; this.createdAt = getCreatedAtInitialize(); createdAtBuildStage = STAGE_INITIALIZED; } return this.createdAt; } void createdAt(long createdAt) { this.createdAt = createdAt; createdAtBuildStage = STAGE_INITIALIZED; } private long updatedAt; private int updatedAtBuildStage; long getUpdatedAt() { if (updatedAtBuildStage == STAGE_INITIALIZING) throw new IllegalStateException(formatInitCycleMessage()); if (updatedAtBuildStage == STAGE_UNINITIALIZED) { updatedAtBuildStage = STAGE_INITIALIZING; this.updatedAt = getUpdatedAtInitialize(); updatedAtBuildStage = STAGE_INITIALIZED; } return this.updatedAt; } void updatedAt(long updatedAt) { this.updatedAt = updatedAt; updatedAtBuildStage = STAGE_INITIALIZED; } private String formatInitCycleMessage() { ArrayList attributes = new ArrayList(); if (metadataBuildStage == STAGE_INITIALIZING) attributes.add("metadata"); if (messagesBuildStage == STAGE_INITIALIZING) attributes.add("messages"); if (createdAtBuildStage == STAGE_INITIALIZING) attributes.add("createdAt"); if (updatedAtBuildStage == STAGE_INITIALIZING) attributes.add("updatedAt"); return "Cannot build ConnectionBulletinBoard, attribute initializers form cycle" + attributes; } } private Map getMetadataInitialize() { return ConnectionBulletinBoard.super.getMetadata(); } private List getMessagesInitialize() { return ConnectionBulletinBoard.super.getMessages(); } private long getCreatedAtInitialize() { return ConnectionBulletinBoard.super.getCreatedAt(); } private long getUpdatedAtInitialize() { return ConnectionBulletinBoard.super.getUpdatedAt(); } /** * @return The value of the {@code id} attribute */ @JsonProperty("id") @Override public Optional getId() { return Optional.ofNullable(id); } /** * @return The value of the {@code targetResourceId} attribute */ @JsonProperty("targetResourceId") @Override public String getTargetResourceId() { return targetResourceId; } /** * @return The value of the {@code notices} attribute */ @JsonProperty("notices") @Override public OptionalInt getNotices() { return notices != null ? OptionalInt.of(notices) : OptionalInt.empty(); } /** * @return The value of the {@code warnings} attribute */ @JsonProperty("warnings") @Override public OptionalInt getWarnings() { return warnings != null ? OptionalInt.of(warnings) : OptionalInt.empty(); } /** * @return The value of the {@code errors} attribute */ @JsonProperty("errors") @Override public OptionalInt getErrors() { return errors != null ? OptionalInt.of(errors) : OptionalInt.empty(); } /** * @return The value of the {@code metadata} attribute */ @JsonProperty("metadata") @Override public Map getMetadata() { InitShim shim = this.initShim; return shim != null ? shim.getMetadata() : this.metadata; } /** * @return The value of the {@code messages} attribute */ @JsonProperty("messages") @Override public List getMessages() { InitShim shim = this.initShim; return shim != null ? shim.getMessages() : this.messages; } /** * @return The value of the {@code createdAt} attribute */ @JsonProperty("createdAt") @Override public long getCreatedAt() { InitShim shim = this.initShim; return shim != null ? shim.getCreatedAt() : this.createdAt; } /** * @return The value of the {@code updatedAt} attribute */ @JsonProperty("updatedAt") @Override public long getUpdatedAt() { InitShim shim = this.initShim; return shim != null ? shim.getUpdatedAt() : this.updatedAt; } /** * Copy the current immutable object by setting a present value for the optional {@link ConnectionBulletinBoard#getId() id} attribute. * @param value The value for id * @return A modified copy of {@code this} object */ public final ImmutableConnectionBulletinBoard withId(String value) { String newValue = Objects.requireNonNull(value, "id"); if (Objects.equals(this.id, newValue)) return this; return validate(new ImmutableConnectionBulletinBoard( this, newValue, this.targetResourceId, this.notices, this.warnings, this.errors, this.metadata, this.messages, this.createdAt, this.updatedAt)); } /** * Copy the current immutable object by setting an optional value for the {@link ConnectionBulletinBoard#getId() id} attribute. * An equality check is used on inner nullable value to prevent copying of the same value by returning {@code this}. * @param optional A value for id * @return A modified copy of {@code this} object */ public final ImmutableConnectionBulletinBoard withId(Optional optional) { String value = optional.orElse(null); if (Objects.equals(this.id, value)) return this; return validate(new ImmutableConnectionBulletinBoard( this, value, this.targetResourceId, this.notices, this.warnings, this.errors, this.metadata, this.messages, this.createdAt, this.updatedAt)); } /** * Copy the current immutable object by setting a value for the {@link ConnectionBulletinBoard#getTargetResourceId() targetResourceId} attribute. * An equals check used to prevent copying of the same value by returning {@code this}. * @param value A new value for targetResourceId (can be {@code null}) * @return A modified copy of the {@code this} object */ public final ImmutableConnectionBulletinBoard withTargetResourceId(String value) { if (Objects.equals(this.targetResourceId, value)) return this; return validate(new ImmutableConnectionBulletinBoard( this, this.id, value, this.notices, this.warnings, this.errors, this.metadata, this.messages, this.createdAt, this.updatedAt)); } /** * Copy the current immutable object by setting a present value for the optional {@link ConnectionBulletinBoard#getNotices() notices} attribute. * @param value The value for notices * @return A modified copy of {@code this} object */ public final ImmutableConnectionBulletinBoard withNotices(int value) { Integer newValue = value; if (Objects.equals(this.notices, newValue)) return this; return validate(new ImmutableConnectionBulletinBoard( this, this.id, this.targetResourceId, newValue, this.warnings, this.errors, this.metadata, this.messages, this.createdAt, this.updatedAt)); } /** * Copy the current immutable object by setting an optional value for the {@link ConnectionBulletinBoard#getNotices() notices} attribute. * An equality check is used on inner nullable value to prevent copying of the same value by returning {@code this}. * @param optional A value for notices * @return A modified copy of {@code this} object */ public final ImmutableConnectionBulletinBoard withNotices(OptionalInt optional) { Integer value = optional.isPresent() ? optional.getAsInt() : null; if (Objects.equals(this.notices, value)) return this; return validate(new ImmutableConnectionBulletinBoard( this, this.id, this.targetResourceId, value, this.warnings, this.errors, this.metadata, this.messages, this.createdAt, this.updatedAt)); } /** * Copy the current immutable object by setting a present value for the optional {@link ConnectionBulletinBoard#getWarnings() warnings} attribute. * @param value The value for warnings * @return A modified copy of {@code this} object */ public final ImmutableConnectionBulletinBoard withWarnings(int value) { Integer newValue = value; if (Objects.equals(this.warnings, newValue)) return this; return validate(new ImmutableConnectionBulletinBoard( this, this.id, this.targetResourceId, this.notices, newValue, this.errors, this.metadata, this.messages, this.createdAt, this.updatedAt)); } /** * Copy the current immutable object by setting an optional value for the {@link ConnectionBulletinBoard#getWarnings() warnings} attribute. * An equality check is used on inner nullable value to prevent copying of the same value by returning {@code this}. * @param optional A value for warnings * @return A modified copy of {@code this} object */ public final ImmutableConnectionBulletinBoard withWarnings(OptionalInt optional) { Integer value = optional.isPresent() ? optional.getAsInt() : null; if (Objects.equals(this.warnings, value)) return this; return validate(new ImmutableConnectionBulletinBoard( this, this.id, this.targetResourceId, this.notices, value, this.errors, this.metadata, this.messages, this.createdAt, this.updatedAt)); } /** * Copy the current immutable object by setting a present value for the optional {@link ConnectionBulletinBoard#getErrors() errors} attribute. * @param value The value for errors * @return A modified copy of {@code this} object */ public final ImmutableConnectionBulletinBoard withErrors(int value) { Integer newValue = value; if (Objects.equals(this.errors, newValue)) return this; return validate(new ImmutableConnectionBulletinBoard( this, this.id, this.targetResourceId, this.notices, this.warnings, newValue, this.metadata, this.messages, this.createdAt, this.updatedAt)); } /** * Copy the current immutable object by setting an optional value for the {@link ConnectionBulletinBoard#getErrors() errors} attribute. * An equality check is used on inner nullable value to prevent copying of the same value by returning {@code this}. * @param optional A value for errors * @return A modified copy of {@code this} object */ public final ImmutableConnectionBulletinBoard withErrors(OptionalInt optional) { Integer value = optional.isPresent() ? optional.getAsInt() : null; if (Objects.equals(this.errors, value)) return this; return validate(new ImmutableConnectionBulletinBoard( this, this.id, this.targetResourceId, this.notices, this.warnings, value, this.metadata, this.messages, this.createdAt, this.updatedAt)); } /** * Copy the current immutable object by replacing the {@link ConnectionBulletinBoard#getMetadata() metadata} map with the specified map. * Nulls are not permitted as keys or values. * A shallow reference equality check is used to prevent copying of the same value by returning {@code this}. * @param entries The entries to be added to the metadata map * @return A modified copy of {@code this} object */ public final ImmutableConnectionBulletinBoard withMetadata(Map entries) { if (this.metadata == entries) return this; Map newValue = createUnmodifiableMap(true, false, entries); return validate(new ImmutableConnectionBulletinBoard( this, this.id, this.targetResourceId, this.notices, this.warnings, this.errors, newValue, this.messages, this.createdAt, this.updatedAt)); } /** * Copy the current immutable object with elements that replace the content of {@link ConnectionBulletinBoard#getMessages() messages}. * @param elements The elements to set * @return A modified copy of {@code this} object */ public final ImmutableConnectionBulletinBoard withMessages(LeveledMessage... elements) { List newValue = createUnmodifiableList(false, createSafeList(Arrays.asList(elements), true, false)); return validate(new ImmutableConnectionBulletinBoard( this, this.id, this.targetResourceId, this.notices, this.warnings, this.errors, this.metadata, newValue, this.createdAt, this.updatedAt)); } /** * Copy the current immutable object with elements that replace the content of {@link ConnectionBulletinBoard#getMessages() messages}. * A shallow reference equality check is used to prevent copying of the same value by returning {@code this}. * @param elements An iterable of messages elements to set * @return A modified copy of {@code this} object */ public final ImmutableConnectionBulletinBoard withMessages(Iterable elements) { if (this.messages == elements) return this; List newValue = createUnmodifiableList(false, createSafeList(elements, true, false)); return validate(new ImmutableConnectionBulletinBoard( this, this.id, this.targetResourceId, this.notices, this.warnings, this.errors, this.metadata, newValue, this.createdAt, this.updatedAt)); } /** * Copy the current immutable object by setting a value for the {@link ConnectionBulletinBoard#getCreatedAt() createdAt} attribute. * A value equality check is used to prevent copying of the same value by returning {@code this}. * @param value A new value for createdAt * @return A modified copy of the {@code this} object */ public final ImmutableConnectionBulletinBoard withCreatedAt(long value) { if (this.createdAt == value) return this; return validate(new ImmutableConnectionBulletinBoard( this, this.id, this.targetResourceId, this.notices, this.warnings, this.errors, this.metadata, this.messages, value, this.updatedAt)); } /** * Copy the current immutable object by setting a value for the {@link ConnectionBulletinBoard#getUpdatedAt() updatedAt} attribute. * A value equality check is used to prevent copying of the same value by returning {@code this}. * @param value A new value for updatedAt * @return A modified copy of the {@code this} object */ public final ImmutableConnectionBulletinBoard withUpdatedAt(long value) { if (this.updatedAt == value) return this; return validate(new ImmutableConnectionBulletinBoard( this, this.id, this.targetResourceId, this.notices, this.warnings, this.errors, this.metadata, this.messages, this.createdAt, value)); } /** * This instance is equal to all instances of {@code ImmutableConnectionBulletinBoard} 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 ImmutableConnectionBulletinBoard && equalTo((ImmutableConnectionBulletinBoard) another); } private boolean equalTo(ImmutableConnectionBulletinBoard another) { return Objects.equals(id, another.id) && Objects.equals(targetResourceId, another.targetResourceId) && Objects.equals(notices, another.notices) && Objects.equals(warnings, another.warnings) && Objects.equals(errors, another.errors) && metadata.equals(another.metadata) && messages.equals(another.messages) && createdAt == another.createdAt && updatedAt == another.updatedAt; } /** * Computes a hash code from attributes: {@code id}, {@code targetResourceId}, {@code notices}, {@code warnings}, {@code errors}, {@code metadata}, {@code messages}, {@code createdAt}, {@code updatedAt}. * @return hashCode value */ @Override public int hashCode() { int h = 5381; h += (h << 5) + Objects.hashCode(id); h += (h << 5) + Objects.hashCode(targetResourceId); h += (h << 5) + Objects.hashCode(notices); h += (h << 5) + Objects.hashCode(warnings); h += (h << 5) + Objects.hashCode(errors); h += (h << 5) + metadata.hashCode(); h += (h << 5) + messages.hashCode(); h += (h << 5) + Long.hashCode(createdAt); h += (h << 5) + Long.hashCode(updatedAt); return h; } /** * Prints the immutable value {@code ConnectionBulletinBoard} with attribute values. * @return A string representation of the value */ @Override public String toString() { StringBuilder builder = new StringBuilder("ConnectionBulletinBoard{"); if (id != null) { builder.append("id=").append(id); } if (targetResourceId != null) { if (builder.length() > 24) builder.append(", "); builder.append("targetResourceId=").append(targetResourceId); } if (notices != null) { if (builder.length() > 24) builder.append(", "); builder.append("notices=").append(notices); } if (warnings != null) { if (builder.length() > 24) builder.append(", "); builder.append("warnings=").append(warnings); } if (errors != null) { if (builder.length() > 24) builder.append(", "); builder.append("errors=").append(errors); } if (builder.length() > 24) builder.append(", "); builder.append("metadata=").append(metadata); builder.append(", "); builder.append("messages=").append(messages); builder.append(", "); builder.append("createdAt=").append(createdAt); builder.append(", "); builder.append("updatedAt=").append(updatedAt); return builder.append("}").toString(); } /** * Construct a new immutable {@code ConnectionBulletinBoard} instance. * @param id The value for the {@code id} attribute * @param targetResourceId The value for the {@code targetResourceId} attribute * @param notices The value for the {@code notices} attribute * @param warnings The value for the {@code warnings} attribute * @param errors The value for the {@code errors} attribute * @param metadata The value for the {@code metadata} attribute * @param messages The value for the {@code messages} attribute * @param createdAt The value for the {@code createdAt} attribute * @param updatedAt The value for the {@code updatedAt} attribute * @return An immutable ConnectionBulletinBoard instance */ public static ConnectionBulletinBoard of(Optional id, String targetResourceId, OptionalInt notices, OptionalInt warnings, OptionalInt errors, Map metadata, List messages, long createdAt, long updatedAt) { return of(id, targetResourceId, notices, warnings, errors, metadata, (Iterable) messages, createdAt, updatedAt); } /** * Construct a new immutable {@code ConnectionBulletinBoard} instance. * @param id The value for the {@code id} attribute * @param targetResourceId The value for the {@code targetResourceId} attribute * @param notices The value for the {@code notices} attribute * @param warnings The value for the {@code warnings} attribute * @param errors The value for the {@code errors} attribute * @param metadata The value for the {@code metadata} attribute * @param messages The value for the {@code messages} attribute * @param createdAt The value for the {@code createdAt} attribute * @param updatedAt The value for the {@code updatedAt} attribute * @return An immutable ConnectionBulletinBoard instance */ public static ConnectionBulletinBoard of(Optional id, String targetResourceId, OptionalInt notices, OptionalInt warnings, OptionalInt errors, Map metadata, Iterable messages, long createdAt, long updatedAt) { return validate(new ImmutableConnectionBulletinBoard(id, targetResourceId, notices, warnings, errors, metadata, messages, createdAt, updatedAt)); } private static final Validator validator = Validation.buildDefaultValidatorFactory().getValidator(); private static ImmutableConnectionBulletinBoard validate(ImmutableConnectionBulletinBoard instance) { Set> constraintViolations = validator.validate(instance); if (!constraintViolations.isEmpty()) { throw new ConstraintViolationException(constraintViolations); } return instance; } /** * Creates an immutable copy of a {@link ConnectionBulletinBoard} 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 ConnectionBulletinBoard instance */ public static ConnectionBulletinBoard copyOf(ConnectionBulletinBoard instance) { if (instance instanceof ImmutableConnectionBulletinBoard) { return (ImmutableConnectionBulletinBoard) instance; } return new ConnectionBulletinBoard.Builder() .createFrom(instance) .build(); } /** * Builds instances of type {@link ConnectionBulletinBoard ConnectionBulletinBoard}. * 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 class Builder { private static final long OPT_BIT_METADATA = 0x1L; private static final long OPT_BIT_MESSAGES = 0x2L; private static final long OPT_BIT_CREATED_AT = 0x4L; private static final long OPT_BIT_UPDATED_AT = 0x8L; private long optBits; private String id; private String targetResourceId; private Integer notices; private Integer warnings; private Integer errors; private Map metadata = new LinkedHashMap(); private List messages = new ArrayList(); private long createdAt; private long updatedAt; /** * Creates a builder for {@link ConnectionBulletinBoard ConnectionBulletinBoard} instances. */ public Builder() { if (!(this instanceof ConnectionBulletinBoard.Builder)) { throw new UnsupportedOperationException("Use: new ConnectionBulletinBoard.Builder()"); } } /** * Fill a builder with attribute values from the provided {@code io.syndesis.common.model.bulletin.ConnectionBulletinBoard} instance. * @param instance The instance from which to copy values * @return {@code this} builder for use in a chained invocation */ public final ConnectionBulletinBoard.Builder createFrom(ConnectionBulletinBoard instance) { Objects.requireNonNull(instance, "instance"); from((Object) instance); return (ConnectionBulletinBoard.Builder) this; } /** * Fill a builder with attribute values from the provided {@code io.syndesis.common.model.bulletin.WithLeveledMessages} instance. * @param instance The instance from which to copy values * @return {@code this} builder for use in a chained invocation */ public final ConnectionBulletinBoard.Builder createFrom(WithLeveledMessages instance) { Objects.requireNonNull(instance, "instance"); from((Object) instance); return (ConnectionBulletinBoard.Builder) this; } /** * Fill a builder with attribute values from the provided {@code io.syndesis.common.model.WithMetadata} instance. * @param instance The instance from which to copy values * @return {@code this} builder for use in a chained invocation */ public final ConnectionBulletinBoard.Builder createFrom(WithMetadata instance) { Objects.requireNonNull(instance, "instance"); from((Object) instance); return (ConnectionBulletinBoard.Builder) this; } /** * Fill a builder with attribute values from the provided {@code io.syndesis.common.model.WithResourceId} instance. * @param instance The instance from which to copy values * @return {@code this} builder for use in a chained invocation */ public final ConnectionBulletinBoard.Builder createFrom(WithResourceId instance) { Objects.requireNonNull(instance, "instance"); from((Object) instance); return (ConnectionBulletinBoard.Builder) this; } /** * Fill a builder with attribute values from the provided {@code io.syndesis.common.model.WithModificationTimestamps} instance. * @param instance The instance from which to copy values * @return {@code this} builder for use in a chained invocation */ public final ConnectionBulletinBoard.Builder createFrom(WithModificationTimestamps instance) { Objects.requireNonNull(instance, "instance"); from((Object) instance); return (ConnectionBulletinBoard.Builder) this; } private void from(Object object) { if (object instanceof ConnectionBulletinBoard) { ConnectionBulletinBoard instance = (ConnectionBulletinBoard) object; OptionalInt noticesOptional = instance.getNotices(); if (noticesOptional.isPresent()) { notices(noticesOptional); } String targetResourceIdValue = instance.getTargetResourceId(); if (targetResourceIdValue != null) { targetResourceId(targetResourceIdValue); } OptionalInt errorsOptional = instance.getErrors(); if (errorsOptional.isPresent()) { errors(errorsOptional); } OptionalInt warningsOptional = instance.getWarnings(); if (warningsOptional.isPresent()) { warnings(warningsOptional); } } if (object instanceof WithLeveledMessages) { WithLeveledMessages instance = (WithLeveledMessages) object; addAllMessages(instance.getMessages()); } if (object instanceof WithMetadata) { WithMetadata instance = (WithMetadata) object; putAllMetadata(instance.getMetadata()); } if (object instanceof WithResourceId) { WithResourceId instance = (WithResourceId) object; Optional idOptional = instance.getId(); if (idOptional.isPresent()) { id(idOptional); } } if (object instanceof WithModificationTimestamps) { WithModificationTimestamps instance = (WithModificationTimestamps) object; createdAt(instance.getCreatedAt()); updatedAt(instance.getUpdatedAt()); } } /** * Initializes the optional value {@link ConnectionBulletinBoard#getId() id} to id. * @param id The value for id * @return {@code this} builder for chained invocation */ public final ConnectionBulletinBoard.Builder id(String id) { this.id = Objects.requireNonNull(id, "id"); return (ConnectionBulletinBoard.Builder) this; } /** * Initializes the optional value {@link ConnectionBulletinBoard#getId() id} to id. * @param id The value for id * @return {@code this} builder for use in a chained invocation */ @JsonProperty("id") public final ConnectionBulletinBoard.Builder id(Optional id) { this.id = id.orElse(null); return (ConnectionBulletinBoard.Builder) this; } /** * Initializes the value for the {@link ConnectionBulletinBoard#getTargetResourceId() targetResourceId} attribute. * @param targetResourceId The value for targetResourceId (can be {@code null}) * @return {@code this} builder for use in a chained invocation */ @JsonProperty("targetResourceId") public final ConnectionBulletinBoard.Builder targetResourceId(String targetResourceId) { this.targetResourceId = targetResourceId; return (ConnectionBulletinBoard.Builder) this; } /** * Initializes the optional value {@link ConnectionBulletinBoard#getNotices() notices} to notices. * @param notices The value for notices * @return {@code this} builder for chained invocation */ public final ConnectionBulletinBoard.Builder notices(int notices) { this.notices = notices; return (ConnectionBulletinBoard.Builder) this; } /** * Initializes the optional value {@link ConnectionBulletinBoard#getNotices() notices} to notices. * @param notices The value for notices * @return {@code this} builder for use in a chained invocation */ @JsonProperty("notices") public final ConnectionBulletinBoard.Builder notices(OptionalInt notices) { this.notices = notices.isPresent() ? notices.getAsInt() : null; return (ConnectionBulletinBoard.Builder) this; } /** * Initializes the optional value {@link ConnectionBulletinBoard#getWarnings() warnings} to warnings. * @param warnings The value for warnings * @return {@code this} builder for chained invocation */ public final ConnectionBulletinBoard.Builder warnings(int warnings) { this.warnings = warnings; return (ConnectionBulletinBoard.Builder) this; } /** * Initializes the optional value {@link ConnectionBulletinBoard#getWarnings() warnings} to warnings. * @param warnings The value for warnings * @return {@code this} builder for use in a chained invocation */ @JsonProperty("warnings") public final ConnectionBulletinBoard.Builder warnings(OptionalInt warnings) { this.warnings = warnings.isPresent() ? warnings.getAsInt() : null; return (ConnectionBulletinBoard.Builder) this; } /** * Initializes the optional value {@link ConnectionBulletinBoard#getErrors() errors} to errors. * @param errors The value for errors * @return {@code this} builder for chained invocation */ public final ConnectionBulletinBoard.Builder errors(int errors) { this.errors = errors; return (ConnectionBulletinBoard.Builder) this; } /** * Initializes the optional value {@link ConnectionBulletinBoard#getErrors() errors} to errors. * @param errors The value for errors * @return {@code this} builder for use in a chained invocation */ @JsonProperty("errors") public final ConnectionBulletinBoard.Builder errors(OptionalInt errors) { this.errors = errors.isPresent() ? errors.getAsInt() : null; return (ConnectionBulletinBoard.Builder) this; } /** * Put one entry to the {@link ConnectionBulletinBoard#getMetadata() metadata} map. * @param key The key in the metadata map * @param value The associated value in the metadata map * @return {@code this} builder for use in a chained invocation */ public final ConnectionBulletinBoard.Builder putMetadata(String key, String value) { this.metadata.put( Objects.requireNonNull(key, "metadata key"), Objects.requireNonNull(value, "metadata value")); optBits |= OPT_BIT_METADATA; return (ConnectionBulletinBoard.Builder) this; } /** * Put one entry to the {@link ConnectionBulletinBoard#getMetadata() metadata} map. Nulls are not permitted * @param entry The key and value entry * @return {@code this} builder for use in a chained invocation */ public final ConnectionBulletinBoard.Builder putMetadata(Map.Entry entry) { String k = entry.getKey(); String v = entry.getValue(); this.metadata.put( Objects.requireNonNull(k, "metadata key"), Objects.requireNonNull(v, "metadata value")); optBits |= OPT_BIT_METADATA; return (ConnectionBulletinBoard.Builder) this; } /** * Sets or replaces all mappings from the specified map as entries for the {@link ConnectionBulletinBoard#getMetadata() metadata} map. Nulls are not permitted * @param metadata The entries that will be added to the metadata map * @return {@code this} builder for use in a chained invocation */ @JsonProperty("metadata") public final ConnectionBulletinBoard.Builder metadata(Map metadata) { this.metadata.clear(); optBits |= OPT_BIT_METADATA; return putAllMetadata(metadata); } /** * Put all mappings from the specified map as entries to {@link ConnectionBulletinBoard#getMetadata() metadata} map. Nulls are not permitted * @param metadata The entries that will be added to the metadata map * @return {@code this} builder for use in a chained invocation */ public final ConnectionBulletinBoard.Builder putAllMetadata(Map metadata) { for (Map.Entry entry : metadata.entrySet()) { String k = entry.getKey(); String v = entry.getValue(); this.metadata.put( Objects.requireNonNull(k, "metadata key"), Objects.requireNonNull(v, "metadata value")); } optBits |= OPT_BIT_METADATA; return (ConnectionBulletinBoard.Builder) this; } /** * Adds one element to {@link ConnectionBulletinBoard#getMessages() messages} list. * @param element A messages element * @return {@code this} builder for use in a chained invocation */ public final ConnectionBulletinBoard.Builder addMessage(LeveledMessage element) { this.messages.add(Objects.requireNonNull(element, "messages element")); optBits |= OPT_BIT_MESSAGES; return (ConnectionBulletinBoard.Builder) this; } /** * Adds elements to {@link ConnectionBulletinBoard#getMessages() messages} list. * @param elements An array of messages elements * @return {@code this} builder for use in a chained invocation */ public final ConnectionBulletinBoard.Builder addMessage(LeveledMessage... elements) { for (LeveledMessage element : elements) { this.messages.add(Objects.requireNonNull(element, "messages element")); } optBits |= OPT_BIT_MESSAGES; return (ConnectionBulletinBoard.Builder) this; } /** * Sets or replaces all elements for {@link ConnectionBulletinBoard#getMessages() messages} list. * @param elements An iterable of messages elements * @return {@code this} builder for use in a chained invocation */ @JsonProperty("messages") public final ConnectionBulletinBoard.Builder messages(Iterable elements) { this.messages.clear(); return addAllMessages(elements); } /** * Adds elements to {@link ConnectionBulletinBoard#getMessages() messages} list. * @param elements An iterable of messages elements * @return {@code this} builder for use in a chained invocation */ public final ConnectionBulletinBoard.Builder addAllMessages(Iterable elements) { for (LeveledMessage element : elements) { this.messages.add(Objects.requireNonNull(element, "messages element")); } optBits |= OPT_BIT_MESSAGES; return (ConnectionBulletinBoard.Builder) this; } /** * Initializes the value for the {@link ConnectionBulletinBoard#getCreatedAt() createdAt} attribute. *

If not set, this attribute will have a default value as returned by the initializer of {@link ConnectionBulletinBoard#getCreatedAt() createdAt}. * @param createdAt The value for createdAt * @return {@code this} builder for use in a chained invocation */ @JsonProperty("createdAt") public final ConnectionBulletinBoard.Builder createdAt(long createdAt) { this.createdAt = createdAt; optBits |= OPT_BIT_CREATED_AT; return (ConnectionBulletinBoard.Builder) this; } /** * Initializes the value for the {@link ConnectionBulletinBoard#getUpdatedAt() updatedAt} attribute. *

If not set, this attribute will have a default value as returned by the initializer of {@link ConnectionBulletinBoard#getUpdatedAt() updatedAt}. * @param updatedAt The value for updatedAt * @return {@code this} builder for use in a chained invocation */ @JsonProperty("updatedAt") public final ConnectionBulletinBoard.Builder updatedAt(long updatedAt) { this.updatedAt = updatedAt; optBits |= OPT_BIT_UPDATED_AT; return (ConnectionBulletinBoard.Builder) this; } /** * Builds a new {@link ConnectionBulletinBoard ConnectionBulletinBoard}. * @return An immutable instance of ConnectionBulletinBoard * @throws java.lang.IllegalStateException if any required attributes are missing */ public ConnectionBulletinBoard build() { return ImmutableConnectionBulletinBoard.validate(new ImmutableConnectionBulletinBoard(this)); } private boolean metadataIsSet() { return (optBits & OPT_BIT_METADATA) != 0; } private boolean messagesIsSet() { return (optBits & OPT_BIT_MESSAGES) != 0; } private boolean createdAtIsSet() { return (optBits & OPT_BIT_CREATED_AT) != 0; } private boolean updatedAtIsSet() { return (optBits & OPT_BIT_UPDATED_AT) != 0; } } private static List createSafeList(Iterable iterable, boolean checkNulls, boolean skipNulls) { ArrayList list; if (iterable instanceof Collection) { int size = ((Collection) iterable).size(); if (size == 0) return Collections.emptyList(); list = new ArrayList(); } else { list = new ArrayList(); } for (T element : iterable) { if (skipNulls && element == null) continue; if (checkNulls) Objects.requireNonNull(element, "element"); list.add(element); } return list; } private static List createUnmodifiableList(boolean clone, List list) { switch(list.size()) { case 0: return Collections.emptyList(); case 1: return Collections.singletonList(list.get(0)); default: if (clone) { return Collections.unmodifiableList(new ArrayList(list)); } else { if (list instanceof ArrayList) { ((ArrayList) list).trimToSize(); } return Collections.unmodifiableList(list); } } } private static Map createUnmodifiableMap(boolean checkNulls, boolean skipNulls, Map map) { switch (map.size()) { case 0: return Collections.emptyMap(); case 1: { Map.Entry e = map.entrySet().iterator().next(); K k = e.getKey(); V v = e.getValue(); if (checkNulls) { Objects.requireNonNull(k, "key"); Objects.requireNonNull(v, "value"); } if (skipNulls && (k == null || v == null)) { return Collections.emptyMap(); } return Collections.singletonMap(k, v); } default: { Map linkedMap = new LinkedHashMap(map.size()); if (skipNulls || checkNulls) { for (Map.Entry e : map.entrySet()) { K k = e.getKey(); V v = e.getValue(); if (skipNulls) { if (k == null || v == null) continue; } else if (checkNulls) { Objects.requireNonNull(k, "key"); Objects.requireNonNull(v, "value"); } linkedMap.put(k, v); } } else { linkedMap.putAll(map); } return Collections.unmodifiableMap(linkedMap); } } } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy