Skip to content

Commit 56d9c8d

Browse files
committed
Add CSVRecord#toStream().
1 parent 2d6090b commit 56d9c8d

3 files changed

Lines changed: 21 additions & 0 deletions

File tree

src/changes/changes.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@
5959
<action issue="CSV-123" type="fix" dev="ggregory" due-to="Emmanuel Bourg, Benedikt Ritter, shivakrishnaah, Gary Gregory">Add possibility to use ResultSet header meta data as CSV header #11.</action>
6060
<!-- ADD -->
6161
<action issue="CSV-275" type="add" dev="ggregory" due-to="Michael Wyraz, Gary Gregory">Make CSVRecord#toList() public.</action>
62+
<action type="add" dev="ggregory" due-to="Gary Gregory">Add CSVRecord#toStream().</action>
6263
<!-- UPDATE -->
6364
<action type="update" dev="ggregory" due-to="Gary Gregory">Update org.junit.jupiter:junit-jupiter from 5.6.0 to 5.7.0, #84 #109</action>
6465
<action type="update" dev="ggregory" due-to="Gary Gregory">Update tests from Apache Commons Lang 3.9 to 3.12.0.</action>

src/main/java/org/apache/commons/csv/CSVRecord.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,16 @@ public Map<String, String> toMap() {
308308
return putIn(new LinkedHashMap<String, String>(values.length));
309309
}
310310

311+
/**
312+
* Returns a sequential ordered stream whose elements are the values.
313+
*
314+
* @return the new stream.
315+
* @since 1.9.0
316+
*/
317+
public Stream<String> toStream() {
318+
return Arrays.stream(values);
319+
}
320+
311321
/**
312322
* Returns a string representation of the contents of this record. The result is constructed by comment, mapping,
313323
* recordNumber and by passing the internal values array to {@link Arrays#toString(Object[])}.

src/test/java/org/apache/commons/csv/CSVRecordTest.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
import java.util.Map;
3535
import java.util.TreeMap;
3636
import java.util.concurrent.ConcurrentHashMap;
37+
import java.util.concurrent.atomic.AtomicInteger;
3738

3839
import org.apache.commons.lang3.StringUtils;
3940
import org.junit.jupiter.api.BeforeEach;
@@ -296,6 +297,15 @@ public void testToMapWithShortRecord() throws Exception {
296297
}
297298
}
298299

300+
@Test
301+
public void testToStream() {
302+
final AtomicInteger i = new AtomicInteger();
303+
record.toStream().forEach(value -> {
304+
assertEquals(values[i.get()], value);
305+
i.incrementAndGet();
306+
});
307+
}
308+
299309
@Test
300310
public void testToString() {
301311
assertNotNull(recordWithHeader.toString());

0 commit comments

Comments
 (0)