Clover icon

Coverage Report

  1. Project Clover database Thu Nov 7 2024 17:01:39 GMT
  2. Package jalview.structure

File StructureCommand.java

 

Coverage histogram

../../img/srcFileCovDistChart0.png
0% of files have more coverage

Code metrics

22
43
10
1
159
118
23
0.53
4.3
10
2.3

Classes

Class Line # Actions
StructureCommand 26 43 23
0.00%
 

Contributing tests

No tests hitting this source file were found.

Source view

1    /*
2    * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3    * Copyright (C) $$Year-Rel$$ The Jalview Authors
4    *
5    * This file is part of Jalview.
6    *
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.
11    *
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.
16    *
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.
20    */
21    package jalview.structure;
22   
23    import java.util.ArrayList;
24    import java.util.List;
25   
 
26    public class StructureCommand implements StructureCommandI
27    {
28    private String command;
29   
30    private List<String> parameters;
31   
32    private boolean waitNeeded = false;
33   
 
34  0 toggle public StructureCommand(String cmd, String... params)
35    {
36  0 command = cmd;
37  0 if (params != null)
38    {
39  0 for (String p : params)
40    {
41  0 addParameter(p);
42    }
43    }
44    }
45   
 
46  0 toggle public void setWaitNeeded(boolean wait)
47    {
48  0 waitNeeded = wait;
49    }
50   
 
51  0 toggle @Override
52    public boolean isWaitNeeded()
53    {
54  0 return waitNeeded;
55    }
56   
 
57  0 toggle @Override
58    public void addParameter(String param)
59    {
60  0 if (parameters == null)
61    {
62  0 parameters = new ArrayList<>();
63    }
64  0 parameters.add(param);
65    }
66   
 
67  0 toggle @Override
68    public String getCommand()
69    {
70  0 return command;
71    }
72   
 
73  0 toggle @Override
74    public List<String> getParameters()
75    {
76  0 return parameters;
77    }
78   
 
79  0 toggle @Override
80    public boolean hasParameters()
81    {
82  0 return parameters != null && !parameters.isEmpty();
83    }
84   
 
85  0 toggle @Override
86    public String toString()
87    {
88  0 if (!hasParameters())
89    {
90  0 return command;
91    }
92  0 StringBuilder sb = new StringBuilder(32);
93  0 sb.append(command).append("(");
94  0 boolean first = true;
95  0 for (String p : parameters)
96    {
97  0 if (!first)
98    {
99  0 sb.append(",");
100    }
101  0 first = false;
102  0 sb.append(p);
103    }
104  0 sb.append(")");
105  0 return sb.toString();
106    }
107   
 
108  0 toggle @Override
109    public int hashCode()
110    {
111  0 int h = command.hashCode();
112  0 if (parameters != null)
113    {
114  0 for (String p : parameters)
115    {
116  0 h = h * 37 + p.hashCode();
117    }
118    }
119  0 return h;
120    }
121   
122    /**
123    * Answers true if {@code obj} is a {@code StructureCommand} with the same
124    * command and parameters as this one, else false
125    */
 
126  0 toggle @Override
127    public boolean equals(Object obj)
128    {
129  0 if (obj == null || !(obj instanceof StructureCommand))
130    {
131  0 return false;
132    }
133  0 StructureCommand sc = (StructureCommand) obj;
134   
135  0 if (!command.equals(sc.command))
136    {
137  0 return false;
138    }
139  0 if (parameters == null || sc.parameters == null)
140    {
141  0 return (parameters == null) && (sc.parameters == null);
142    }
143   
144  0 int j = parameters.size();
145  0 if (j != sc.parameters.size())
146    {
147  0 return false;
148    }
149  0 for (int i = 0; i < j; i++)
150    {
151  0 if (!parameters.get(i).equals(sc.parameters.get(i)))
152    {
153  0 return false;
154    }
155    }
156  0 return true;
157    }
158   
159    }