I am using a Map to read the rows from a spreadsheet and store its contents in the following way:
public class DocumentRow {
private Map<Column, DocumentCell<?>> rowContents = new HashMap<>();
private int rowNum;
public DocumentCell<?> getValue(Column column) {
return rowContents.get(column);
}
public void setValue(Column column, DocumentCell<?> value) {
rowContents.put(column, value);
}
public DigitalDocument toDomainObject() {
DomainObject domainObject = new DomainObject();
domainObject.setTextValue((String) rowContents.get(TEXT_VALUE).getValue());
domainObject.setNumericValue((int) rowContents.get(NUMERIC_VALUE).getValue());
domainObject.setDateValue((LocalDate) rowContents.get(DATE_VALUE).getValue());
return domainObject;
}
}
public class DocumentCell<T> {
private T value;
}
public enum Column {
TEXT_VALUE("Text_Column_Name", DataType.STRING),
NUMERIC_VALUE("Numeric_Column_Name", DataType.NUMBER),
DATE_VALUE("Date_Column_Name", DataType.DATE);
}
(I have ommited some obvious classes for the sake of brevity)
The row values are provided as:
row.setValue(column, new DocumentCell<>(getDateCellValue(spreadSheetCell)));
Is there way this could be made cleaner so that I don't require these unchecked casts while constructing the domain object? Or a better way to design this?