Use Stream.of() and rename new method to be like Collection#stream()
instead of toStream().
This commit is contained in:
parent
805d329bda
commit
a0fcf9a5a5
|
@ -24,8 +24,8 @@ import java.util.LinkedHashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
import java.util.stream.Stream;
|
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A CSV record parsed from a CSV file.
|
* A CSV record parsed from a CSV file.
|
||||||
|
@ -289,6 +289,16 @@ public final class CSVRecord implements Serializable, Iterable<String> {
|
||||||
return values.length;
|
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.
|
* Converts the values to a List.
|
||||||
*
|
*
|
||||||
|
@ -308,16 +318,6 @@ public final class CSVRecord implements Serializable, Iterable<String> {
|
||||||
return putIn(new LinkedHashMap<String, String>(values.length));
|
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,
|
* 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[])}.
|
* recordNumber and by passing the internal values array to {@link Arrays#toString(Object[])}.
|
||||||
|
|
|
@ -54,10 +54,7 @@ public class CSVFileParserTest {
|
||||||
public static Stream<File> generateData() {
|
public static Stream<File> generateData() {
|
||||||
final FilenameFilter fileNameFilter = (dir, name) -> name.startsWith("test") && name.endsWith(".txt");
|
final FilenameFilter fileNameFilter = (dir, name) -> name.startsWith("test") && name.endsWith(".txt");
|
||||||
final File[] files = BASE.listFiles(fileNameFilter);
|
final File[] files = BASE.listFiles(fileNameFilter);
|
||||||
if (files != null) {
|
return files != null ? Stream.of(files) : Stream.empty();
|
||||||
return Arrays.stream(files);
|
|
||||||
}
|
|
||||||
return Stream.empty();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ParameterizedTest
|
@ParameterizedTest
|
||||||
|
|
|
@ -298,9 +298,9 @@ public class CSVRecordTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testToStream() {
|
public void testStream() {
|
||||||
final AtomicInteger i = new AtomicInteger();
|
final AtomicInteger i = new AtomicInteger();
|
||||||
record.toStream().forEach(value -> {
|
record.stream().forEach(value -> {
|
||||||
assertEquals(values[i.get()], value);
|
assertEquals(values[i.get()], value);
|
||||||
i.incrementAndGet();
|
i.incrementAndGet();
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue