Skip to content
Permalink
Browse files
Use Stream.of() and rename new method to be like Collection#stream()
instead of toStream().
  • Loading branch information
garydgregory committed Jul 3, 2021
1 parent 805d329 commit a0fcf9a5a595c63e7098debac25d9c0c9f01fb36
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 17 deletions.
@@ -24,8 +24,8 @@
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.stream.Stream;
import java.util.Objects;
import java.util.stream.Stream;

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

/**
* Returns a sequential ordered stream whose elements are the values.
*
* @return the new stream.
* @since 1.9.0
*/
public Stream<String> stream() {
return Stream.of(values);
}

/**
* Converts the values to a List.
*
@@ -308,16 +318,6 @@ public Map<String, String> toMap() {
return putIn(new LinkedHashMap<String, String>(values.length));
}

/**
* Returns a sequential ordered stream whose elements are the values.
*
* @return the new stream.
* @since 1.9.0
*/
public Stream<String> toStream() {
return Arrays.stream(values);
}

/**
* Returns a string representation of the contents of this record. The result is constructed by comment, mapping,
* recordNumber and by passing the internal values array to {@link Arrays#toString(Object[])}.
@@ -54,10 +54,7 @@ private String readTestData(final BufferedReader reader) throws IOException {
public static Stream<File> generateData() {
final FilenameFilter fileNameFilter = (dir, name) -> name.startsWith("test") && name.endsWith(".txt");
final File[] files = BASE.listFiles(fileNameFilter);
if (files != null) {
return Arrays.stream(files);
}
return Stream.empty();
return files != null ? Stream.of(files) : Stream.empty();
}

@ParameterizedTest
@@ -298,9 +298,9 @@ public void testToMapWithShortRecord() throws Exception {
}

@Test
public void testToStream() {
public void testStream() {
final AtomicInteger i = new AtomicInteger();
record.toStream().forEach(value -> {
record.stream().forEach(value -> {
assertEquals(values[i.get()], value);
i.incrementAndGet();
});

0 comments on commit a0fcf9a

Please sign in to comment.