use of org.knime.timeseries.node.extract.AbstractTimeExtractorStringCellFactory in project knime-core by knime.
the class DateFieldExtractorNodeModel method createColumnRearranger.
private SingleCellFactoryCompound createColumnRearranger(final DataTableSpec inSpec) {
final int colIdx = inSpec.findColumnIndex(m_selectedColumn.getStringValue());
ColumnRearranger rearranger = new ColumnRearranger(inSpec);
List<AbstractTimeExtractorCellFactory> cellFactories = new ArrayList<AbstractTimeExtractorCellFactory>();
// year
if (m_useYear.getBooleanValue()) {
String colName = DataTableSpec.getUniqueColumnName(inSpec, m_yearColName.getStringValue());
AbstractTimeExtractorCellFactory yearFactory = new AbstractTimeExtractorIntCellFactory(colName, colIdx, false) {
@Override
protected int extractTimeField(final DateAndTimeValue value) {
return value.getYear();
}
};
rearranger.append(yearFactory);
cellFactories.add(yearFactory);
}
// quarter
if (m_useQuarter.getBooleanValue()) {
String colName = DataTableSpec.getUniqueColumnName(inSpec, m_quarterColName.getStringValue());
AbstractTimeExtractorCellFactory quarterFactory = new AbstractTimeExtractorIntCellFactory(colName, colIdx, false) {
@Override
protected int extractTimeField(final DateAndTimeValue value) {
int month = value.getMonth();
// hence we add 1
return month / 3 + 1;
}
};
rearranger.append(quarterFactory);
cellFactories.add(quarterFactory);
}
// month
AbstractTimeExtractorCellFactory monthFactory = null;
if (m_useMonth.getBooleanValue()) {
String colName = DataTableSpec.getUniqueColumnName(inSpec, m_monthColName.getStringValue());
if (m_monthRepresentation.getStringValue().equals(AbstractFieldExtractorNodeDialog.AS_INT)) {
monthFactory = new AbstractTimeExtractorIntCellFactory(colName, colIdx, false) {
@Override
protected int extractTimeField(final DateAndTimeValue value) {
// to java.util.Calendar#MONTH
return value.getMonth() + 1;
}
};
} else {
// extract the display name of the month
monthFactory = new AbstractTimeExtractorStringCellFactory(colName, colIdx, false) {
@Override
protected String extractTimeField(final DateAndTimeValue value) {
return value.getUTCCalendarClone().getDisplayName(Calendar.MONTH, Calendar.LONG, Locale.getDefault());
}
};
}
rearranger.append(monthFactory);
cellFactories.add(monthFactory);
}
// day of month
if (m_useDay.getBooleanValue()) {
String colName = DataTableSpec.getUniqueColumnName(inSpec, m_dayColName.getStringValue());
AbstractTimeExtractorCellFactory dayFactory = new AbstractTimeExtractorIntCellFactory(colName, colIdx, false) {
@Override
protected int extractTimeField(final DateAndTimeValue value) {
return value.getDayOfMonth();
}
};
rearranger.append(dayFactory);
cellFactories.add(dayFactory);
}
// day of week
AbstractTimeExtractorCellFactory dayOfWeekFactory = null;
if (m_useDayOfWeek.getBooleanValue()) {
String colName = DataTableSpec.getUniqueColumnName(inSpec, m_dayOfWeekColName.getStringValue());
if (m_dayOfWeekRepresentationModel.getStringValue().equals(AbstractFieldExtractorNodeDialog.AS_INT)) {
dayOfWeekFactory = new AbstractTimeExtractorIntCellFactory(colName, colIdx, false) {
@Override
protected int extractTimeField(final DateAndTimeValue value) {
return value.getUTCCalendarClone().get(Calendar.DAY_OF_WEEK);
}
};
} else {
dayOfWeekFactory = new AbstractTimeExtractorStringCellFactory(colName, colIdx, false) {
@Override
protected String extractTimeField(final DateAndTimeValue value) {
return value.getUTCCalendarClone().getDisplayName(Calendar.DAY_OF_WEEK, Calendar.LONG, Locale.getDefault());
}
};
// extract the display name of the day of week
}
rearranger.append(dayOfWeekFactory);
cellFactories.add(dayOfWeekFactory);
}
// day of year
if (m_useDayOfYear.getBooleanValue()) {
String colName = DataTableSpec.getUniqueColumnName(inSpec, m_dayOfYearColName.getStringValue());
AbstractTimeExtractorCellFactory dayofYearFactory = new AbstractTimeExtractorIntCellFactory(colName, colIdx, false) {
@Override
protected int extractTimeField(final DateAndTimeValue value) {
return value.getUTCCalendarClone().get(Calendar.DAY_OF_YEAR);
}
};
rearranger.append(dayofYearFactory);
cellFactories.add(dayofYearFactory);
}
// week of year
if (m_useWeekOfYear.getBooleanValue()) {
String colName = DataTableSpec.getUniqueColumnName(inSpec, m_weekOfYearColName.getStringValue());
AbstractTimeExtractorCellFactory weekofYearFactory = new AbstractTimeExtractorIntCellFactory(colName, colIdx, false) {
@Override
protected int extractTimeField(final DateAndTimeValue value) {
return value.getUTCCalendarClone().get(Calendar.WEEK_OF_YEAR);
}
};
rearranger.append(weekofYearFactory);
cellFactories.add(weekofYearFactory);
}
return new SingleCellFactoryCompound(rearranger, cellFactories);
}
Aggregations