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;
34 public StructureCommand(String cmd, String... params)
39 for (String p : params)
46 public void setWaitNeeded(boolean wait)
52 public boolean isWaitNeeded()
58 public void addParameter(String param)
60 if (parameters == null)
62 parameters = new ArrayList<>();
64 parameters.add(param);
68 public String getCommand()
74 public List<String> getParameters()
80 public boolean hasParameters()
82 return parameters != null && !parameters.isEmpty();
86 public String toString()
92 StringBuilder sb = new StringBuilder(32);
93 sb.append(command).append("(");
95 for (String p : parameters)
105 return sb.toString();
109 public int hashCode()
111 int h = command.hashCode();
112 if (parameters != null)
114 for (String p : parameters)
116 h = h * 37 + p.hashCode();
123 * Answers true if {@code obj} is a {@code StructureCommand} with the same
124 * command and parameters as this one, else false
127 public boolean equals(Object obj)
129 if (obj == null || !(obj instanceof StructureCommand))
133 StructureCommand sc = (StructureCommand) obj;
135 if (!command.equals(sc.command))
139 if (parameters == null || sc.parameters == null)
141 return (parameters == null) && (sc.parameters == null);
144 int j = parameters.size();
145 if (j != sc.parameters.size())
149 for (int i = 0; i < j; i++)
151 if (!parameters.get(i).equals(sc.parameters.get(i)))