• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

pmd / pmd / 380

29 Jan 2026 03:55PM UTC coverage: 78.964%. Remained the same
380

push

github

adangel
[doc] ADR 3: Clarify javadoc tags (#6392)

18537 of 24358 branches covered (76.1%)

Branch coverage included in aggregate %.

40391 of 50268 relevant lines covered (80.35%)

0.81 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

95.0
/pmd-core/src/main/java/net/sourceforge/pmd/renderers/CSVWriter.java
1
/*
2
 * BSD-style license; for more info see http://pmd.sourceforge.net/license.html
3
 */
4

5
package net.sourceforge.pmd.renderers;
6

7
import java.io.IOException;
8
import java.io.Writer;
9
import java.util.Iterator;
10
import java.util.List;
11

12
import net.sourceforge.pmd.annotation.InternalApi;
13

14
/**
15
 * A generic writer that formats input items into rows and columns per the
16
 * provided column descriptors.
17
 *
18
 * @author Brian Remedios
19
 * @param <T>
20
 * @apiNote This is internal API and an implementation detail for {@link CSVRenderer}.
21
 */
22
@InternalApi
23
class CSVWriter<T> {
24

25
    private final String separator; // e.g., the comma
26
    private final String lineSeparator; // cr
27
    private final List<ColumnDescriptor<T>> columns;
28

29
    CSVWriter(List<ColumnDescriptor<T>> theColumns, String theSeparator, String theLineSeparator) {
1✔
30
        columns = theColumns;
1✔
31
        separator = theSeparator;
1✔
32
        lineSeparator = theLineSeparator;
1✔
33
    }
1✔
34

35
    public void writeTitles(Writer writer) throws IOException {
36
        StringBuilder buf = new StringBuilder(300);
1✔
37
        for (int i = 0; i < columns.size() - 1; i++) {
1✔
38
            quoteAndCommify(buf, columns.get(i).title);
1✔
39
        }
40

41
        quote(buf, columns.get(columns.size() - 1).title);
1✔
42

43
        buf.append(lineSeparator);
1✔
44
        writer.write(buf.toString());
1✔
45
    }
1✔
46

47
    public void writeData(Writer writer, Iterator<T> items) throws IOException {
48

49
        int count = 1;
1✔
50

51
        StringBuilder buf = new StringBuilder(300);
1✔
52

53
        T rv;
54
        final int lastColumnIdx = columns.size() - 1;
1✔
55

56
        while (items.hasNext()) {
1✔
57
            buf.setLength(0);
1✔
58
            rv = items.next();
1✔
59

60
            for (int i = 0; i < lastColumnIdx; i++) {
1✔
61
                quoteAndCommify(buf, columns.get(i).accessor.get(count, rv, separator));
1✔
62
            }
63

64
            quote(buf, columns.get(lastColumnIdx).accessor.get(count, rv, separator));
1✔
65

66
            buf.append(lineSeparator);
1✔
67
            writer.write(buf.toString());
1✔
68
            count++;
1✔
69
        }
70
    }
1✔
71

72
    private void quote(StringBuilder buffer, String s) {
73
        if (s == null) {
1!
74
            s = "";
×
75
        }
76
        buffer.append('"').append(s).append('"');
1✔
77
    }
1✔
78

79
    private void quoteAndCommify(StringBuilder buffer, String s) {
80
        quote(buffer, s);
1✔
81
        buffer.append(separator);
1✔
82
    }
1✔
83
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc