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.
23 import java.net.URLDecoder;
24 import java.util.Vector;
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 '-'
32 * @author Andrew Waterhouse and JBP documented.
35 public class ArgsParser
37 Vector<String> vargs = null;
39 public ArgsParser(String[] args)
41 vargs = new Vector<String>();
42 for (int i = 0; i < args.length; i++)
44 String arg = args[i].trim();
45 if (arg.charAt(0) == '-')
47 arg = arg.substring(1);
49 vargs.addElement(arg);
54 * check for and remove first occurence of arg+parameter in arglist.
57 * @return return the argument following the given arg if arg was in list.
59 public String getValue(String arg)
61 return getValue(arg, false);
64 public String getValue(String arg, boolean utf8decode)
66 int index = vargs.indexOf(arg);
67 String dc = null, ret = null;
70 ret = vargs.elementAt(index + 1).toString();
71 vargs.removeElementAt(index);
72 vargs.removeElementAt(index);
73 if (utf8decode && ret != null)
77 dc = URLDecoder.decode(ret, "UTF-8");
81 // TODO: log failure to decode
89 * check for and remove first occurence of arg in arglist.
92 * @return true if arg was present in argslist.
94 public boolean contains(String arg)
96 if (vargs.contains(arg))
98 vargs.removeElement(arg);
107 public String nextValue()
109 return vargs.remove(0);