Class CsvSupport.ColumnJoiner

java.lang.Object
io.jenetics.ext.util.CsvSupport.ColumnJoiner
Enclosing class:
CsvSupport

public static final class CsvSupport.ColumnJoiner extends Object
This class joins an array of columns into one CSV line.

Examples

Simple usage
final var joiner = ColumnJoiner.DEFAULT;
final var csv = Arrays.stream(data)
	.map(joiner::join)
	.collect(CsvSupport.toCsv());
Embedding and re-ordering data
final var data = new String[][] {
	{"Region", "City", "Country"},
	{"06", "aixas", "ad"},
	{"06", "aixirivali", "ad"},
	{"06", "aixirivall", "ad"},
	{"06", "aixirvall", "ad"},
	{"06", "aixovall", "ad"}
};

final var embedding = new ColumnIndexes(
	// Writes 'Region' as fourth column.
	3,
	// Write 'City' as second column.
	1,
	// Write 'Country' as third column.
	0,

	// Since the data rows have only three elements, the
	// missing column data are set to an empty string.
	// The last written column index will be 6, which
	// results to 7 written columns
	6
);

final var joiner = new ColumnJoiner(embedding);

final var csv = Arrays.stream(data)
	.map(joiner::join)
	.collect(CsvSupport.toCsv("\n"));

assert csv.equals("""
	Country,City,,Region,,,
	ad,aixas,,06,,,
	ad,aixirivali,,06,,,
	ad,aixirivall,,06,,,
	ad,aixirvall,,06,,,
	ad,aixovall,,06,,,
	"""
);
Since:
8.1
Version:
8.1
API Note:
The column joiner is thread-safe and can be shared between different threads.