1 /*
2 * Copyright (c) 1998-2002 The Jgroup Team.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License version 2 as
6 * published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU Lesser General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
16 *
17 */
18
19 package jgroup.test.performance.upgrade;
20
21
22
23 /**
24 * This class supports command line parameter parsing. In the future,
25 * it should be replaced by a more powerful standard framework for
26 * command line parameter parsing.
27 *
28 * @author Marcin Solarski
29 * @since Jgroup 2.1
30 */
31
32 class PUtil {
33
34 /**
35 * method parses the string array with tokenized parameters.
36 * @param argv the string array with parameters
37 * @param name the parameter name
38 * @param defValue the default value of the parameter
39 * @return value of the parameter following one with a given name
40 * or its default value. If the default value is not convertable to
41 * int the method returns 0.
42 */
43 static int getIntParameter(String argv[], String name, String defValue) {
44 int dv = 0;
45 try {
46 dv = Integer.parseInt(defValue);
47 for(int i=0; i<argv.length; i++){
48 if( argv[i] != null && argv[i] != null && argv[i].compareTo(name) == 0) {
49 String val = "1";
50 if( i+1<argv.length ) val = argv[i+1];
51 try{ return Integer.parseInt(val); }
52 catch(NumberFormatException e) { return dv;}
53 }
54 }
55 } catch(NumberFormatException e) { return 0;}
56 return dv;
57 }
58
59
60 /**
61 * method parses the string array with tokenized parameters.
62 * @param argv the string array with parameters
63 * @param name the parameter name
64 * @param defValue the default value of the parameter
65 * @return string value of the parameter following one with a given name
66 * or its default value if the name is not given in the command line.
67 */
68 static String getStringParameter(String argv[], String name, String defValue) {
69 String val = null;
70 for(int i=0; i<argv.length; i++){
71 if( argv[i] != null && argv[i] != null && argv[i].compareTo(name) == 0) {
72 if( i+1<argv.length ) val = argv[i+1]; else val = defValue;
73 return val;
74 }
75 }
76 return defValue;
77 }
78
79 /**
80 * parses a switch kind of command line parameter
81 * @param name the switch name
82 * @return true if the switch is found in the command line
83 */
84 static boolean getSwitch(String argv[], String name) {
85 for(int i=0; i<argv.length; i++)
86 if( argv[i] != null && argv[i].compareTo(name) == 0)
87 return true;
88 return false;
89 }
90 }