EMMA Coverage Report (generated Tue May 16 15:34:38 CDT 2006)
[all classes][com.mysql.management.util]

COVERAGE SUMMARY FOR SOURCE FILE [CommandLineOptionsParser.java]

nameclass, %method, %block, %line, %
CommandLineOptionsParser.java100% (1/1)90%  (9/10)96%  (119/124)96%  (27/28)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class CommandLineOptionsParser100% (1/1)90%  (9/10)96%  (119/124)96%  (27/28)
remove (String): Object 0%   (0/1)0%   (0/5)0%   (0/1)
CommandLineOptionsParser (List): void 100% (1/1)100% (71/71)100% (16/16)
CommandLineOptionsParser (String []): void 100% (1/1)100% (5/5)100% (2/2)
asMap (): Map 100% (1/1)100% (3/3)100% (1/1)
containsKey (String): boolean 100% (1/1)100% (5/5)100% (1/1)
getBaseDir (): File 100% (1/1)100% (4/4)100% (1/1)
getDataDir (): File 100% (1/1)100% (4/4)100% (1/1)
getVersion (): String 100% (1/1)100% (6/6)100% (1/1)
isShutdown (): boolean 100% (1/1)100% (4/4)100% (1/1)
newFile (String): File 100% (1/1)100% (17/17)100% (3/3)

1/*
2 Copyright (C) 2004 MySQL AB
3 
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU 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 General Public License for more details.
12 
13 You should have received a copy of the GNU General Public License
14 along with this program; if not, write to the Free Software
15 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16 
17 */
18package com.mysql.management.util;
19 
20import java.io.File;
21import java.util.Arrays;
22import java.util.HashMap;
23import java.util.List;
24import java.util.Map;
25 
26import com.mysql.management.MysqldResourceI;
27 
28/**
29 * This class is final simply as a hint to the compiler, it may be un-finalized
30 * safely.
31 * 
32 * @author Eric Herman <eric@mysql.com>
33 * @version $Id: CommandLineOptionsParser.java,v 1.1 2005/02/17 21:20:45 eherman
34 *          Exp $
35 */
36public final class CommandLineOptionsParser {
37 
38    private Map params;
39 
40    private Files fileUtil;
41 
42    public CommandLineOptionsParser(String[] args) {
43        this(Arrays.asList(args));
44    }
45 
46    public CommandLineOptionsParser(List args) {
47        this.params = new HashMap();
48        this.fileUtil = new Files();
49 
50        for (int i = 0; i < args.size(); i++) {
51            String arg = (String) args.get(i);
52            if (arg.startsWith("--")) {
53                arg = arg.substring(2);
54            }
55            int equalsPos = arg.indexOf("=");
56            if (equalsPos == -1) {
57                equalsPos = arg.length();
58            }
59            String key = arg.substring(0, equalsPos).trim();
60            String value = null;
61            if (arg.length() > equalsPos) {
62                value = arg.substring(equalsPos + 1, arg.length()).trim();
63            }
64 
65            params.put(key, value);
66        }
67    }
68 
69    public boolean containsKey(String key) {
70        return asMap().containsKey(key);
71    }
72 
73    public Object remove(String key) {
74        return asMap().remove(key);
75    }
76 
77    public Map asMap() {
78        return params;
79    }
80 
81    public File getBaseDir() {
82        return newFile(MysqldResourceI.BASEDIR);
83    }
84 
85    public File getDataDir() {
86        return newFile(MysqldResourceI.DATADIR);
87    }
88 
89    private File newFile(String key) {
90        if (!params.containsKey(key))
91            return fileUtil.nullFile();
92        return fileUtil.newFile(params.get(key));
93    }
94 
95    public String getVersion() {
96        return (String) params.get(MysqldResourceI.MYSQLD_VERSION);
97    }
98 
99    public boolean isShutdown() {
100        return containsKey("shutdown");
101    }
102}

[all classes][com.mysql.management.util]
EMMA 2.0.5312 (C) Vladimir Roubtsov