org.jsapar.compose.string.StringLineComposerNullOnEmptyCell Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jsapar Show documentation
Show all versions of jsapar Show documentation
JSaPar is a Java library providing a schema based parser and composer of almost collected sorts of delimited and fixed
width files.
The newest version!
package org.jsapar.compose.string;
import org.jsapar.model.Line;
import org.jsapar.schema.SchemaCell;
import org.jsapar.schema.SchemaLine;
import java.util.stream.Stream;
public final class StringLineComposerNullOnEmptyCell extends StringLineComposer {
StringLineComposerNullOnEmptyCell(SchemaLine extends SchemaCell> schemaLine) {
super(schemaLine);
}
@Override
Stream composeStringLine(Line line) {
return getCellComposers().stream().map(cellComposer ->
line.getCell(cellComposer.getName())
.map(cellComposer::compose)
.map(s->s.isEmpty() && !cellComposer.isDefaultValue() ? null : s)
.orElseGet(()-> cellComposer.isDefaultValue() ? cellComposer.compose(cellComposer.makeEmptyCell()) : null)
);
}
}