From: Mateusz Warowny Date: Fri, 18 Feb 2022 14:42:41 +0000 (+0100) Subject: JAL-3878 Create abstract base class for actions. X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=98bab37888bc2f761fa339b131e852237ed299a3;p=jalview.git JAL-3878 Create abstract base class for actions. --- diff --git a/src/jalview/ws2/actions/BaseAction.java b/src/jalview/ws2/actions/BaseAction.java new file mode 100644 index 0000000..37fbe39 --- /dev/null +++ b/src/jalview/ws2/actions/BaseAction.java @@ -0,0 +1,165 @@ +package jalview.ws2.actions; + +import java.util.EnumSet; + +import jalview.ws2.actions.api.ActionI; +import jalview.ws2.api.CredentialType; + +/** + * 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 class Builder + { + protected String name; + + 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(String name) + { + this.name = name; + } + + 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 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) + { + 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; + } + + public static Builder newBuilder(String name) + { + return new Builder(name); + } + + @Override + public String getName() + { + return 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; + } +}