2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3 * Copyright (C) $$Year-Rel$$ The Jalview Authors
5 * This file is part of Jalview.
7 * Jalview is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation, either version 3
10 * of the License, or (at your option) any later version.
12 * Jalview is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty
14 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19 * The Jalview Authors are detailed in the 'AUTHORS' file.
21 package jalview.structure;
23 import java.util.ArrayList;
24 import java.util.List;
26 public class StructureCommand implements StructureCommandI
28 private String command;
30 private List<String> parameters;
32 private boolean waitNeeded=false;
33 public StructureCommand(String cmd, String... params)
38 for (String p : params)
45 public void setWaitNeeded(boolean wait)
51 public boolean isWaitNeeded()
57 public void addParameter(String param)
59 if (parameters == null)
61 parameters = new ArrayList<>();
63 parameters.add(param);
67 public String getCommand()
73 public List<String> getParameters()
79 public boolean hasParameters()
81 return parameters != null && !parameters.isEmpty();
85 public String toString()
91 StringBuilder sb = new StringBuilder(32);
92 sb.append(command).append("(");
94 for (String p : parameters)
104 return sb.toString();
108 public int hashCode()
110 int h = command.hashCode();
111 if (parameters != null)
113 for (String p : parameters)
115 h = h * 37 + p.hashCode();
122 * Answers true if {@code obj} is a {@code StructureCommand} with the same
123 * command and parameters as this one, else false
126 public boolean equals(Object obj)
128 if (obj == null || !(obj instanceof StructureCommand))
132 StructureCommand sc = (StructureCommand) obj;
134 if (!command.equals(sc.command))
138 if (parameters == null || sc.parameters == null)
140 return (parameters == null) && (sc.parameters == null);
143 int j = parameters.size();
144 if (j != sc.parameters.size())
148 for (int i = 0; i < j; i++)
150 if (!parameters.get(i).equals(sc.parameters.get(i)))