Skip to content

Commit a0fcf9a

Browse files
committed
Use Stream.of() and rename new method to be like Collection#stream()
instead of toStream().
1 parent 805d329 commit a0fcf9a

3 files changed

Lines changed: 14 additions & 17 deletions

File tree

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

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@
2424
import java.util.List;
2525
import java.util.Map;
2626
import java.util.Map.Entry;
27-
import java.util.stream.Stream;
2827
import java.util.Objects;
28+
import java.util.stream.Stream;
2929

3030
/**
3131
* A CSV record parsed from a CSV file.
@@ -289,6 +289,16 @@ public int size() {
289289
return values.length;
290290
}
291291

292+
/**
293+
* Returns a sequential ordered stream whose elements are the values.
294+
*
295+
* @return the new stream.
296+
* @since 1.9.0
297+
*/
298+
public Stream<String> stream() {
299+
return Stream.of(values);
300+
}
301+
292302
/**
293303
* Converts the values to a List.
294304
*
@@ -308,16 +318,6 @@ public Map<String, String> toMap() {
308318
return putIn(new LinkedHashMap<String, String>(values.length));
309319
}
310320

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-
321321
/**
322322
* Returns a string representation of the contents of this record. The result is constructed by comment, mapping,
323323
* recordNumber and by passing the internal values array to {@link Arrays#toString(Object[])}.

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

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,7 @@ private String readTestData(final BufferedReader reader) throws IOException {
5454
public static Stream<File> generateData() {
5555
final FilenameFilter fileNameFilter = (dir, name) -> name.startsWith("test") && name.endsWith(".txt");
5656
final File[] files = BASE.listFiles(fileNameFilter);
57-
if (files != null) {
58-
return Arrays.stream(files);
59-
}
60-
return Stream.empty();
57+
return files != null ? Stream.of(files) : Stream.empty();
6158
}
6259

6360
@ParameterizedTest

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -298,9 +298,9 @@ public void testToMapWithShortRecord() throws Exception {
298298
}
299299

300300
@Test
301-
public void testToStream() {
301+
public void testStream() {
302302
final AtomicInteger i = new AtomicInteger();
303-
record.toStream().forEach(value -> {
303+
record.stream().forEach(value -> {
304304
assertEquals(values[i.get()], value);
305305
i.incrementAndGet();
306306
});

0 commit comments

Comments
 (0)