Clover icon

Coverage Report

  1. Project Clover database Fri Nov 1 2024 11:46:37 GMT
  2. Package jalview.structure

File StructureCommand.java

 

Coverage histogram

../../img/srcFileCovDistChart8.png
20% 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.7272%
 

Contributing tests

This file is covered by 95 tests. .

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  2032 toggle public StructureCommand(String cmd, String... params)
35    {
36  2032 command = cmd;
37  2032 if (params != null)
38    {
39  2032 for (String p : params)
40    {
41  95 addParameter(p);
42    }
43    }
44    }
45   
 
46  3 toggle public void setWaitNeeded(boolean wait)
47    {
48  3 waitNeeded = wait;
49    }
50   
 
51  212 toggle @Override
52    public boolean isWaitNeeded()
53    {
54  212 return waitNeeded;
55    }
56   
 
57  95 toggle @Override
58    public void addParameter(String param)
59    {
60  95 if (parameters == null)
61    {
62  53 parameters = new ArrayList<>();
63    }
64  95 parameters.add(param);
65    }
66   
 
67  1920 toggle @Override
68    public String getCommand()
69    {
70  1920 return command;
71    }
72   
 
73  1 toggle @Override
74    public List<String> getParameters()
75    {
76  1 return parameters;
77    }
78   
 
79  2 toggle @Override
80    public boolean hasParameters()
81    {
82  2 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  2 toggle @Override
109    public int hashCode()
110    {
111  2 int h = command.hashCode();
112  2 if (parameters != null)
113    {
114  2 for (String p : parameters)
115    {
116  4 h = h * 37 + p.hashCode();
117    }
118    }
119  2 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  89 toggle @Override
127    public boolean equals(Object obj)
128    {
129  89 if (obj == null || !(obj instanceof StructureCommand))
130    {
131  2 return false;
132    }
133  87 StructureCommand sc = (StructureCommand) obj;
134   
135  87 if (!command.equals(sc.command))
136    {
137  3 return false;
138    }
139  84 if (parameters == null || sc.parameters == null)
140    {
141  34 return (parameters == null) && (sc.parameters == null);
142    }
143   
144  50 int j = parameters.size();
145  50 if (j != sc.parameters.size())
146    {
147  0 return false;
148    }
149  138 for (int i = 0; i < j; i++)
150    {
151  89 if (!parameters.get(i).equals(sc.parameters.get(i)))
152    {
153  1 return false;
154    }
155    }
156  49 return true;
157    }
158   
159    }