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 public StructureCommand(String cmd, String... params)
37 for (String p : params)
45 public void addParameter(String param)
47 if (parameters == null)
49 parameters = new ArrayList<>();
51 parameters.add(param);
55 public String getCommand()
61 public List<String> getParameters()
67 public boolean hasParameters()
69 return parameters != null && !parameters.isEmpty();
73 public String toString()
79 StringBuilder sb = new StringBuilder(32);
80 sb.append(command).append("(");
82 for (String p : parameters)
98 int h = command.hashCode();
99 if (parameters != null)
101 for (String p : parameters)
103 h = h * 37 + p.hashCode();
110 * Answers true if {@code obj} is a {@code StructureCommand} with the same
111 * command and parameters as this one, else false
114 public boolean equals(Object obj)
116 if (obj == null || !(obj instanceof StructureCommand))
120 StructureCommand sc = (StructureCommand) obj;
122 if (!command.equals(sc.command))
126 if (parameters == null || sc.parameters == null)
128 return (parameters == null) && (sc.parameters == null);
131 int j = parameters.size();
132 if (j != sc.parameters.size())
136 for (int i = 0; i < j; i++)
138 if (!parameters.get(i).equals(sc.parameters.get(i)))