diff --git a/zulia-data/src/main/java/io/zulia/data/source/json/JsonArrayDataSource.java b/zulia-data/src/main/java/io/zulia/data/source/json/JsonArraySource.java similarity index 60% rename from zulia-data/src/main/java/io/zulia/data/source/json/JsonArrayDataSource.java rename to zulia-data/src/main/java/io/zulia/data/source/json/JsonArraySource.java index b06432bf..c819a106 100644 --- a/zulia-data/src/main/java/io/zulia/data/source/json/JsonArrayDataSource.java +++ b/zulia-data/src/main/java/io/zulia/data/source/json/JsonArraySource.java @@ -9,30 +9,30 @@ import java.io.IOException; import java.util.Iterator; -public class JsonArrayDataSource implements DataSource, AutoCloseable { - private final JsonArrayDataSourceConfig jsonArrayDataSourceConfig; +public class JsonArraySource implements DataSource, AutoCloseable { + private final JsonArraySourceConfig jsonArraySourceConfig; private String next; private JsonParser parser; private final ObjectMapper mapper = new ObjectMapper(); - - public static JsonArrayDataSource withConfig(JsonArrayDataSourceConfig jsonArrayDataSourceConfig) throws IOException { - return new JsonArrayDataSource(jsonArrayDataSourceConfig); + + public static JsonArraySource withConfig(JsonArraySourceConfig jsonArraySourceConfig) throws IOException { + return new JsonArraySource(jsonArraySourceConfig); } - - public static JsonArrayDataSource withDefaults(DataInputStream dataInputStream) throws IOException { - return withConfig(JsonArrayDataSourceConfig.from(dataInputStream)); + + public static JsonArraySource withDefaults(DataInputStream dataInputStream) throws IOException { + return withConfig(JsonArraySourceConfig.from(dataInputStream)); } - - protected JsonArrayDataSource(JsonArrayDataSourceConfig jsonArrayDataSourceConfig) throws IOException { - this.jsonArrayDataSourceConfig = jsonArrayDataSourceConfig; + + protected JsonArraySource(JsonArraySourceConfig jsonArraySourceConfig) throws IOException { + this.jsonArraySourceConfig = jsonArraySourceConfig; open(); } protected void open() throws IOException { - - parser = mapper.getFactory().createParser(jsonArrayDataSourceConfig.getDataInputStream().openInputStream()); + + parser = mapper.getFactory().createParser(jsonArraySourceConfig.getDataInputStream().openInputStream()); if (parser.nextToken() != JsonToken.START_ARRAY) { throw new IllegalStateException("Expected an array"); } @@ -48,7 +48,7 @@ public void reset() throws IOException { } @Override - public Iterator iterator() { + public Iterator iterator() { if (next == null) { try { @@ -68,8 +68,8 @@ public boolean hasNext() { } @Override - public JsonDataSourceRecord next() { - JsonDataSourceRecord jsonDataSourceRecord = new JsonDataSourceRecord(next); + public JsonSourceRecord next() { + JsonSourceRecord jsonSourceRecord = new JsonSourceRecord(next); try { if (parser.nextToken() == JsonToken.START_OBJECT) { next = mapper.readTree(parser).toString(); @@ -82,7 +82,7 @@ public JsonDataSourceRecord next() { System.out.println(e.getMessage()); //throw new RuntimeException(e); } - return jsonDataSourceRecord; + return jsonSourceRecord; } @Override diff --git a/zulia-data/src/main/java/io/zulia/data/source/json/JsonArrayDataSourceConfig.java b/zulia-data/src/main/java/io/zulia/data/source/json/JsonArraySourceConfig.java similarity index 67% rename from zulia-data/src/main/java/io/zulia/data/source/json/JsonArrayDataSourceConfig.java rename to zulia-data/src/main/java/io/zulia/data/source/json/JsonArraySourceConfig.java index 98093e2b..b2e8c082 100644 --- a/zulia-data/src/main/java/io/zulia/data/source/json/JsonArrayDataSourceConfig.java +++ b/zulia-data/src/main/java/io/zulia/data/source/json/JsonArraySourceConfig.java @@ -5,17 +5,17 @@ import java.nio.charset.Charset; import java.nio.charset.StandardCharsets; -public class JsonArrayDataSourceConfig { +public class JsonArraySourceConfig { private final DataInputStream dataInputStream; private Charset charset = StandardCharsets.UTF_8; - - public static JsonArrayDataSourceConfig from(DataInputStream dataInputStream) { - return new JsonArrayDataSourceConfig(dataInputStream); + + public static JsonArraySourceConfig from(DataInputStream dataInputStream) { + return new JsonArraySourceConfig(dataInputStream); } - - private JsonArrayDataSourceConfig(DataInputStream dataInputStream) { + + private JsonArraySourceConfig(DataInputStream dataInputStream) { this.dataInputStream = dataInputStream; } diff --git a/zulia-data/src/main/java/io/zulia/data/source/json/JsonLineDataSource.java b/zulia-data/src/main/java/io/zulia/data/source/json/JsonLineDataSource.java index ee8c08a2..08638601 100644 --- a/zulia-data/src/main/java/io/zulia/data/source/json/JsonLineDataSource.java +++ b/zulia-data/src/main/java/io/zulia/data/source/json/JsonLineDataSource.java @@ -9,28 +9,28 @@ import java.io.InputStreamReader; import java.util.Iterator; -public class JsonLineDataSource implements DataSource, AutoCloseable { - private final JsonLineDataSourceConfig jsonLineDataSourceConfig; +public class JsonLineDataSource implements DataSource, AutoCloseable { + private final JsonLineSourceConfig jsonLineSourceConfig; private BufferedReader reader; private String next; - - public static JsonLineDataSource withConfig(JsonLineDataSourceConfig jsonLineDataSourceConfig) throws IOException { - return new JsonLineDataSource(jsonLineDataSourceConfig); + + public static JsonLineDataSource withConfig(JsonLineSourceConfig jsonLineSourceConfig) throws IOException { + return new JsonLineDataSource(jsonLineSourceConfig); } public static JsonLineDataSource withDefaults(DataInputStream dataInputStream) throws IOException { - return withConfig(JsonLineDataSourceConfig.from(dataInputStream)); + return withConfig(JsonLineSourceConfig.from(dataInputStream)); } - - protected JsonLineDataSource(JsonLineDataSourceConfig jsonLineDataSourceConfig) throws IOException { - this.jsonLineDataSourceConfig = jsonLineDataSourceConfig; + + protected JsonLineDataSource(JsonLineSourceConfig jsonLineSourceConfig) throws IOException { + this.jsonLineSourceConfig = jsonLineSourceConfig; open(); } protected void open() throws IOException { - InputStream inputStream = jsonLineDataSourceConfig.getDataInputStream().openInputStream(); - reader = new BufferedReader(new InputStreamReader(inputStream, jsonLineDataSourceConfig.getCharset().newDecoder())); + InputStream inputStream = jsonLineSourceConfig.getDataInputStream().openInputStream(); + reader = new BufferedReader(new InputStreamReader(inputStream, jsonLineSourceConfig.getCharset().newDecoder())); next = reader.readLine(); } @@ -40,7 +40,7 @@ public void reset() throws IOException { } @Override - public Iterator iterator() { + public Iterator iterator() { if (next == null) { try { @@ -59,14 +59,14 @@ public boolean hasNext() { } @Override - public JsonDataSourceRecord next() { + public JsonSourceRecord next() { try { - JsonDataSourceRecord jsonDataSourceRecord = new JsonDataSourceRecord(next); + JsonSourceRecord jsonSourceRecord = new JsonSourceRecord(next); next = reader.readLine(); - return jsonDataSourceRecord; + return jsonSourceRecord; } catch (Exception e) { - return jsonLineDataSourceConfig.getExceptionHandler().handleException(e); + return jsonLineSourceConfig.getExceptionHandler().handleException(e); } } diff --git a/zulia-data/src/main/java/io/zulia/data/source/json/JsonLineParseExceptionHandler.java b/zulia-data/src/main/java/io/zulia/data/source/json/JsonLineParseExceptionHandler.java index b2a23d67..a18d1237 100644 --- a/zulia-data/src/main/java/io/zulia/data/source/json/JsonLineParseExceptionHandler.java +++ b/zulia-data/src/main/java/io/zulia/data/source/json/JsonLineParseExceptionHandler.java @@ -1,6 +1,6 @@ package io.zulia.data.source.json; public interface JsonLineParseExceptionHandler { - - JsonDataSourceRecord handleException(Exception e); + + JsonSourceRecord handleException(Exception e); } diff --git a/zulia-data/src/main/java/io/zulia/data/source/json/JsonLineDataSourceConfig.java b/zulia-data/src/main/java/io/zulia/data/source/json/JsonLineSourceConfig.java similarity index 77% rename from zulia-data/src/main/java/io/zulia/data/source/json/JsonLineDataSourceConfig.java rename to zulia-data/src/main/java/io/zulia/data/source/json/JsonLineSourceConfig.java index a1334d13..a15d2617 100644 --- a/zulia-data/src/main/java/io/zulia/data/source/json/JsonLineDataSourceConfig.java +++ b/zulia-data/src/main/java/io/zulia/data/source/json/JsonLineSourceConfig.java @@ -5,19 +5,19 @@ import java.nio.charset.Charset; import java.nio.charset.StandardCharsets; -public class JsonLineDataSourceConfig { +public class JsonLineSourceConfig { private final DataInputStream dataInputStream; private Charset charset = StandardCharsets.UTF_8; private JsonLineParseExceptionHandler exceptionHandler = new ThrowingJsonLineParseExceptionHandler(); - - public static JsonLineDataSourceConfig from(DataInputStream dataInputStream) { - return new JsonLineDataSourceConfig(dataInputStream); + + public static JsonLineSourceConfig from(DataInputStream dataInputStream) { + return new JsonLineSourceConfig(dataInputStream); } - - private JsonLineDataSourceConfig(DataInputStream dataInputStream) { + + private JsonLineSourceConfig(DataInputStream dataInputStream) { this.dataInputStream = dataInputStream; } diff --git a/zulia-data/src/main/java/io/zulia/data/source/json/JsonDataSourceRecord.java b/zulia-data/src/main/java/io/zulia/data/source/json/JsonSourceRecord.java similarity index 92% rename from zulia-data/src/main/java/io/zulia/data/source/json/JsonDataSourceRecord.java rename to zulia-data/src/main/java/io/zulia/data/source/json/JsonSourceRecord.java index af9397b1..2edfbc4b 100644 --- a/zulia-data/src/main/java/io/zulia/data/source/json/JsonDataSourceRecord.java +++ b/zulia-data/src/main/java/io/zulia/data/source/json/JsonSourceRecord.java @@ -7,11 +7,11 @@ import java.util.Date; import java.util.List; -public class JsonDataSourceRecord implements DataSourceRecord { +public class JsonSourceRecord implements DataSourceRecord { private final Document document; - - public JsonDataSourceRecord(String json) { + + public JsonSourceRecord(String json) { document = Document.parse(json); } diff --git a/zulia-data/src/main/java/io/zulia/data/source/json/LoggingJsonLineParseExceptionHandler.java b/zulia-data/src/main/java/io/zulia/data/source/json/LoggingJsonLineParseExceptionHandler.java index 69dbde09..33dae637 100644 --- a/zulia-data/src/main/java/io/zulia/data/source/json/LoggingJsonLineParseExceptionHandler.java +++ b/zulia-data/src/main/java/io/zulia/data/source/json/LoggingJsonLineParseExceptionHandler.java @@ -11,7 +11,7 @@ public LoggingJsonLineParseExceptionHandler(Logger log) { } @Override - public JsonDataSourceRecord handleException(Exception e) { + public JsonSourceRecord handleException(Exception e) { log.error(e.getMessage(), e); return null; } diff --git a/zulia-data/src/main/java/io/zulia/data/source/json/ThrowingJsonLineParseExceptionHandler.java b/zulia-data/src/main/java/io/zulia/data/source/json/ThrowingJsonLineParseExceptionHandler.java index 0999656d..1c43a142 100644 --- a/zulia-data/src/main/java/io/zulia/data/source/json/ThrowingJsonLineParseExceptionHandler.java +++ b/zulia-data/src/main/java/io/zulia/data/source/json/ThrowingJsonLineParseExceptionHandler.java @@ -2,7 +2,7 @@ public class ThrowingJsonLineParseExceptionHandler implements JsonLineParseExceptionHandler { @Override - public JsonDataSourceRecord handleException(Exception e) { + public JsonSourceRecord handleException(Exception e) { throw new RuntimeException(e); } } diff --git a/zulia-data/src/main/java/io/zulia/data/source/spreadsheet/SpreadsheetDataSource.java b/zulia-data/src/main/java/io/zulia/data/source/spreadsheet/SpreadsheetSource.java similarity index 73% rename from zulia-data/src/main/java/io/zulia/data/source/spreadsheet/SpreadsheetDataSource.java rename to zulia-data/src/main/java/io/zulia/data/source/spreadsheet/SpreadsheetSource.java index 4c3dfc25..c80a44e9 100644 --- a/zulia-data/src/main/java/io/zulia/data/source/spreadsheet/SpreadsheetDataSource.java +++ b/zulia-data/src/main/java/io/zulia/data/source/spreadsheet/SpreadsheetSource.java @@ -5,7 +5,7 @@ import java.io.IOException; import java.util.SequencedSet; -public interface SpreadsheetDataSource extends DataSource { +public interface SpreadsheetSource extends DataSource { boolean hasHeader(String field); diff --git a/zulia-data/src/main/java/io/zulia/data/source/spreadsheet/SpreadsheetSourceFactory.java b/zulia-data/src/main/java/io/zulia/data/source/spreadsheet/SpreadsheetSourceFactory.java index b08e5a89..09f02f75 100644 --- a/zulia-data/src/main/java/io/zulia/data/source/spreadsheet/SpreadsheetSourceFactory.java +++ b/zulia-data/src/main/java/io/zulia/data/source/spreadsheet/SpreadsheetSourceFactory.java @@ -3,54 +3,54 @@ import io.zulia.data.common.SpreadsheetType; import io.zulia.data.input.DataInputStream; import io.zulia.data.input.FileDataInputStream; -import io.zulia.data.source.spreadsheet.csv.CSVDataSource; -import io.zulia.data.source.spreadsheet.csv.CSVDataSourceConfig; -import io.zulia.data.source.spreadsheet.excel.ExcelDataSource; -import io.zulia.data.source.spreadsheet.excel.ExcelDataSourceConfig; +import io.zulia.data.source.spreadsheet.csv.CSVSource; +import io.zulia.data.source.spreadsheet.csv.CSVSourceConfig; +import io.zulia.data.source.spreadsheet.excel.ExcelSource; +import io.zulia.data.source.spreadsheet.excel.ExcelSourceConfig; import java.io.IOException; public class SpreadsheetSourceFactory { - public static SpreadsheetDataSource fromFileWithoutHeaders(String filePath) throws IOException { + public static SpreadsheetSource fromFileWithoutHeaders(String filePath) throws IOException { return fromStream(FileDataInputStream.from(filePath), false); } - public static SpreadsheetDataSource fromFileWithHeaders(String filePath) throws IOException { + public static SpreadsheetSource fromFileWithHeaders(String filePath) throws IOException { return fromStream(FileDataInputStream.from(filePath), true); } - public static SpreadsheetDataSource fromFile(String filePath, boolean hasHeaders) throws IOException { + public static SpreadsheetSource fromFile(String filePath, boolean hasHeaders) throws IOException { return fromStream(FileDataInputStream.from(filePath), hasHeaders); } - public static SpreadsheetDataSource fromStreamWithoutHeaders(DataInputStream dataInputStream) throws IOException { + public static SpreadsheetSource fromStreamWithoutHeaders(DataInputStream dataInputStream) throws IOException { return fromStream(dataInputStream, false); } - public static SpreadsheetDataSource fromStreamWithHeaders(DataInputStream dataInputStream) throws IOException { + public static SpreadsheetSource fromStreamWithHeaders(DataInputStream dataInputStream) throws IOException { return fromStream(dataInputStream, true); } - public static SpreadsheetDataSource fromStream(DataInputStream dataInputStream, boolean hasHeaders) throws IOException { + public static SpreadsheetSource fromStream(DataInputStream dataInputStream, boolean hasHeaders) throws IOException { SpreadsheetType spreadsheetType = SpreadsheetType.getSpreadsheetType(dataInputStream.getMeta()); if (SpreadsheetType.CSV.equals(spreadsheetType) || SpreadsheetType.TSV.equals(spreadsheetType)) { - CSVDataSourceConfig csvDataSourceConfig = CSVDataSourceConfig.from(dataInputStream); + CSVSourceConfig csvSourceConfig = CSVSourceConfig.from(dataInputStream); if (hasHeaders) { - csvDataSourceConfig.withHeaders(); + csvSourceConfig.withHeaders(); } if (SpreadsheetType.TSV.equals(spreadsheetType)) { - csvDataSourceConfig.withDelimiter('\t'); + csvSourceConfig.withDelimiter('\t'); } - return CSVDataSource.withConfig(csvDataSourceConfig); + return CSVSource.withConfig(csvSourceConfig); } else if (SpreadsheetType.XLSX.equals(spreadsheetType) || SpreadsheetType.XLS.equals(spreadsheetType)) { - ExcelDataSourceConfig excelDataSourceConfig = ExcelDataSourceConfig.from(dataInputStream); + ExcelSourceConfig excelSourceConfig = ExcelSourceConfig.from(dataInputStream); if (hasHeaders) { - excelDataSourceConfig.withHeaders(); + excelSourceConfig.withHeaders(); } - return ExcelDataSource.withConfig(excelDataSourceConfig); + return ExcelSource.withConfig(excelSourceConfig); } else { throw new IllegalArgumentException("Failed to determine file type from content type <" + dataInputStream.getMeta() diff --git a/zulia-data/src/main/java/io/zulia/data/source/spreadsheet/csv/CSVDataSourceRecord.java b/zulia-data/src/main/java/io/zulia/data/source/spreadsheet/csv/CSVRecord.java similarity index 73% rename from zulia-data/src/main/java/io/zulia/data/source/spreadsheet/csv/CSVDataSourceRecord.java rename to zulia-data/src/main/java/io/zulia/data/source/spreadsheet/csv/CSVRecord.java index 05347f9a..eff27445 100644 --- a/zulia-data/src/main/java/io/zulia/data/source/spreadsheet/csv/CSVDataSourceRecord.java +++ b/zulia-data/src/main/java/io/zulia/data/source/spreadsheet/csv/CSVRecord.java @@ -7,23 +7,23 @@ import java.util.List; import java.util.SequencedSet; -public class CSVDataSourceRecord implements SpreadsheetRecord { +public class CSVRecord implements SpreadsheetRecord { private final String[] row; private final HeaderMapping headerMapping; - private final CSVDataSourceConfig csvDataSourceConfig; + private final CSVSourceConfig csvSourceConfig; - public CSVDataSourceRecord(String[] row, HeaderMapping headerMapping, CSVDataSourceConfig csvDataSourceConfig) { + public CSVRecord(String[] row, HeaderMapping headerMapping, CSVSourceConfig csvSourceConfig) { this.row = row; this.headerMapping = headerMapping; - this.csvDataSourceConfig = csvDataSourceConfig; + this.csvSourceConfig = csvSourceConfig; } public int getIndexFromField(String field) { if (headerMapping == null) { - throw new IllegalStateException("Use csvDataSourceConfig.withHeaders() use field names"); + throw new IllegalStateException("Use csvSourceConfig.withHeaders() use field names"); } if (headerMapping.hasHeader(field)) { return headerMapping.getHeaderIndex(field); @@ -34,7 +34,7 @@ public int getIndexFromField(String field) { @Override public List getList(String key, Class clazz) { String cellValue = getString(key); - return csvDataSourceConfig.getDelimitedListHandler().cellValueToList(clazz, cellValue); + return csvSourceConfig.getDelimitedListHandler().cellValueToList(clazz, cellValue); } @Override @@ -44,7 +44,7 @@ public String getString(String field) { @Override public Boolean getBoolean(String field) { - return parseFromString(field, csvDataSourceConfig.getBooleanParser(), null); + return parseFromString(field, csvSourceConfig.getBooleanParser(), null); } @Override @@ -69,13 +69,13 @@ public Long getLong(String field) { @Override public Date getDate(String field) { - return parseFromString(field, csvDataSourceConfig.getDateParser(), null); + return parseFromString(field, csvSourceConfig.getDateParser(), null); } @Override public List getList(int index, Class clazz) { String cellValue = getString(index); - return csvDataSourceConfig.getDelimitedListHandler().cellValueToList(clazz, cellValue); + return csvSourceConfig.getDelimitedListHandler().cellValueToList(clazz, cellValue); } @Override @@ -85,7 +85,7 @@ public String getString(int index) { @Override public Boolean getBoolean(int index) { - return parseFromString(index, csvDataSourceConfig.getBooleanParser(), null); + return parseFromString(index, csvSourceConfig.getBooleanParser(), null); } @Override @@ -110,7 +110,7 @@ public Long getLong(int index) { @Override public Date getDate(int index) { - return parseFromString(index, csvDataSourceConfig.getDateParser(), null); + return parseFromString(index, csvSourceConfig.getDateParser(), null); } public String[] getRow() { diff --git a/zulia-data/src/main/java/io/zulia/data/source/spreadsheet/csv/CSVDataSource.java b/zulia-data/src/main/java/io/zulia/data/source/spreadsheet/csv/CSVSource.java similarity index 63% rename from zulia-data/src/main/java/io/zulia/data/source/spreadsheet/csv/CSVDataSource.java rename to zulia-data/src/main/java/io/zulia/data/source/spreadsheet/csv/CSVSource.java index 68b69066..c35326dd 100644 --- a/zulia-data/src/main/java/io/zulia/data/source/spreadsheet/csv/CSVDataSource.java +++ b/zulia-data/src/main/java/io/zulia/data/source/spreadsheet/csv/CSVSource.java @@ -5,7 +5,7 @@ import com.univocity.parsers.csv.CsvParserSettings; import io.zulia.data.common.HeaderMapping; import io.zulia.data.input.DataInputStream; -import io.zulia.data.source.spreadsheet.SpreadsheetDataSource; +import io.zulia.data.source.spreadsheet.SpreadsheetSource; import java.io.BufferedInputStream; import java.io.IOException; @@ -13,28 +13,28 @@ import java.util.Iterator; import java.util.SequencedSet; -public class CSVDataSource implements SpreadsheetDataSource, AutoCloseable { - - private final CSVDataSourceConfig csvDataSourceConfig; +public class CSVSource implements SpreadsheetSource, AutoCloseable { + + private final CSVSourceConfig csvSourceConfig; private final CsvParser csvParser; private String[] nextRow; private HeaderMapping headerMapping; - - public static CSVDataSource withConfig(CSVDataSourceConfig csvDataSourceConfig) throws IOException { - return new CSVDataSource(csvDataSourceConfig); + + public static CSVSource withConfig(CSVSourceConfig csvSourceConfig) throws IOException { + return new CSVSource(csvSourceConfig); } - - public static CSVDataSource withDefaults(DataInputStream dataInputStream) throws IOException { - return withConfig(CSVDataSourceConfig.from(dataInputStream)); + + public static CSVSource withDefaults(DataInputStream dataInputStream) throws IOException { + return withConfig(CSVSourceConfig.from(dataInputStream)); } - - protected CSVDataSource(CSVDataSourceConfig csvDataSourceConfig) throws IOException { - this.csvDataSourceConfig = csvDataSourceConfig; + + protected CSVSource(CSVSourceConfig csvSourceConfig) throws IOException { + this.csvSourceConfig = csvSourceConfig; CsvParserSettings parserSettings = new CsvParserSettings(); parserSettings.setLineSeparatorDetectionEnabled(true); CsvFormat csvFormat = new CsvFormat(); - csvFormat.setDelimiter(csvDataSourceConfig.getDelimiter()); + csvFormat.setDelimiter(csvSourceConfig.getDelimiter()); parserSettings.setFormat(csvFormat); parserSettings.setMaxCharsPerColumn(100_000_000); parserSettings.setMaxColumns(10_000); @@ -48,12 +48,12 @@ public void reset() throws IOException { } protected void open() throws IOException { - csvParser.beginParsing(new BufferedInputStream(csvDataSourceConfig.getDataInputStream().openInputStream())); - - if (csvDataSourceConfig.hasHeaders()) { + csvParser.beginParsing(new BufferedInputStream(csvSourceConfig.getDataInputStream().openInputStream())); + + if (csvSourceConfig.hasHeaders()) { String[] headerRow = csvParser.parseNext(); - headerMapping = new HeaderMapping(csvDataSourceConfig.getHeaderConfig(), Arrays.stream(headerRow).toList()); + headerMapping = new HeaderMapping(csvSourceConfig.getHeaderConfig(), Arrays.stream(headerRow).toList()); } @@ -75,7 +75,7 @@ public SequencedSet getHeaders() { } @Override - public Iterator iterator() { + public Iterator iterator() { //handles multiple iterations with the same DataSources if (nextRow == null) { @@ -95,8 +95,8 @@ public boolean hasNext() { } @Override - public CSVDataSourceRecord next() { - CSVDataSourceRecord csvDataSourceRecord = new CSVDataSourceRecord(nextRow, headerMapping, csvDataSourceConfig); + public CSVRecord next() { + CSVRecord csvDataSourceRecord = new CSVRecord(nextRow, headerMapping, csvSourceConfig); nextRow = csvParser.parseNext(); return csvDataSourceRecord; } diff --git a/zulia-data/src/main/java/io/zulia/data/source/spreadsheet/csv/CSVDataSourceConfig.java b/zulia-data/src/main/java/io/zulia/data/source/spreadsheet/csv/CSVSourceConfig.java similarity index 73% rename from zulia-data/src/main/java/io/zulia/data/source/spreadsheet/csv/CSVDataSourceConfig.java rename to zulia-data/src/main/java/io/zulia/data/source/spreadsheet/csv/CSVSourceConfig.java index 0f898240..48bda733 100644 --- a/zulia-data/src/main/java/io/zulia/data/source/spreadsheet/csv/CSVDataSourceConfig.java +++ b/zulia-data/src/main/java/io/zulia/data/source/spreadsheet/csv/CSVSourceConfig.java @@ -11,13 +11,13 @@ import java.util.Date; import java.util.function.Function; -public class CSVDataSourceConfig { +public class CSVSourceConfig { private Function booleanParser; private Function dateParser; - public static CSVDataSourceConfig from(DataInputStream dataStream) { - return new CSVDataSourceConfig(dataStream); + public static CSVSourceConfig from(DataInputStream dataStream) { + return new CSVSourceConfig(dataStream); } private final DataInputStream dataInputStream; @@ -26,8 +26,8 @@ public static CSVDataSourceConfig from(DataInputStream dataStream) { private HeaderConfig headerConfig; private DelimitedListHandler delimitedListHandler = new DefaultDelimitedListHandler(';'); - - private CSVDataSourceConfig(DataInputStream dataInputStream) { + + private CSVSourceConfig(DataInputStream dataInputStream) { this.dataInputStream = dataInputStream; this.booleanParser = (s) -> { String lowerCase = s.toLowerCase(); @@ -41,32 +41,32 @@ private CSVDataSourceConfig(DataInputStream dataInputStream) { DateTimeFormatter formatter = DateTimeFormatter.ISO_LOCAL_DATE; this.dateParser = (s) -> Date.from(LocalDate.from(formatter.parse(s)).atStartOfDay().atOffset(ZoneOffset.UTC).toInstant()); } - - public CSVDataSourceConfig withDelimiter(char delimiter) { + + public CSVSourceConfig withDelimiter(char delimiter) { this.delimiter = delimiter; return this; } - - public CSVDataSourceConfig withListDelimiter(char listDelimiter) { + + public CSVSourceConfig withListDelimiter(char listDelimiter) { this.delimitedListHandler = new DefaultDelimitedListHandler(listDelimiter); return this; } - - public CSVDataSourceConfig withDelimitedListHandler(DelimitedListHandler delimitedListHandler) { + + public CSVSourceConfig withDelimitedListHandler(DelimitedListHandler delimitedListHandler) { this.delimitedListHandler = delimitedListHandler; return this; } - - public CSVDataSourceConfig withHeaders() { + + public CSVSourceConfig withHeaders() { return withHeaders(new HeaderConfig()); } - - public CSVDataSourceConfig withHeaders(HeaderConfig headerConfig) { + + public CSVSourceConfig withHeaders(HeaderConfig headerConfig) { this.headerConfig = headerConfig; return this; } - - public CSVDataSourceConfig withoutHeaders() { + + public CSVSourceConfig withoutHeaders() { this.headerConfig = null; return this; } @@ -95,7 +95,7 @@ public Function getBooleanParser() { return booleanParser; } - public CSVDataSourceConfig withBooleanParser(Function booleanParser) { + public CSVSourceConfig withBooleanParser(Function booleanParser) { this.booleanParser = booleanParser; return this; } @@ -104,7 +104,7 @@ public Function getDateParser() { return dateParser; } - public CSVDataSourceConfig withDateParser(Function dateParser) { + public CSVSourceConfig withDateParser(Function dateParser) { this.dateParser = dateParser; return this; } diff --git a/zulia-data/src/main/java/io/zulia/data/source/spreadsheet/csv/DataSourceConfigFactory.java b/zulia-data/src/main/java/io/zulia/data/source/spreadsheet/csv/DataSourceConfigFactory.java deleted file mode 100644 index e4f6f2ed..00000000 --- a/zulia-data/src/main/java/io/zulia/data/source/spreadsheet/csv/DataSourceConfigFactory.java +++ /dev/null @@ -1,12 +0,0 @@ -package io.zulia.data.source.spreadsheet.csv; - -import io.zulia.data.input.FileDataInputStream; - -import java.io.IOException; - -public class DataSourceConfigFactory { - - public static CSVDataSourceConfig fromCSVFile(String filePath) throws IOException { - return CSVDataSourceConfig.from(FileDataInputStream.from(filePath)); - } -} diff --git a/zulia-data/src/main/java/io/zulia/data/source/spreadsheet/excel/ExcelDataSourceRecord.java b/zulia-data/src/main/java/io/zulia/data/source/spreadsheet/excel/ExcelRecord.java similarity index 91% rename from zulia-data/src/main/java/io/zulia/data/source/spreadsheet/excel/ExcelDataSourceRecord.java rename to zulia-data/src/main/java/io/zulia/data/source/spreadsheet/excel/ExcelRecord.java index 95b84751..3842d16b 100644 --- a/zulia-data/src/main/java/io/zulia/data/source/spreadsheet/excel/ExcelDataSourceRecord.java +++ b/zulia-data/src/main/java/io/zulia/data/source/spreadsheet/excel/ExcelRecord.java @@ -10,19 +10,19 @@ import java.util.List; import java.util.SequencedSet; -public class ExcelDataSourceRecord implements SpreadsheetRecord { +public class ExcelRecord implements SpreadsheetRecord { private final Row row; private final DelimitedListHandler delimitedListHandler; private final ExcelCellHandler excelCellHandler; private final SheetInfo sheetInfo; - - public ExcelDataSourceRecord(Row row, SheetInfo sheetInfo, ExcelDataSourceConfig excelDataSourceConfig) { + + public ExcelRecord(Row row, SheetInfo sheetInfo, ExcelSourceConfig excelSourceConfig) { this.row = row; this.sheetInfo = sheetInfo; - this.delimitedListHandler = excelDataSourceConfig.getDelimitedListHandler(); - this.excelCellHandler = excelDataSourceConfig.getExcelCellHandler(); + this.delimitedListHandler = excelSourceConfig.getDelimitedListHandler(); + this.excelCellHandler = excelSourceConfig.getExcelCellHandler(); } public int getIndexFromField(String field) { diff --git a/zulia-data/src/main/java/io/zulia/data/source/spreadsheet/excel/ExcelDataSource.java b/zulia-data/src/main/java/io/zulia/data/source/spreadsheet/excel/ExcelSource.java similarity index 66% rename from zulia-data/src/main/java/io/zulia/data/source/spreadsheet/excel/ExcelDataSource.java rename to zulia-data/src/main/java/io/zulia/data/source/spreadsheet/excel/ExcelSource.java index 11322064..80d4a395 100644 --- a/zulia-data/src/main/java/io/zulia/data/source/spreadsheet/excel/ExcelDataSource.java +++ b/zulia-data/src/main/java/io/zulia/data/source/spreadsheet/excel/ExcelSource.java @@ -2,7 +2,7 @@ import io.zulia.data.common.HeaderMapping; import io.zulia.data.input.DataInputStream; -import io.zulia.data.source.spreadsheet.SpreadsheetDataSource; +import io.zulia.data.source.spreadsheet.SpreadsheetSource; import org.apache.poi.openxml4j.util.ZipInputStreamZipEntrySource; import org.apache.poi.ss.usermodel.*; import org.apache.poi.util.IOUtils; @@ -11,7 +11,7 @@ import java.io.IOException; import java.util.*; -public class ExcelDataSource implements SpreadsheetDataSource, AutoCloseable { +public class ExcelSource implements SpreadsheetSource, AutoCloseable { static { LocaleUtil.setUserTimeZone(LocaleUtil.TIMEZONE_UTC); @@ -19,7 +19,7 @@ public class ExcelDataSource implements SpreadsheetDataSource headerRow = new ArrayList<>(); Row header = sheet.getRow(0); @@ -108,7 +108,7 @@ private void initializeSheet() { headerRow.add(excelCellHandler.cellToString(cell)); } } - sheetInfo = new SheetInfo(numberOfColumns, numberOfRowsForSheet, new HeaderMapping(excelDataSourceConfig.getHeaderConfig(), headerRow)); + sheetInfo = new SheetInfo(numberOfColumns, numberOfRowsForSheet, new HeaderMapping(excelSourceConfig.getHeaderConfig(), headerRow)); } else { sheetInfo = new SheetInfo(numberOfColumns, numberOfRowsForSheet, null); @@ -123,16 +123,16 @@ public void reset() { } private int getStartRow() { - return excelDataSourceConfig.hasHeaders() ? 1 : 0; + return excelSourceConfig.hasHeaders() ? 1 : 0; } - public ExcelDataSource setRow(int newRow) { + public ExcelSource setRow(int newRow) { currentRow = newRow; return this; } @Override - public Iterator iterator() { + public Iterator iterator() { if (currentRow != getStartRow()) { reset(); @@ -146,10 +146,10 @@ public boolean hasNext() { } @Override - public ExcelDataSourceRecord next() { + public ExcelRecord next() { Row next = sheet.getRow(currentRow); currentRow++; - return new ExcelDataSourceRecord(next, sheetInfo, excelDataSourceConfig); + return new ExcelRecord(next, sheetInfo, excelSourceConfig); } @Override diff --git a/zulia-data/src/main/java/io/zulia/data/source/spreadsheet/excel/ExcelDataSourceConfig.java b/zulia-data/src/main/java/io/zulia/data/source/spreadsheet/excel/ExcelSourceConfig.java similarity index 68% rename from zulia-data/src/main/java/io/zulia/data/source/spreadsheet/excel/ExcelDataSourceConfig.java rename to zulia-data/src/main/java/io/zulia/data/source/spreadsheet/excel/ExcelSourceConfig.java index 828282ac..17357412 100644 --- a/zulia-data/src/main/java/io/zulia/data/source/spreadsheet/excel/ExcelDataSourceConfig.java +++ b/zulia-data/src/main/java/io/zulia/data/source/spreadsheet/excel/ExcelSourceConfig.java @@ -5,10 +5,10 @@ import io.zulia.data.source.spreadsheet.DefaultDelimitedListHandler; import io.zulia.data.source.spreadsheet.DelimitedListHandler; -public class ExcelDataSourceConfig { - - public static ExcelDataSourceConfig from(DataInputStream dataStream) { - return new ExcelDataSourceConfig(dataStream); +public class ExcelSourceConfig { + + public static ExcelSourceConfig from(DataInputStream dataStream) { + return new ExcelSourceConfig(dataStream); } private DelimitedListHandler delimitedListHandler = new DefaultDelimitedListHandler(';'); @@ -24,36 +24,36 @@ public enum OpenHandling { ACTIVE_SHEET, FIRST_SHEET } - - private ExcelDataSourceConfig(DataInputStream dataInputStream) { + + private ExcelSourceConfig(DataInputStream dataInputStream) { this.dataInputStream = dataInputStream; } - - public ExcelDataSourceConfig withHeaders() { + + public ExcelSourceConfig withHeaders() { return withHeaders(new HeaderConfig()); } - - public ExcelDataSourceConfig withHeaders(HeaderConfig headerConfig) { + + public ExcelSourceConfig withHeaders(HeaderConfig headerConfig) { this.headerConfig = headerConfig; return this; } - - public ExcelDataSourceConfig withoutHeaders() { + + public ExcelSourceConfig withoutHeaders() { this.headerConfig = null; return this; } - - public ExcelDataSourceConfig withListDelimiter(char listDelimiter) { + + public ExcelSourceConfig withListDelimiter(char listDelimiter) { this.delimitedListHandler = new DefaultDelimitedListHandler(listDelimiter); return this; } - - public ExcelDataSourceConfig withDelimitedListHandler(DelimitedListHandler delimitedListHandler) { + + public ExcelSourceConfig withDelimitedListHandler(DelimitedListHandler delimitedListHandler) { this.delimitedListHandler = delimitedListHandler; return this; } - - public ExcelDataSourceConfig withExcelCellHandler(ExcelCellHandler excelCellHandler) { + + public ExcelSourceConfig withExcelCellHandler(ExcelCellHandler excelCellHandler) { this.excelCellHandler = excelCellHandler; return this; } @@ -61,8 +61,8 @@ public ExcelDataSourceConfig withExcelCellHandler(ExcelCellHandler excelCellHand public final OpenHandling getOpenHandling() { return openHandling; } - - public final ExcelDataSourceConfig setOpenHandling(OpenHandling openHandling) { + + public final ExcelSourceConfig setOpenHandling(OpenHandling openHandling) { this.openHandling = openHandling; return this; } diff --git a/zulia-data/src/main/java/io/zulia/data/target/spreadsheet/SpreadsheetDataTarget.java b/zulia-data/src/main/java/io/zulia/data/target/spreadsheet/SpreadsheetTarget.java similarity index 90% rename from zulia-data/src/main/java/io/zulia/data/target/spreadsheet/SpreadsheetDataTarget.java rename to zulia-data/src/main/java/io/zulia/data/target/spreadsheet/SpreadsheetTarget.java index b3fa6113..30d28d69 100644 --- a/zulia-data/src/main/java/io/zulia/data/target/spreadsheet/SpreadsheetDataTarget.java +++ b/zulia-data/src/main/java/io/zulia/data/target/spreadsheet/SpreadsheetTarget.java @@ -6,11 +6,11 @@ import java.util.Collection; import java.util.Date; -public abstract class SpreadsheetDataTarget> implements AutoCloseable { +public abstract class SpreadsheetTarget> implements AutoCloseable { - private final SpreadsheetDataTargetConfig dataConfig; + private final SpreadsheetTargetConfig dataConfig; - public SpreadsheetDataTarget(SpreadsheetDataTargetConfig dataConfig) { + public SpreadsheetTarget(SpreadsheetTargetConfig dataConfig) { this.dataConfig = dataConfig; } diff --git a/zulia-data/src/main/java/io/zulia/data/target/spreadsheet/SpreadsheetDataTargetConfig.java b/zulia-data/src/main/java/io/zulia/data/target/spreadsheet/SpreadsheetTargetConfig.java similarity index 95% rename from zulia-data/src/main/java/io/zulia/data/target/spreadsheet/SpreadsheetDataTargetConfig.java rename to zulia-data/src/main/java/io/zulia/data/target/spreadsheet/SpreadsheetTargetConfig.java index 993d9144..326cc8e9 100644 --- a/zulia-data/src/main/java/io/zulia/data/target/spreadsheet/SpreadsheetDataTargetConfig.java +++ b/zulia-data/src/main/java/io/zulia/data/target/spreadsheet/SpreadsheetTargetConfig.java @@ -8,7 +8,7 @@ import java.util.Collection; import java.util.Date; -public abstract class SpreadsheetDataTargetConfig> { +public abstract class SpreadsheetTargetConfig> { private final DataOutputStream dataStream; @@ -25,7 +25,7 @@ public abstract class SpreadsheetDataTargetConfig defaultTypeHandler; private SpreadsheetTypeHandler headerHandler; - public SpreadsheetDataTargetConfig(DataOutputStream dataStream) { + public SpreadsheetTargetConfig(DataOutputStream dataStream) { this.dataStream = dataStream; withListDelimiter(';'); } diff --git a/zulia-data/src/main/java/io/zulia/data/target/spreadsheet/SpreadsheetTargetFactory.java b/zulia-data/src/main/java/io/zulia/data/target/spreadsheet/SpreadsheetTargetFactory.java index a75a1b99..ec2cd745 100644 --- a/zulia-data/src/main/java/io/zulia/data/target/spreadsheet/SpreadsheetTargetFactory.java +++ b/zulia-data/src/main/java/io/zulia/data/target/spreadsheet/SpreadsheetTargetFactory.java @@ -3,47 +3,47 @@ import io.zulia.data.common.SpreadsheetType; import io.zulia.data.output.DataOutputStream; import io.zulia.data.output.FileDataOutputStream; -import io.zulia.data.target.spreadsheet.csv.CSVDataTarget; -import io.zulia.data.target.spreadsheet.csv.CSVDataTargetConfig; -import io.zulia.data.target.spreadsheet.excel.ExcelDataTarget; -import io.zulia.data.target.spreadsheet.excel.ExcelDataTargetConfig; +import io.zulia.data.target.spreadsheet.csv.CSVTarget; +import io.zulia.data.target.spreadsheet.csv.CSVTargetConfig; +import io.zulia.data.target.spreadsheet.excel.ExcelTarget; +import io.zulia.data.target.spreadsheet.excel.ExcelTargetConfig; import java.io.IOException; import java.util.Collection; public class SpreadsheetTargetFactory { - public static SpreadsheetDataTarget fromFile(String filePath, boolean overwrite) throws IOException { + public static SpreadsheetTarget fromFile(String filePath, boolean overwrite) throws IOException { return fromStream(FileDataOutputStream.from(filePath, overwrite)); } - public static SpreadsheetDataTarget fromStream(DataOutputStream dataOutputStream) throws IOException { + public static SpreadsheetTarget fromStream(DataOutputStream dataOutputStream) throws IOException { return fromStreamWithHeaders(dataOutputStream, null); } - public static SpreadsheetDataTarget fromFileWithHeaders(String filePath, boolean overwrite, Collection headers) throws IOException { + public static SpreadsheetTarget fromFileWithHeaders(String filePath, boolean overwrite, Collection headers) throws IOException { return fromStreamWithHeaders(FileDataOutputStream.from(filePath, overwrite), headers); } - public static SpreadsheetDataTarget fromStreamWithHeaders(DataOutputStream dataOutputStream, Collection headers) throws IOException { + public static SpreadsheetTarget fromStreamWithHeaders(DataOutputStream dataOutputStream, Collection headers) throws IOException { SpreadsheetType spreadsheetType = SpreadsheetType.getSpreadsheetType(dataOutputStream.getMeta()); if (SpreadsheetType.CSV.equals(spreadsheetType) || SpreadsheetType.TSV.equals(spreadsheetType)) { - CSVDataTargetConfig csvDataTargetConfig = CSVDataTargetConfig.from(dataOutputStream); + CSVTargetConfig csvDataTargetConfig = CSVTargetConfig.from(dataOutputStream); if (headers != null) { csvDataTargetConfig.withHeaders(headers); } if (SpreadsheetType.TSV.equals(spreadsheetType)) { csvDataTargetConfig.withDelimiter('\t'); } - return CSVDataTarget.withConfig(csvDataTargetConfig); + return CSVTarget.withConfig(csvDataTargetConfig); } else if (SpreadsheetType.XLSX.equals(spreadsheetType)) { - ExcelDataTargetConfig excelDataSourceConfig = ExcelDataTargetConfig.from(dataOutputStream); + ExcelTargetConfig excelDataSourceConfig = ExcelTargetConfig.from(dataOutputStream); if (headers != null) { excelDataSourceConfig.withHeaders(headers); } - return ExcelDataTarget.withConfig(excelDataSourceConfig); + return ExcelTarget.withConfig(excelDataSourceConfig); } else { throw new IllegalArgumentException("Failed to determine file type from content type <" + dataOutputStream.getMeta() diff --git a/zulia-data/src/main/java/io/zulia/data/target/spreadsheet/csv/CSVDataTarget.java b/zulia-data/src/main/java/io/zulia/data/target/spreadsheet/csv/CSVTarget.java similarity index 53% rename from zulia-data/src/main/java/io/zulia/data/target/spreadsheet/csv/CSVDataTarget.java rename to zulia-data/src/main/java/io/zulia/data/target/spreadsheet/csv/CSVTarget.java index 1d8fae2e..8336eb99 100644 --- a/zulia-data/src/main/java/io/zulia/data/target/spreadsheet/csv/CSVDataTarget.java +++ b/zulia-data/src/main/java/io/zulia/data/target/spreadsheet/csv/CSVTarget.java @@ -4,35 +4,35 @@ import com.univocity.parsers.csv.CsvWriterSettings; import io.zulia.data.output.DataOutputStream; import io.zulia.data.output.FileDataOutputStream; -import io.zulia.data.target.spreadsheet.SpreadsheetDataTarget; +import io.zulia.data.target.spreadsheet.SpreadsheetTarget; import java.io.IOException; import java.util.Collection; -public class CSVDataTarget extends SpreadsheetDataTarget { +public class CSVTarget extends SpreadsheetTarget { private final CsvWriterSettings settings; - private final CSVDataTargetConfig csvDataTargetConfig; + private final CSVTargetConfig csvDataTargetConfig; private CsvWriter csvWriter; - public static CSVDataTarget withConfig(CSVDataTargetConfig csvDataTargetConfig) throws IOException { - return new CSVDataTarget(csvDataTargetConfig); + public static CSVTarget withConfig(CSVTargetConfig csvDataTargetConfig) throws IOException { + return new CSVTarget(csvDataTargetConfig); } - public static CSVDataTarget withDefaults(DataOutputStream dataOutputStream) throws IOException { - return withConfig(CSVDataTargetConfig.from(dataOutputStream)); + public static CSVTarget withDefaults(DataOutputStream dataOutputStream) throws IOException { + return withConfig(CSVTargetConfig.from(dataOutputStream)); } - public static CSVDataTarget withDefaultsFromFile(String path, boolean overwrite) throws IOException { + public static CSVTarget withDefaultsFromFile(String path, boolean overwrite) throws IOException { return withDefaults(FileDataOutputStream.from(path, overwrite)); } - public static CSVDataTarget withDefaultsFromFile(String path, boolean overwrite, Collection headers) throws IOException { - return withConfig(CSVDataTargetConfig.from(FileDataOutputStream.from(path, overwrite)).withHeaders(headers)); + public static CSVTarget withDefaultsFromFile(String path, boolean overwrite, Collection headers) throws IOException { + return withConfig(CSVTargetConfig.from(FileDataOutputStream.from(path, overwrite)).withHeaders(headers)); } - protected CSVDataTarget(CSVDataTargetConfig csvDataTargetConfig) throws IOException { + protected CSVTarget(CSVTargetConfig csvDataTargetConfig) throws IOException { super(csvDataTargetConfig); this.csvDataTargetConfig = csvDataTargetConfig; settings = new CsvWriterSettings(); diff --git a/zulia-data/src/main/java/io/zulia/data/target/spreadsheet/csv/CSVDataTargetConfig.java b/zulia-data/src/main/java/io/zulia/data/target/spreadsheet/csv/CSVTargetConfig.java similarity index 64% rename from zulia-data/src/main/java/io/zulia/data/target/spreadsheet/csv/CSVDataTargetConfig.java rename to zulia-data/src/main/java/io/zulia/data/target/spreadsheet/csv/CSVTargetConfig.java index 1ede990c..ecd8d0ad 100644 --- a/zulia-data/src/main/java/io/zulia/data/target/spreadsheet/csv/CSVDataTargetConfig.java +++ b/zulia-data/src/main/java/io/zulia/data/target/spreadsheet/csv/CSVTargetConfig.java @@ -2,18 +2,18 @@ import com.univocity.parsers.csv.CsvWriter; import io.zulia.data.output.DataOutputStream; -import io.zulia.data.target.spreadsheet.SpreadsheetDataTargetConfig; +import io.zulia.data.target.spreadsheet.SpreadsheetTargetConfig; import io.zulia.data.target.spreadsheet.csv.formatter.*; -public class CSVDataTargetConfig extends SpreadsheetDataTargetConfig { +public class CSVTargetConfig extends SpreadsheetTargetConfig { - public static CSVDataTargetConfig from(DataOutputStream dataStream) { - return new CSVDataTargetConfig(dataStream); + public static CSVTargetConfig from(DataOutputStream dataStream) { + return new CSVTargetConfig(dataStream); } private char delimiter = ','; - public CSVDataTargetConfig(DataOutputStream dataStream) { + public CSVTargetConfig(DataOutputStream dataStream) { super(dataStream); withStringHandler(new StringCSVWriter()); withDateTypeHandler(new DateCSVWriter()); @@ -26,11 +26,11 @@ public CSVDataTargetConfig(DataOutputStream dataStream) { } @Override - protected CSVDataTargetConfig getSelf() { + protected CSVTargetConfig getSelf() { return this; } - public CSVDataTargetConfig withDelimiter(char delimiter) { + public CSVTargetConfig withDelimiter(char delimiter) { this.delimiter = delimiter; return this; } diff --git a/zulia-data/src/main/java/io/zulia/data/target/spreadsheet/csv/formatter/CollectionCSVWriter.java b/zulia-data/src/main/java/io/zulia/data/target/spreadsheet/csv/formatter/CollectionCSVWriter.java index 1881d305..8e996a12 100644 --- a/zulia-data/src/main/java/io/zulia/data/target/spreadsheet/csv/formatter/CollectionCSVWriter.java +++ b/zulia-data/src/main/java/io/zulia/data/target/spreadsheet/csv/formatter/CollectionCSVWriter.java @@ -3,15 +3,15 @@ import com.univocity.parsers.csv.CsvWriter; import io.zulia.data.source.spreadsheet.DelimitedListHandler; import io.zulia.data.target.spreadsheet.SpreadsheetTypeHandler; -import io.zulia.data.target.spreadsheet.csv.CSVDataTargetConfig; +import io.zulia.data.target.spreadsheet.csv.CSVTargetConfig; import java.util.Collection; public class CollectionCSVWriter implements SpreadsheetTypeHandler> { - private final CSVDataTargetConfig csvDataTargetConfig; + private final CSVTargetConfig csvDataTargetConfig; - public CollectionCSVWriter(CSVDataTargetConfig csvDataTargetConfig) { + public CollectionCSVWriter(CSVTargetConfig csvDataTargetConfig) { this.csvDataTargetConfig = csvDataTargetConfig; } diff --git a/zulia-data/src/main/java/io/zulia/data/target/spreadsheet/excel/ExcelDataTarget.java b/zulia-data/src/main/java/io/zulia/data/target/spreadsheet/excel/ExcelTarget.java similarity index 68% rename from zulia-data/src/main/java/io/zulia/data/target/spreadsheet/excel/ExcelDataTarget.java rename to zulia-data/src/main/java/io/zulia/data/target/spreadsheet/excel/ExcelTarget.java index a783df1c..beb51a4b 100644 --- a/zulia-data/src/main/java/io/zulia/data/target/spreadsheet/excel/ExcelDataTarget.java +++ b/zulia-data/src/main/java/io/zulia/data/target/spreadsheet/excel/ExcelTarget.java @@ -2,7 +2,7 @@ import io.zulia.data.output.DataOutputStream; import io.zulia.data.output.FileDataOutputStream; -import io.zulia.data.target.spreadsheet.SpreadsheetDataTarget; +import io.zulia.data.target.spreadsheet.SpreadsheetTarget; import io.zulia.data.target.spreadsheet.excel.cell.CellReference; import org.apache.poi.xssf.streaming.SXSSFCell; import org.apache.poi.xssf.streaming.SXSSFRow; @@ -14,9 +14,9 @@ import java.util.Collection; import java.util.List; -public class ExcelDataTarget extends SpreadsheetDataTarget { +public class ExcelTarget extends SpreadsheetTarget { - private final ExcelDataTargetConfig excelDataTargetConfig; + private final ExcelTargetConfig excelDataTargetConfig; private final SXSSFWorkbook workbook; private final WorkbookHelper workbookHelper; @@ -25,23 +25,23 @@ public class ExcelDataTarget extends SpreadsheetDataTarget headers) throws IOException { - return withConfig(ExcelDataTargetConfig.from(FileDataOutputStream.from(path, overwrite)).withHeaders(headers)); + public static ExcelTarget withDefaultsFromFile(String path, boolean overwrite, Collection headers) throws IOException { + return withConfig(ExcelTargetConfig.from(FileDataOutputStream.from(path, overwrite)).withHeaders(headers)); } - protected ExcelDataTarget(ExcelDataTargetConfig excelDataTargetConfig) throws IOException { + protected ExcelTarget(ExcelTargetConfig excelDataTargetConfig) throws IOException { super(excelDataTargetConfig); this.excelDataTargetConfig = excelDataTargetConfig; this.workbook = new SXSSFWorkbook(); diff --git a/zulia-data/src/main/java/io/zulia/data/target/spreadsheet/excel/ExcelDataTargetConfig.java b/zulia-data/src/main/java/io/zulia/data/target/spreadsheet/excel/ExcelTargetConfig.java similarity index 61% rename from zulia-data/src/main/java/io/zulia/data/target/spreadsheet/excel/ExcelDataTargetConfig.java rename to zulia-data/src/main/java/io/zulia/data/target/spreadsheet/excel/ExcelTargetConfig.java index 6daacf7e..9b300531 100644 --- a/zulia-data/src/main/java/io/zulia/data/target/spreadsheet/excel/ExcelDataTargetConfig.java +++ b/zulia-data/src/main/java/io/zulia/data/target/spreadsheet/excel/ExcelTargetConfig.java @@ -1,18 +1,18 @@ package io.zulia.data.target.spreadsheet.excel; import io.zulia.data.output.DataOutputStream; -import io.zulia.data.target.spreadsheet.SpreadsheetDataTargetConfig; +import io.zulia.data.target.spreadsheet.SpreadsheetTargetConfig; import io.zulia.data.target.spreadsheet.excel.cell.*; -public class ExcelDataTargetConfig extends SpreadsheetDataTargetConfig { +public class ExcelTargetConfig extends SpreadsheetTargetConfig { - public static ExcelDataTargetConfig from(DataOutputStream dataStream) { - return new ExcelDataTargetConfig(dataStream); + public static ExcelTargetConfig from(DataOutputStream dataStream) { + return new ExcelTargetConfig(dataStream); } private String primarySheetName; - private ExcelDataTargetConfig(DataOutputStream dataStream) { + private ExcelTargetConfig(DataOutputStream dataStream) { super(dataStream); withStringHandler(new StringCellHandler()); withDateTypeHandler(new DateCellHandler()); @@ -25,7 +25,7 @@ private ExcelDataTargetConfig(DataOutputStream dataStream) { } - public ExcelDataTargetConfig getSelf() { + public ExcelTargetConfig getSelf() { return this; } @@ -33,7 +33,7 @@ public String getPrimarySheetName() { return primarySheetName; } - public ExcelDataTargetConfig withPrimarySheetName(String primarySheetName) { + public ExcelTargetConfig withPrimarySheetName(String primarySheetName) { this.primarySheetName = primarySheetName; return this; } diff --git a/zulia-data/src/main/java/io/zulia/data/target/spreadsheet/excel/cell/CollectionCellHandler.java b/zulia-data/src/main/java/io/zulia/data/target/spreadsheet/excel/cell/CollectionCellHandler.java index 79228cb9..57f04a40 100644 --- a/zulia-data/src/main/java/io/zulia/data/target/spreadsheet/excel/cell/CollectionCellHandler.java +++ b/zulia-data/src/main/java/io/zulia/data/target/spreadsheet/excel/cell/CollectionCellHandler.java @@ -2,15 +2,15 @@ import io.zulia.data.source.spreadsheet.DelimitedListHandler; import io.zulia.data.target.spreadsheet.SpreadsheetTypeHandler; -import io.zulia.data.target.spreadsheet.excel.ExcelDataTargetConfig; +import io.zulia.data.target.spreadsheet.excel.ExcelTargetConfig; import java.util.Collection; public class CollectionCellHandler implements SpreadsheetTypeHandler> { - private final ExcelDataTargetConfig excelDataTargetConfig; + private final ExcelTargetConfig excelDataTargetConfig; - public CollectionCellHandler(ExcelDataTargetConfig excelDataTargetConfig) { + public CollectionCellHandler(ExcelTargetConfig excelDataTargetConfig) { this.excelDataTargetConfig = excelDataTargetConfig; } diff --git a/zulia-data/src/main/java/io/zulia/data/target/spreadsheet/excel/cell/DefaultCellHandler.java b/zulia-data/src/main/java/io/zulia/data/target/spreadsheet/excel/cell/DefaultCellHandler.java index 0bb41b62..54c01d87 100644 --- a/zulia-data/src/main/java/io/zulia/data/target/spreadsheet/excel/cell/DefaultCellHandler.java +++ b/zulia-data/src/main/java/io/zulia/data/target/spreadsheet/excel/cell/DefaultCellHandler.java @@ -1,13 +1,13 @@ package io.zulia.data.target.spreadsheet.excel.cell; import io.zulia.data.target.spreadsheet.SpreadsheetTypeHandler; -import io.zulia.data.target.spreadsheet.excel.ExcelDataTargetConfig; +import io.zulia.data.target.spreadsheet.excel.ExcelTargetConfig; public class DefaultCellHandler implements SpreadsheetTypeHandler { - private final ExcelDataTargetConfig excelDataTargetConfig; + private final ExcelTargetConfig excelDataTargetConfig; - public DefaultCellHandler(ExcelDataTargetConfig excelDataTargetConfig) { + public DefaultCellHandler(ExcelTargetConfig excelDataTargetConfig) { this.excelDataTargetConfig = excelDataTargetConfig; } diff --git a/zulia-data/src/test/java/io/zulia/data/test/DataSourceExamples.java b/zulia-data/src/test/java/io/zulia/data/test/DataSourceExamples.java index 63be498c..0bcad104 100644 --- a/zulia-data/src/test/java/io/zulia/data/test/DataSourceExamples.java +++ b/zulia-data/src/test/java/io/zulia/data/test/DataSourceExamples.java @@ -1,16 +1,16 @@ package io.zulia.data.test; import io.zulia.data.input.FileDataInputStream; -import io.zulia.data.source.spreadsheet.SpreadsheetDataSource; import io.zulia.data.source.spreadsheet.SpreadsheetRecord; +import io.zulia.data.source.spreadsheet.SpreadsheetSource; import io.zulia.data.source.spreadsheet.SpreadsheetSourceFactory; -import io.zulia.data.source.spreadsheet.csv.CSVDataSource; -import io.zulia.data.source.spreadsheet.csv.CSVDataSourceConfig; -import io.zulia.data.source.spreadsheet.csv.CSVDataSourceRecord; +import io.zulia.data.source.spreadsheet.csv.CSVRecord; +import io.zulia.data.source.spreadsheet.csv.CSVSource; +import io.zulia.data.source.spreadsheet.csv.CSVSourceConfig; import io.zulia.data.source.spreadsheet.excel.DefaultExcelCellHandler; -import io.zulia.data.source.spreadsheet.excel.ExcelDataSource; -import io.zulia.data.source.spreadsheet.excel.ExcelDataSourceConfig; -import io.zulia.data.source.spreadsheet.excel.ExcelDataSourceRecord; +import io.zulia.data.source.spreadsheet.excel.ExcelRecord; +import io.zulia.data.source.spreadsheet.excel.ExcelSource; +import io.zulia.data.source.spreadsheet.excel.ExcelSourceConfig; import org.apache.poi.ss.usermodel.Cell; import org.apache.poi.ss.usermodel.Row; @@ -24,7 +24,7 @@ public class DataSourceExamples { public void genericSpreadsheetHandling() throws IOException { FileDataInputStream dataInputStream = FileDataInputStream.from("/data/test.csv"); // xls, csv and tsv also supported by SpreadsheetSourceFactory - try (SpreadsheetDataSource dataSource = SpreadsheetSourceFactory.fromStreamWithHeaders(dataInputStream)) { //reads first line as headers + try (SpreadsheetSource dataSource = SpreadsheetSourceFactory.fromStreamWithHeaders(dataInputStream)) { //reads first line as headers // optionally do something with the headers but not required to use headers below SequencedSet headers = dataSource.getHeaders(); @@ -39,7 +39,7 @@ public void genericSpreadsheetHandling() throws IOException { } } - try (SpreadsheetDataSource dataSource = SpreadsheetSourceFactory.fromFileWithHeaders("/data/test.csv")) { // concise version of above + try (SpreadsheetSource dataSource = SpreadsheetSourceFactory.fromFileWithHeaders("/data/test.csv")) { // concise version of above // two (or more) passes are supported by the iterator @@ -60,32 +60,32 @@ public void manualConfigurationOfCSV() throws IOException { // manual configuration allows more flexibility than generic by more verbose FileDataInputStream dataInputStream = FileDataInputStream.from("/data/test.tsv"); - CSVDataSourceConfig csvDataSourceConfig = CSVDataSourceConfig.from(dataInputStream).withHeaders(); + CSVSourceConfig csvSourceConfig = CSVSourceConfig.from(dataInputStream).withHeaders(); //optionally configure these below - csvDataSourceConfig.withDelimiter('\t'); // set delimiter - csvDataSourceConfig.withListDelimiter(';'); // if reading a cell as a list, split on this, defaults to ; - csvDataSourceConfig.withDateParser(s -> { + csvSourceConfig.withDelimiter('\t'); // set delimiter + csvSourceConfig.withListDelimiter(';'); // if reading a cell as a list, split on this, defaults to ; + csvSourceConfig.withDateParser(s -> { // by default dates in format yyyy-mm-dd are supported; // implement specialized date parsing here return null; }); - csvDataSourceConfig.withBooleanParser(s -> { + csvSourceConfig.withBooleanParser(s -> { // by default true,t,1,yes,y,false,f,0,no,n are supported // implement specialized boolean parsing here return null; }); - try (CSVDataSource csvDataSource = CSVDataSource.withConfig(csvDataSourceConfig)) { - for (CSVDataSourceRecord csvDataSourceRecord : csvDataSource) { + try (CSVSource csvSource = CSVSource.withConfig(csvSourceConfig)) { + for (CSVRecord csvRecord : csvSource) { // Standard handling - String firstColumn = csvDataSourceRecord.getString(0); // access value in first column not relying on headers - String title = csvDataSourceRecord.getString("title"); // can access by header name because headers were read on open - Integer year = csvDataSourceRecord.getInt("year"); - Float rating = csvDataSourceRecord.getFloat("rating"); - Boolean recommended = csvDataSourceRecord.getBoolean("recommended"); - Date dateAdded = csvDataSourceRecord.getDate("dateAdded"); - List labels = csvDataSourceRecord.getList("labels", String.class); + String firstColumn = csvRecord.getString(0); // access value in first column not relying on headers + String title = csvRecord.getString("title"); // can access by header name because headers were read on open + Integer year = csvRecord.getInt("year"); + Float rating = csvRecord.getFloat("rating"); + Boolean recommended = csvRecord.getBoolean("recommended"); + Date dateAdded = csvRecord.getDate("dateAdded"); + List labels = csvRecord.getList("labels", String.class); // no special handling for CSV } @@ -94,12 +94,12 @@ public void manualConfigurationOfCSV() throws IOException { public void manualConfigurationWithExcel() throws IOException { FileDataInputStream dataInputStream = FileDataInputStream.from("/data/test.xlsx"); // xlsx and xls are supported; - ExcelDataSourceConfig excelDataSourceConfig = ExcelDataSourceConfig.from(dataInputStream).withHeaders(); + ExcelSourceConfig excelSourceConfig = ExcelSourceConfig.from(dataInputStream).withHeaders(); - excelDataSourceConfig.withListDelimiter(';'); + excelSourceConfig.withListDelimiter(';'); // default is DefaultExcelCellHandler but a complete custom implementation can be given or can override individual methods - excelDataSourceConfig.withExcelCellHandler(new DefaultExcelCellHandler() { + excelSourceConfig.withExcelCellHandler(new DefaultExcelCellHandler() { @Override public Boolean cellToBoolean(Cell cell) { // override boolean handling @@ -113,22 +113,22 @@ public Float cellToFloat(Cell cell) { } }); - try (ExcelDataSource dataSource = ExcelDataSource.withConfig(excelDataSourceConfig)) { + try (ExcelSource excelSource = ExcelSource.withConfig(excelSourceConfig)) { - for (ExcelDataSourceRecord excelDataSourceRecord : dataSource) { + for (ExcelRecord excelRecord : excelSource) { // Standard handling - String firstColumn = excelDataSourceRecord.getString(0); // access value in first column not relying on headers - String title = excelDataSourceRecord.getString("title"); // can access by header name because headers were read on open - Integer year = excelDataSourceRecord.getInt("year"); - Float rating = excelDataSourceRecord.getFloat("rating"); - Boolean recommended = excelDataSourceRecord.getBoolean("recommended"); - Date dateAdded = excelDataSourceRecord.getDate("dateAdded"); - List labels = excelDataSourceRecord.getList("labels", String.class); + String firstColumn = excelRecord.getString(0); // access value in first column not relying on headers + String title = excelRecord.getString("title"); // can access by header name because headers were read on open + Integer year = excelRecord.getInt("year"); + Float rating = excelRecord.getFloat("rating"); + Boolean recommended = excelRecord.getBoolean("recommended"); + Date dateAdded = excelRecord.getDate("dateAdded"); + List labels = excelRecord.getList("labels", String.class); //Excel specific - Row nativeRow = excelDataSourceRecord.getNativeRow(); - Cell titleCell = excelDataSourceRecord.getCell("title"); + Row nativeRow = excelRecord.getNativeRow(); + Cell titleCell = excelRecord.getCell("title"); } } diff --git a/zulia-data/src/test/java/io/zulia/data/test/DataTargetExamples.java b/zulia-data/src/test/java/io/zulia/data/test/DataTargetExamples.java index 30f52b01..d6dc5808 100644 --- a/zulia-data/src/test/java/io/zulia/data/test/DataTargetExamples.java +++ b/zulia-data/src/test/java/io/zulia/data/test/DataTargetExamples.java @@ -1,9 +1,9 @@ package io.zulia.data.test; -import io.zulia.data.target.spreadsheet.SpreadsheetDataTarget; +import io.zulia.data.target.spreadsheet.SpreadsheetTarget; import io.zulia.data.target.spreadsheet.SpreadsheetTargetFactory; -import io.zulia.data.target.spreadsheet.csv.CSVDataTarget; -import io.zulia.data.target.spreadsheet.excel.ExcelDataTarget; +import io.zulia.data.target.spreadsheet.csv.CSVTarget; +import io.zulia.data.target.spreadsheet.excel.ExcelTarget; import io.zulia.data.target.spreadsheet.excel.cell.Link; import java.io.IOException; @@ -16,40 +16,41 @@ public class DataTargetExamples { public static void main(String[] args) throws IOException { List headers = List.of("string column", "number", "decimal number", "boolean column", "list column", "link column", "some date"); - try (CSVDataTarget csvDataTarget = CSVDataTarget.withDefaultsFromFile("/data/test.csv", true, headers)) { - writeSampleRecords(csvDataTarget); + try (CSVTarget csvTarget = CSVTarget.withDefaultsFromFile("/data/test.csv", true, headers)) { + writeSampleRecords(csvTarget); } - try (ExcelDataTarget excelDataTarget = ExcelDataTarget.withDefaultsFromFile("/data/test.xlsx", true, headers)) { - writeSampleRecords(excelDataTarget); + try (ExcelTarget excelTarget = ExcelTarget.withDefaultsFromFile("/data/test.xlsx", true, headers)) { + writeSampleRecords(excelTarget); } - try (SpreadsheetDataTarget dataTarget = SpreadsheetTargetFactory.fromFile("/data/test2.xlsx", true)) { - writeSampleRecords(dataTarget); + try (SpreadsheetTarget spreadsheetTarget = SpreadsheetTargetFactory.fromFile("/data/test2.xlsx", true)) { + writeSampleRecords(spreadsheetTarget); } - try (SpreadsheetDataTarget dataTarget = SpreadsheetTargetFactory.fromFileWithHeaders("/data/test3.xlsx", true, List.of("header1", "header2"))) { - writeSampleRecords(dataTarget); + try (SpreadsheetTarget spreadsheetTarget = SpreadsheetTargetFactory.fromFileWithHeaders("/data/test3.xlsx", true, + List.of("header1", "header2"))) { + writeSampleRecords(spreadsheetTarget); } } - private static void writeSampleRecords(SpreadsheetDataTarget spreadsheetDataTarget) { - spreadsheetDataTarget.appendValue("some string"); - spreadsheetDataTarget.appendValue(132); - spreadsheetDataTarget.appendValue(10.332443f); - spreadsheetDataTarget.appendValue(true); - spreadsheetDataTarget.appendValue(List.of("a", "b", "c")); - spreadsheetDataTarget.appendValue(new Link("google", "https://www.google.com")); //label is ignored by CSV by default - spreadsheetDataTarget.appendValue(new Date()); - spreadsheetDataTarget.finishRow(); + private static void writeSampleRecords(SpreadsheetTarget spreadsheetTarget) { + spreadsheetTarget.appendValue("some string"); + spreadsheetTarget.appendValue(132); + spreadsheetTarget.appendValue(10.332443f); + spreadsheetTarget.appendValue(true); + spreadsheetTarget.appendValue(List.of("a", "b", "c")); + spreadsheetTarget.appendValue(new Link("google", "https://www.google.com")); //label is ignored by CSV by default + spreadsheetTarget.appendValue(new Date()); + spreadsheetTarget.finishRow(); - spreadsheetDataTarget.appendValue("another string"); - spreadsheetDataTarget.appendValue(4443232333L); - spreadsheetDataTarget.appendValue(10.33343432); - spreadsheetDataTarget.appendValue(false); - spreadsheetDataTarget.appendValue(Set.of("x", "y", "z")); - spreadsheetDataTarget.appendValue(new Link("yahoo", "https://www.yahoo.com")); //label is ignored by CSV by default - spreadsheetDataTarget.appendValue(new Date()); - spreadsheetDataTarget.finishRow(); + spreadsheetTarget.appendValue("another string"); + spreadsheetTarget.appendValue(4443232333L); + spreadsheetTarget.appendValue(10.33343432); + spreadsheetTarget.appendValue(false); + spreadsheetTarget.appendValue(Set.of("x", "y", "z")); + spreadsheetTarget.appendValue(new Link("yahoo", "https://www.yahoo.com")); //label is ignored by CSV by default + spreadsheetTarget.appendValue(new Date()); + spreadsheetTarget.finishRow(); } } diff --git a/zulia-tools/src/main/java/io/zulia/tools/cmd/ZuliaTest.java b/zulia-tools/src/main/java/io/zulia/tools/cmd/ZuliaTest.java index 4ff80ec4..521d298d 100644 --- a/zulia-tools/src/main/java/io/zulia/tools/cmd/ZuliaTest.java +++ b/zulia-tools/src/main/java/io/zulia/tools/cmd/ZuliaTest.java @@ -4,7 +4,7 @@ import io.zulia.cmd.common.ZuliaCommonCmd; import io.zulia.cmd.common.ZuliaVersionProvider; import io.zulia.data.output.FileDataOutputStream; -import io.zulia.data.target.spreadsheet.csv.CSVDataTarget; +import io.zulia.data.target.spreadsheet.csv.CSVTarget; import io.zulia.testing.ZuliaTestRunner; import io.zulia.testing.config.ZuliaTestConfig; import io.zulia.testing.result.TestResult; @@ -50,7 +50,7 @@ public Integer call() throws Exception { FileDataOutputStream dataOutputStream = FileDataOutputStream.from(testOutput, true); boolean anyFailed = false; - try (CSVDataTarget csvDataTarget = CSVDataTarget.withDefaults(dataOutputStream)) { + try (CSVTarget csvDataTarget = CSVTarget.withDefaults(dataOutputStream)) { for (TestResult testResult : testResults) { csvDataTarget.writeRow(testResult.getTestId(), testResult.isPassed() ? "PASS" : "FAIL"); if (!testResult.isPassed()) {