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

com.almworks.jira.structure.api.folder.Folder Maven / Gradle / Ivy

There is a newer version: 17.25.3
Show newest version
package com.almworks.jira.structure.api.folder;

import com.almworks.jira.structure.api.util.Limits;
import com.almworks.jira.structure.api.util.StructureUtil;
import com.atlassian.annotations.PublicApi;
import org.apache.commons.lang.StringUtils;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

@PublicApi
public final class Folder {
  @NotNull
  private final String myName;

  @Nullable
  private final Long myOwningStructure;

  private Folder(@NotNull String name, @Nullable Long owningStructure) {
    myName = StructureUtil.nonBlank(name);
    myOwningStructure = owningStructure;
  }

  @NotNull
  public String getName() {
    return myName;
  }

  @Nullable
  public Long getOwningStructure() {
    return myOwningStructure;
  }

  @NotNull
  public static Builder named(@NotNull String name) {
    return new Builder(name);
  }

  @NotNull
  public static Builder copy(@NotNull Folder folder) {
    return new Builder(folder.getName()).setOwningStructure(folder.getOwningStructure());
  }


  @PublicApi
  public static final class Builder {
    @NotNull
    private String myName;

    @Nullable
    private Long myOwningStructure;

    private Builder(@NotNull String name) {
      myName = checkName(name);
    }

    @NotNull
    public Builder setName(@NotNull String name) {
      myName = checkName(name);
      return this;
    }

    private String checkName(String name) {
      if (StringUtils.isBlank(name)) {
        throw new IllegalArgumentException("Folder name must not be blank.");
      }
      return StringUtils.abbreviate(name, Limits.MAX_NAME_LENGTH);
    }

    @NotNull
    public Builder setOwningStructure(@Nullable Long owningStructure) {
      myOwningStructure = owningStructure;
      return this;
    }

    @NotNull
    public Folder build() {
      return new Folder(myName, myOwningStructure);
    }
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy