package jalview.ws2.actions; import java.util.EnumSet; import java.util.Objects; import jalview.ws2.actions.api.ActionI; import jalview.ws2.api.CredentialType; import jalview.ws2.api.WebService; /** * An abstract base class storing common data and implementing their getters * defined in {@link ActionI} interface. The concrete action implementations are * encouraged to extend this class and provide their own {@code perform} and * {@code isActive} implementations. * * @author mmwarowny * @param * task result type */ public abstract class BaseAction implements ActionI { public static abstract class Builder> { protected WebService webService; protected String name = null; protected String tooltip = ""; protected String subcategory = null; protected int minSequences = -1; protected int maxSequences = -1; protected boolean allowProtein = true; protected boolean allowNucleotide = true; protected EnumSet requiredCredentials = EnumSet.noneOf(CredentialType.class); public Builder() { } public void name(String val) { this.name = val; } public void webService(WebService val) { this.webService = val; } public void tooltip(String val) { tooltip = val; } public void subcategory(String val) { subcategory = val; } public void minSequences(int val) { minSequences = val; } public void maxSequecnes(int val) { maxSequences = val; } public void allowProtein(boolean val) { allowProtein = val; } public void allowNucleotide(boolean val) { allowNucleotide = val; } public void addRequiredCredential(CredentialType val) { requiredCredentials.add(val); } public void requiredCredentials(EnumSet val) { requiredCredentials = val; } } protected final WebService> webService; protected final String name; protected final String tooltip; protected final String subcategory; protected final int minSequences; protected final int maxSequences; protected final boolean allowProtein; protected final boolean allowNucleotide; protected final EnumSet requiredCredentials; protected BaseAction(Builder> builder) { Objects.requireNonNull(builder.webService); this.webService = builder.webService; this.name = builder.name; this.tooltip = builder.tooltip; this.subcategory = builder.subcategory; this.minSequences = builder.minSequences; this.maxSequences = builder.maxSequences; this.allowProtein = builder.allowProtein; this.allowNucleotide = builder.allowNucleotide; this.requiredCredentials = builder.requiredCredentials; } @Override public WebService> getWebService() { return webService; } @Override public String getName() { return name; } /** * Returns a full name of the action which comprises of the service name and * the action name if present. * * @return full name of this action */ public String getFullName() { if (name == null || name.isEmpty()) return webService.getName(); else return webService.getName() + " " + name; } @Override public String getTooltip() { return tooltip; } @Override public String getSubcategory() { return subcategory; } @Override public int getMinSequences() { return minSequences; } @Override public int getMaxSequences() { return maxSequences; } @Override public boolean doAllowProtein() { return allowProtein; } @Override public boolean doAllowNucleotide() { return allowNucleotide; } @Override public EnumSet getRequiredCredentials() { return requiredCredentials; } }