Skip to content

Commit 73f2fd1

Browse files
committed
Revert "Add support for column labels to CSVEncoder."
This reverts commit 1f73aad.
1 parent 1f73aad commit 73f2fd1

File tree

5 files changed

+22
-86
lines changed

5 files changed

+22
-86
lines changed

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
subprojects {
1616
group = 'org.httprpc'
17-
version = '7.3'
17+
version = '7.2.3'
1818

1919
apply plugin: 'java-library'
2020
apply plugin: 'maven-publish'

httprpc-client/src/main/java/org/httprpc/io/CSVEncoder.java

Lines changed: 16 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -27,90 +27,36 @@
2727
* CSV encoder.
2828
*/
2929
public class CSVEncoder extends Encoder<Iterable<? extends Map<String, ?>>> {
30-
/**
31-
* Class representing a column.
32-
*/
33-
public static final class Column {
34-
private String key;
35-
private String label;
36-
37-
/**
38-
* Constructs a new column.
39-
*
40-
* @param key
41-
* The column key.
42-
*/
43-
public Column(String key) {
44-
this(key, key);
45-
}
46-
47-
/**
48-
* Constructs a new column.
49-
*
50-
* @param key
51-
* The column key.
52-
*
53-
* @param label
54-
* The column label.
55-
*/
56-
public Column(String key, String label) {
57-
this.key = key;
58-
this.label = label;
59-
}
60-
61-
/**
62-
* Returns the column key.
63-
*
64-
* @return
65-
* The column key.
66-
*/
67-
public String getKey() {
68-
return key;
69-
}
70-
71-
/**
72-
* Returns the column label.
73-
*
74-
* @return
75-
* The column label.
76-
*/
77-
public String getLabel() {
78-
return label;
79-
}
80-
}
81-
82-
private List<Column> columns;
30+
private List<String> keys;
8331
private char delimiter;
8432

85-
private static final char DEFAULT_DELIMITER = ',';
86-
8733
/**
8834
* Constructs a new CSV encoder.
8935
*
90-
* @param columns
91-
* The output columns.
36+
* @param keys
37+
* The output column keys.
9238
*/
93-
public CSVEncoder(List<Column> columns) {
94-
this(columns, DEFAULT_DELIMITER);
39+
public CSVEncoder(List<String> keys) {
40+
this(keys, ',');
9541
}
9642

9743
/**
9844
* Constructs a new CSV encoder.
9945
*
100-
* @param columns
101-
* The output columns.
46+
* @param keys
47+
* The output column keys.
10248
*
10349
* @param delimiter
10450
* The character to use as a field delimiter.
10551
*/
106-
public CSVEncoder(List<Column> columns, char delimiter) {
52+
public CSVEncoder(List<String> keys, char delimiter) {
10753
super(StandardCharsets.ISO_8859_1);
10854

109-
if (columns == null) {
55+
if (keys == null) {
11056
throw new IllegalArgumentException();
11157
}
11258

113-
this.columns = columns;
59+
this.keys = keys;
11460
this.delimiter = delimiter;
11561
}
11662

@@ -120,16 +66,16 @@ public void write(Iterable<? extends Map<String, ?>> values, Writer writer) thro
12066

12167
int i = 0;
12268

123-
for (Column column : columns) {
124-
if (column == null) {
69+
for (String key : keys) {
70+
if (key == null) {
12571
continue;
12672
}
12773

12874
if (i > 0) {
12975
writer.write(delimiter);
13076
}
13177

132-
encode(column.getLabel(), writer);
78+
encode(key, writer);
13379

13480
i++;
13581
}
@@ -139,16 +85,16 @@ public void write(Iterable<? extends Map<String, ?>> values, Writer writer) thro
13985
for (Map<String, ?> map : values) {
14086
i = 0;
14187

142-
for (Column column : columns) {
143-
if (column == null) {
88+
for (String key : keys) {
89+
if (key == null) {
14490
continue;
14591
}
14692

14793
if (i > 0) {
14894
writer.write(delimiter);
14995
}
15096

151-
encode(BeanAdapter.valueAt(map, column.getKey()), writer);
97+
encode(BeanAdapter.valueAt(map, key), writer);
15298

15399
i++;
154100
}

httprpc-client/src/test/java/org/httprpc/io/CSVEncoderTest.java

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
import java.util.Date;
2323
import java.util.List;
2424
import java.util.Map;
25-
import java.util.stream.Collectors;
2625

2726
import static org.httprpc.util.Collections.entry;
2827
import static org.httprpc.util.Collections.listOf;
@@ -32,7 +31,7 @@
3231
public class CSVEncoderTest {
3332
@Test
3433
public void testWrite() throws IOException {
35-
String expected = "\"1\",\"2\",\"3\",\"d.e\",\"f\",\"g\"\r\n"
34+
String expected = "\"a\",\"b\",\"c\",\"d.e\",\"f\",\"g\"\r\n"
3635
+ "\"A,B,\"\"C\"\" \",1,2.0,true,0,3\r\n"
3736
+ "\" D\r\nÉ\r\nF\r\n\",2,4.0,,,\r\n";
3837

@@ -56,16 +55,7 @@ public void testWrite() throws IOException {
5655

5756
StringWriter writer = new StringWriter();
5857

59-
List<CSVEncoder.Column> columns = listOf(
60-
new CSVEncoder.Column("a", "1"),
61-
new CSVEncoder.Column("b", "2"),
62-
new CSVEncoder.Column("c", "3"),
63-
new CSVEncoder.Column("d.e"),
64-
new CSVEncoder.Column("f"),
65-
new CSVEncoder.Column("g")
66-
);
67-
68-
CSVEncoder csvEncoder = new CSVEncoder(columns);
58+
CSVEncoder csvEncoder = new CSVEncoder(listOf("a", "b", "c", "d.e", "f", "g"));
6959

7060
csvEncoder.write(values, writer);
7161

httprpc-server/src/main/java/org/httprpc/io/TemplateEncoder.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ public Object apply(Object value, String argument, Locale locale, TimeZone timeZ
279279
}
280280

281281
// CSV escape modifier
282-
private static class CSVEscapeModifier implements Modifier {
282+
private static class CSVEscapeModifier implements TemplateEncoder.Modifier {
283283
@Override
284284
public Object apply(Object value, String argument, Locale locale, TimeZone timeZone) {
285285
if (value instanceof CharSequence) {

httprpc-test/src/test/java/org/httprpc/WebServiceProxyTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ public void testCustomPost() throws IOException {
237237

238238
URL imageTestURL = WebServiceProxyTest.class.getResource("test.jpg");
239239

240-
webServiceProxy.setRequestHandler(outputStream -> {
240+
webServiceProxy.setRequestHandler((outputStream) -> {
241241
try (InputStream inputStream = imageTestURL.openStream()) {
242242
int b;
243243
while ((b = inputStream.read()) != EOF) {
@@ -261,7 +261,7 @@ public void testPut() throws IOException {
261261

262262
URL textTestURL = WebServiceProxyTest.class.getResource("test.txt");
263263

264-
webServiceProxy.setRequestHandler(outputStream -> {
264+
webServiceProxy.setRequestHandler((outputStream) -> {
265265
try (InputStream inputStream = textTestURL.openStream()) {
266266
int b;
267267
while ((b = inputStream.read()) != EOF) {

0 commit comments

Comments
 (0)