Add Instant support to Row
@@ -2,6 +2,7 @@ package tech.tablesaw.api;
import tech.tablesaw.columns.Column;
+import java.time.Instant;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
@@ -23,6 +24,7 @@ public class Row implements Iterator<Row> {
private final Map<String, Column<String>> stringColumnMap = new TreeMap<>(String.CASE_INSENSITIVE_ORDER);
private final Map<String, BooleanColumn> booleanColumnMap = new TreeMap<>(String.CASE_INSENSITIVE_ORDER);
private final Map<String, DateTimeColumn> dateTimeColumnMap = new TreeMap<>(String.CASE_INSENSITIVE_ORDER);
+ private final Map<String, InstantColumn> instantColumnMap = new TreeMap<>(String.CASE_INSENSITIVE_ORDER);
private final Map<String, TimeColumn> timeColumnMap = new TreeMap<>(String.CASE_INSENSITIVE_ORDER);
private final Map<String, Column<?>> columnMap = new TreeMap<>(String.CASE_INSENSITIVE_ORDER);
private int rowNumber;
@@ -62,6 +64,9 @@ public class Row implements Iterator<Row> {
} else if (column instanceof DateTimeColumn) {
dateTimeColumnMap.put(column.name(), (DateTimeColumn) column);
+ } else if (column instanceof InstantColumn) {
+ instantColumnMap.put(column.name(), (InstantColumn) column);
+
} else if (column instanceof TimeColumn) {
timeColumnMap.put(column.name(), (TimeColumn) column);
}
@@ -108,6 +113,14 @@ public class Row implements Iterator<Row> {
return ((DateTimeColumn) columnMap.get(columnName)).get(rowNumber);
}
+ public Instant getInstant(int columnIndex) {
+ return getInstant(columnNames[columnIndex]);
+ }
+
+ public Instant getInstant(String columnName) {
+ return ((InstantColumn) columnMap.get(columnName)).get(rowNumber);
+ }
+
public double getDouble(int columnIndex) {
return getDouble(columnNames[columnIndex]);
}
@@ -243,6 +256,14 @@ public class Row implements Iterator<Row> {
dateTimeColumnMap.get(columnName).set(rowNumber, value);
}
+ public void setInstant(int columnIndex, Instant value) {
+ setInstant(columnNames[columnIndex], value);
+ }
+
+ public void setInstant(String columnName, Instant value) {
+ instantColumnMap.get(columnName).set(rowNumber, value);
+ }
+
public void setDouble(int columnIndex, double value) {
setDouble(columnNames[columnIndex], value);
}
