Skip to content

Commit

Permalink
Rename void IO and add tee()
Browse files Browse the repository at this point in the history
  • Loading branch information
sagebind committed May 4, 2017
1 parent c9aba61 commit 16a9ab9
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/main/java/com/widen/tabitha/RowReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public interface RowReader extends Iterable<Row>, Closeable
*
* Closing has no effect on this row reader and is always re-usable.
*/
RowReader EMPTY = Optional::empty;
RowReader VOID = Optional::empty;

/**
* Create a row reader from an array of rows.
Expand Down
32 changes: 31 additions & 1 deletion src/main/java/com/widen/tabitha/RowWriter.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,37 @@ public interface RowWriter extends Closeable
*
* Closing has no effect on this row writer and is always re-usable.
*/
RowWriter NULL = row -> {};
RowWriter VOID = row -> {};

/**
* Creates a new row writer that writes rows to multiple destinations.
*
* @param rowWriters The writers to write to.
* @return The new row writer.
*/
static RowWriter tee(RowWriter... rowWriters)
{
return new RowWriter()
{
@Override
public void write(Row row) throws IOException
{
for (RowWriter rowWriter : rowWriters)
{
rowWriter.write(row);
}
}

@Override
public void close() throws IOException
{
for (RowWriter rowWriter : rowWriters)
{
rowWriter.close();
}
}
};
}

/**
* Writes a row to the output.
Expand Down
2 changes: 1 addition & 1 deletion src/test/groovy/com/widen/tabitha/DataFrameTest.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class DataFrameTest extends Specification {
def "test is streaming"() {
setup:
def inMemory = new DataFrame()
def streaming = DataFrame.streaming(RowReader.EMPTY)
def streaming = DataFrame.streaming(RowReader.VOID)

expect:
!inMemory.isStreaming()
Expand Down
2 changes: 1 addition & 1 deletion src/test/groovy/com/widen/tabitha/RowReaderTest.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import spock.lang.*
class RowReaderTest extends Specification {
def "empty reader"() {
setup:
def reader = RowReader.EMPTY
def reader = RowReader.VOID

expect:
!reader.read().isPresent()
Expand Down
4 changes: 2 additions & 2 deletions src/test/groovy/com/widen/tabitha/RowWriterTest.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ package com.widen.tabitha
import spock.lang.*

class RowWriterTest extends Specification {
def "null is always writable"() {
def "void is always writable"() {
setup:
100.times {
RowWriter.NULL.write(Mock(Row.class))
RowWriter.VOID.write(Mock(Row.class))
}
}
}

0 comments on commit 16a9ab9

Please sign in to comment.