diff --git a/java/com.sap.sailing.domain.deckmanadapter.test/build.properties b/java/com.sap.sailing.domain.deckmanadapter.test/build.properties index 34d2e4d2dad..f11210d3f2c 100755 --- a/java/com.sap.sailing.domain.deckmanadapter.test/build.properties +++ b/java/com.sap.sailing.domain.deckmanadapter.test/build.properties @@ -1,4 +1,5 @@ -source.. = src/ +source.. = src/,\ + resources/ output.. = bin/ bin.includes = META-INF/,\ . diff --git a/java/com.sap.sailing.domain.deckmanadapter/src/com/sap/sailing/domain/deckmanadapter/impl/LogFile.java b/java/com.sap.sailing.domain.deckmanadapter/src/com/sap/sailing/domain/deckmanadapter/impl/LogFile.java new file mode 100755 index 00000000000..b07ee5d1495 --- /dev/null +++ b/java/com.sap.sailing.domain.deckmanadapter/src/com/sap/sailing/domain/deckmanadapter/impl/LogFile.java @@ -0,0 +1,64 @@ +package com.sap.sailing.domain.deckmanadapter.impl; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.Reader; +import java.text.ParseException; +import java.util.HashMap; +import java.util.Iterator; +import java.util.Map; + +/** + * A log file as produced by Deckman, in CSV format. The first line is expected to contain the column headers. + * Column headers not found in {@link FieldType} are ignored with a warning being logged. + * + * @author Axel Uhl (D043530) + * + */ +public class LogFile implements Iterator { + private final FieldType[] fieldTypes; + private final BufferedReader bufferedReader; + private String nextLine; + + /** + * Reads the header from the reader to initialize {@link #fieldTypes}. Afterwards, using the {@link #iterator}, + * the records can be read one by one. + */ + public LogFile(Reader r) throws IOException { + bufferedReader = new BufferedReader(r); + String header = bufferedReader.readLine(); + String[] fieldNames = header.split(","); + fieldTypes = new FieldType[fieldNames.length]; + for (int i=0; i fieldsAsStrings = new HashMap<>(); + final String[] fieldValues = nextLine.split(","); + try { + nextLine = bufferedReader.readLine(); + for (int i = 0; i < fieldValues.length; i++) { + fieldsAsStrings.put(fieldTypes[i], fieldValues[i]); + } + final Record result = new Record(fieldsAsStrings); + return result; + } catch (ParseException | IOException e) { + throw new RuntimeException(e); + } + } + + @Override + public void remove() { + throw new UnsupportedOperationException("remove() is not supported on a Deckman log file"); + } + +}