CmdArgs.java
919 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package io.mycat.util.cmd;
import java.util.HashMap;
import java.util.Map;
/**
* -host=192.168.1.1:8080
* -
* @author me
*
*/
public class CmdArgs {
private static final CmdArgs cmdArgs=new CmdArgs();
private Map<String,String> args;
private CmdArgs(){
args=new HashMap<>();
}
public static CmdArgs getInstance(String[] args){
Map<String,String> cmdArgs=CmdArgs.cmdArgs.args;
for(int i=0,l=args.length;i<l;i++){
String arg=args[i].trim();
int split=arg.indexOf('=');
cmdArgs.put(arg.substring(1,split), arg.substring(split+1));
}
return CmdArgs.cmdArgs;
}
public String getString(String name){
return args.get(name);
}
public int getInt(String name){
return Integer.parseInt(getString(name));
}
public long getLong(String name){
return Long.parseLong(getString(name));
}
public boolean getBoolean(String name){
return Boolean.parseBoolean(getString(name));
}
}