EMMA Coverage Report (generated Sun Mar 01 22:06:14 CET 2015)
[all classes][org.h2.util]

COVERAGE SUMMARY FOR SOURCE FILE [StatementBuilder.java]

nameclass, %method, %block, %line, %
StatementBuilder.java100% (1/1)100% (10/10)100% (78/78)100% (22/22)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class StatementBuilder100% (1/1)100% (10/10)100% (78/78)100% (22/22)
StatementBuilder (): void 100% (1/1)100% (8/8)100% (3/3)
StatementBuilder (String): void 100% (1/1)100% (13/13)100% (4/4)
append (String): StatementBuilder 100% (1/1)100% (7/7)100% (2/2)
append (char): StatementBuilder 100% (1/1)100% (7/7)100% (2/2)
append (long): StatementBuilder 100% (1/1)100% (7/7)100% (2/2)
appendExceptFirst (String): void 100% (1/1)100% (14/14)100% (3/3)
appendOnlyFirst (String): void 100% (1/1)100% (9/9)100% (3/3)
length (): int 100% (1/1)100% (4/4)100% (1/1)
resetCount (): StatementBuilder 100% (1/1)100% (5/5)100% (2/2)
toString (): String 100% (1/1)100% (4/4)100% (1/1)

1/*
2 * Copyright 2004-2014 H2 Group. Multiple-Licensed under the MPL 2.0,
3 * and the EPL 1.0 (http://h2database.com/html/license.html).
4 * Initial Developer: H2 Group
5 */
6package org.h2.util;
7 
8/**
9 * A utility class to build a statement. In addition to the methods supported by
10 * StringBuilder, it allows to add a text only in the second iteration. This
11 * simplified constructs such as:
12 * <pre>
13 * StringBuilder buff = new StringBuilder();
14 * for (int i = 0; i &lt; args.length; i++) {
15 *     if (i &gt; 0) {
16 *         buff.append(&quot;, &quot;);
17 *     }
18 *     buff.append(args[i]);
19 * }
20 * </pre>
21 * to
22 * <pre>
23 * StatementBuilder buff = new StatementBuilder();
24 * for (String s : args) {
25 *     buff.appendExceptFirst(&quot;, &quot;);
26 *     buff.append(a);
27 * }
28 *</pre>
29 */
30public class StatementBuilder {
31 
32    private final StringBuilder builder = new StringBuilder();
33    private int index;
34 
35    /**
36     * Create a new builder.
37     */
38    public StatementBuilder() {
39        // nothing to do
40    }
41 
42    /**
43     * Create a new builder.
44     *
45     * @param string the initial string
46     */
47    public StatementBuilder(String string) {
48        builder.append(string);
49    }
50 
51    /**
52     * Append a text.
53     *
54     * @param s the text to append
55     * @return itself
56     */
57    public StatementBuilder append(String s) {
58        builder.append(s);
59        return this;
60    }
61 
62    /**
63     * Append a character.
64     *
65     * @param c the character to append
66     * @return itself
67     */
68    public StatementBuilder append(char c) {
69        builder.append(c);
70        return this;
71    }
72 
73    /**
74     * Append a number.
75     *
76     * @param x the number to append
77     * @return itself
78     */
79    public StatementBuilder append(long x) {
80        builder.append(x);
81        return this;
82    }
83 
84    /**
85     * Reset the loop counter.
86     *
87     * @return itself
88     */
89    public StatementBuilder resetCount() {
90        index = 0;
91        return this;
92    }
93 
94    /**
95     * Append a text, but only if appendExceptFirst was never called.
96     *
97     * @param s the text to append
98     */
99    public void appendOnlyFirst(String s) {
100        if (index == 0) {
101            builder.append(s);
102        }
103    }
104 
105    /**
106     * Append a text, except when this method is called the first time.
107     *
108     * @param s the text to append
109     */
110    public void appendExceptFirst(String s) {
111        if (index++ > 0) {
112            builder.append(s);
113        }
114    }
115 
116    @Override
117    public String toString() {
118        return builder.toString();
119    }
120 
121    /**
122     * Get the length.
123     *
124     * @return the length
125     */
126    public int length() {
127        return builder.length();
128    }
129 
130}

[all classes][org.h2.util]
EMMA 2.0.5312 (C) Vladimir Roubtsov