Clover icon

Coverage Report

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

File ArgsParser.java

 

Coverage histogram

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

Code metrics

10
24
6
1
117
66
14
0.58
4
6
2.33

Classes

Class Line # Actions
ArgsParser 35 24 14
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.bin;
22   
23    import java.net.URLDecoder;
24    import java.util.Vector;
25   
26    /**
27    * Notes: this argParser does not distinguish between parameter switches,
28    * parameter values and argument text. If an argument happens to be identical to
29    * a parameter, it will be taken as such (even though it didn't have a '-'
30    * prefixing it).
31    *
32    * @author Andrew Waterhouse and JBP documented.
33    *
34    */
 
35    public class ArgsParser
36    {
37    Vector<String> vargs = null;
38   
 
39  0 toggle public ArgsParser(String[] args)
40    {
41  0 vargs = new Vector<String>();
42  0 for (int i = 0; i < args.length; i++)
43    {
44  0 String arg = args[i].trim();
45  0 if (arg.length() > 0 && arg.charAt(0) == '-')
46    {
47  0 arg = arg.substring(1);
48    }
49  0 vargs.addElement(arg);
50    }
51    }
52   
53    /**
54    * check for and remove first occurence of arg+parameter in arglist.
55    *
56    * @param arg
57    * @return return the argument following the given arg if arg was in list.
58    */
 
59  0 toggle public String getValue(String arg)
60    {
61  0 return getValue(arg, false);
62    }
63   
 
64  0 toggle public String getValue(String arg, boolean utf8decode)
65    {
66  0 int index = vargs.indexOf(arg);
67  0 String dc = null, ret = null;
68  0 if (index != -1)
69    {
70  0 ret = vargs.elementAt(index + 1).toString();
71  0 vargs.removeElementAt(index);
72  0 vargs.removeElementAt(index);
73  0 if (utf8decode && ret != null)
74    {
75  0 try
76    {
77  0 dc = URLDecoder.decode(ret, "UTF-8");
78  0 ret = dc;
79    } catch (Exception e)
80    {
81    // TODO: log failure to decode
82    }
83    }
84    }
85  0 return ret;
86    }
87   
88    /**
89    * check for and remove first occurence of arg in arglist.
90    *
91    * @param arg
92    * @return true if arg was present in argslist.
93    */
 
94  0 toggle public boolean contains(String arg)
95    {
96  0 if (vargs.contains(arg))
97    {
98  0 vargs.removeElement(arg);
99  0 return true;
100    }
101    else
102    {
103  0 return false;
104    }
105    }
106   
 
107  0 toggle public String nextValue()
108    {
109  0 return vargs.remove(0);
110    }
111   
 
112  0 toggle public int getSize()
113    {
114  0 return vargs.size();
115    }
116   
117    }