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

io.sphere.sdk.models.AssetDraftBuilderBase Maven / Gradle / Ivy

The newest version!
package io.sphere.sdk.models;

import io.sphere.sdk.types.CustomFields;
import io.sphere.sdk.types.CustomFieldsDraft;
import io.sphere.sdk.types.CustomFieldsDraftBuilder;
import io.sphere.sdk.utils.SphereInternalUtils;
import java.lang.String;
import java.lang.SuppressWarnings;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Optional;
import java.util.Set;
import javax.annotation.Generated;
import javax.annotation.Nullable;

/**
 * Abstract base builder for {@link AssetDraft} which needs to be extended to add additional methods.
 * Subclasses have to provide the same non-default constructor as this class.
 */
@Generated(
    value = "io.sphere.sdk.annotations.processors.generators.DraftBuilderGenerator",
    comments = "Generated from: io.sphere.sdk.models.AssetDraft"
)
abstract class AssetDraftBuilderBase extends Base implements Builder {
  @Nullable
  CustomFieldsDraft custom;

  @Nullable
  LocalizedString description;

  String key;

  LocalizedString name;

  List sources;

  @Nullable
  Set tags;

  protected AssetDraftBuilderBase() {
  }

  protected AssetDraftBuilderBase(@Nullable final CustomFieldsDraft custom,
      @Nullable final LocalizedString description, final String key, final LocalizedString name,
      final List sources, @Nullable final Set tags) {
    this.custom = custom;
    this.description = description;
    this.key = key;
    this.name = name;
    this.sources = sources;
    this.tags = tags;
  }

  /**
   * Sets the {@code custom} property of this builder.
   *
   * @param custom the value for {@link AssetDraft#getCustom()}
   * @return this builder
   */
  @SuppressWarnings("unchecked")
  public T custom(@Nullable final CustomFieldsDraft custom) {
    this.custom = custom;
    return (T) this;
  }

  /**
   * Sets the {@code description} property of this builder.
   *
   * @param description the value for {@link AssetDraft#getDescription()}
   * @return this builder
   */
  @SuppressWarnings("unchecked")
  public T description(@Nullable final LocalizedString description) {
    this.description = description;
    return (T) this;
  }

  /**
   * Sets the {@code key} property of this builder.
   *
   * @param key the value for {@link AssetDraft#getKey()}
   * @return this builder
   */
  @SuppressWarnings("unchecked")
  public T key(final String key) {
    this.key = key;
    return (T) this;
  }

  /**
   * Sets the {@code name} property of this builder.
   *
   * @param name the value for {@link AssetDraft#getName()}
   * @return this builder
   */
  @SuppressWarnings("unchecked")
  public T name(final LocalizedString name) {
    this.name = name;
    return (T) this;
  }

  /**
   * Sets the {@code sources} property of this builder.
   *
   * @param sources the value for {@link AssetDraft#getSources()}
   * @return this builder
   */
  @SuppressWarnings("unchecked")
  public T sources(final List sources) {
    this.sources = sources;
    return (T) this;
  }

  /**
   * Sets the {@code tags} property of this builder.
   *
   * @param tags the value for {@link AssetDraft#getTags()}
   * @return this builder
   */
  @SuppressWarnings("unchecked")
  public T tags(@Nullable final Set tags) {
    this.tags = tags;
    return (T) this;
  }

  @Nullable
  public CustomFieldsDraft getCustom() {
    return custom;
  }

  @Nullable
  public LocalizedString getDescription() {
    return description;
  }

  public String getKey() {
    return key;
  }

  public LocalizedString getName() {
    return name;
  }

  public List getSources() {
    return sources;
  }

  @Nullable
  public Set getTags() {
    return tags;
  }

  /**
   * Concatenate {@code sources} parameter to the {@code sources} list property of this builder.
   *
   * @param sources the value for {@link AssetDraft#getSources()}
   * @return this builder
   */
  @SuppressWarnings("unchecked")
  public T plusSources(final List sources) {
    this.sources =  SphereInternalUtils.listOf(Optional.ofNullable(this.sources).orElseGet(ArrayList::new), sources);
    return (T) this;
  }

  /**
   * Adds {@code sources} parameter to the {@code sources} list property of this builder.
   *
   * @param sources the value of the element to add to {@link AssetDraft#getSources()}
   * @return this builder
   */
  @SuppressWarnings("unchecked")
  public T plusSources(final AssetSource sources) {
    this.sources =  SphereInternalUtils.listOf(Optional.ofNullable(this.sources).orElseGet(ArrayList::new), Collections.singletonList(sources));
    return (T) this;
  }

  /**
   * Concatenate {@code tags} parameter to the {@code tags} set property of this builder.
   *
   * @param tags the value for {@link AssetDraft#getTags()}
   * @return this builder
   */
  @SuppressWarnings("unchecked")
  public T plusTags(final Set tags) {
    this.tags =  SphereInternalUtils.setOf(Optional.ofNullable(this.tags).orElseGet(HashSet::new), tags);
    return (T) this;
  }

  /**
   * Adds {@code tags} parameter to the {@code tags} set property of this builder.
   *
   * @param tags the value of the element to add to {@link AssetDraft#getTags()}
   * @return this builder
   */
  @SuppressWarnings("unchecked")
  public T plusTags(final String tags) {
    this.tags =  SphereInternalUtils.setOf(Collections.singleton(tags), Optional.ofNullable(this.tags).orElseGet(HashSet::new));
    return (T) this;
  }

  /**
   * Creates a new instance of {@code AssetDraftDsl} with the values of this builder.
   *
   * @return the instance
   */
  public AssetDraftDsl build() {
    return new AssetDraftDsl(custom, description, key, name, sources, tags);
  }

  /**
   * Creates a new object initialized with the given values.
   *
   * @param sources initial value for the {@link AssetDraft#getSources()} property
   * @param name initial value for the {@link AssetDraft#getName()} property
   * @return new object initialized with the given values
   */
  public static AssetDraftBuilder of(final List sources, final LocalizedString name) {
    return new AssetDraftBuilder(null, null, null, name, sources, null);
  }

  /**
   * Creates a new object initialized with the fields of the template parameter.
   *
   * @param template the template
   * @return a new object initialized from the template
   */
  public static AssetDraftBuilder of(final AssetDraft template) {
    return new AssetDraftBuilder(template.getCustom(), template.getDescription(), template.getKey(), template.getName(), template.getSources(), template.getTags());
  }

  private static CustomFieldsDraft copyCustom(final CustomFields template) {
    return template == null ? null : CustomFieldsDraftBuilder.of(template).build();
  }

  /**
   * Creates a new object initialized with the fields of the template parameter.
   *
   * @param template the template
   * @return a new object initialized from the template
   */
  public static AssetDraftBuilder of(final Asset template) {
    return new AssetDraftBuilder(copyCustom(template.getCustom()), template.getDescription(), template.getKey(), template.getName(), template.getSources(), template.getTags());
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy