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

COVERAGE SUMMARY FOR SOURCE FILE [ListToString.java]

nameclass, %method, %block, %line, %
ListToString.java100% (1/1)100% (6/6)85%  (108/127)84%  (27/32)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class ListToString100% (1/1)100% (6/6)85%  (108/127)84%  (27/32)
toString (Map): String 100% (1/1)70%  (7/10)67%  (2/3)
toString (Object []): String 100% (1/1)70%  (7/10)67%  (2/3)
toString (Object): String 100% (1/1)79%  (38/48)80%  (8/10)
toString (Collection): String 100% (1/1)93%  (38/41)89%  (8/9)
ListToString (): void 100% (1/1)100% (6/6)100% (2/2)
ListToString (String, String, String): void 100% (1/1)100% (12/12)100% (5/5)

1package com.mysql.management.util;
2 
3import java.util.Arrays;
4import java.util.Collection;
5import java.util.Iterator;
6import java.util.Map;
7 
8/*
9 Copyright (C) 2004 MySQL AB
10 
11 This program is free software; you can redistribute it and/or modify
12 it under the terms of the GNU General Public License version 2 as 
13 published by the Free Software Foundation.
14 
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18 GNU General Public License for more details.
19 
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
23 
24 */
25 
26/**
27 * This class is final simply as a hint to the compiler, it may be un-finalized
28 * safely.
29 * 
30 * @author Eric Herman <eric@mysql.com>
31 * @version $Id: Str.java,v 1.11 2005/08/31 01:21:16 eherman Exp $
32 */
33public final class ListToString {
34    private String prefix;
35 
36    private String separator;
37 
38    private String postfix;
39 
40    public ListToString() {
41        this("[", "][", "]");
42    }
43 
44    public ListToString(String prefix, String separator, String postfix) {
45        this.prefix = prefix;
46        this.separator = separator;
47        this.postfix = postfix;
48    }
49 
50    /**
51     * returns the contentents of the collection as a string a collections with
52     * "a", "b", null, and new Integer(1) would return: {[a][b][null][1]}
53     */
54    public String toString(Object[] objs) {
55        if (objs == null) {
56            return String.valueOf(null);
57        }
58        return toString(Arrays.asList(objs));
59    }
60 
61    public String toString(Map map) {
62        if (map == null) {
63            return String.valueOf(null);
64        }
65        return toString(map.entrySet());
66    }
67 
68    /**
69     * returns the contentents of the collection as a string a collections with
70     * "a", "b", null, and new Integer(1) would return: {[a][b][null][1]}
71     * 
72     * @param objs
73     *            collection
74     * @param prefix
75     * @param separator
76     * @param postfix
77     * @return the contentents of the collection as a string
78     */
79    public String toString(Collection objs) {
80        if (objs == null) {
81            return String.valueOf(objs);
82        }
83        StringBuffer buf = new StringBuffer(prefix);
84        for (Iterator iter = objs.iterator(); iter.hasNext();) {
85            buf.append(toString(iter.next()));
86            if (iter.hasNext()) {
87                buf.append(separator);
88            }
89        }
90        buf.append(postfix);
91        return buf.toString();
92    }
93 
94    public String toString(Object obj) {
95        if (obj instanceof Object[]) {
96            return toString((Object[]) obj);
97        }
98        if (obj instanceof Collection) {
99            return toString((Collection) obj);
100        }
101        if (obj instanceof Map) {
102            return toString((Map) obj);
103        }
104        if (obj instanceof Map.Entry) {
105            Map.Entry entry = (Map.Entry) obj;
106            return entry.getKey() + "=" + toString(entry.getValue());
107        }
108        return String.valueOf(obj);
109    }
110}

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