Example usage for java.time.temporal TemporalUnit toString

List of usage examples for java.time.temporal TemporalUnit toString

Introduction

In this page you can find the example usage for java.time.temporal TemporalUnit toString.

Prototype

@Override
String toString();

Source Link

Document

Gets a descriptive name for the unit.

Usage

From source file:org.talend.dataprep.transformation.actions.date.ComputeTimeSince.java

@Override
public void compile(ActionContext context) {
    super.compile(context);
    if (context.getActionStatus() == ActionContext.ActionStatus.OK) {
        // Create new column
        Map<String, String> parameters = context.getParameters();
        String columnId = context.getColumnId();
        TemporalUnit unit = ChronoUnit.valueOf(parameters.get(TIME_UNIT_PARAMETER).toUpperCase());
        ColumnMetadata column = context.getRowMetadata().getById(columnId);
        context.column("result", r -> {
            final ColumnMetadata c = ColumnMetadata.Builder //
                    .column() //
                    .copy(column)//
                    .computedId(StringUtils.EMPTY) //
                    .name(PREFIX + column.getName() + SUFFIX + unit.toString().toLowerCase()) //
                    .computedId(null) // remove the id
                    .statistics(new Statistics()) // clear the statistics
                    .type(INTEGER)//
                    .build();//  ww  w  . java 2  s  .com
            context.getRowMetadata().insertAfter(columnId, c);
            return c;
        });
        context.get(SINCE_WHEN_PARAMETER,
                m -> parameters.containsKey(SINCE_WHEN_PARAMETER) ? parameters.get(SINCE_WHEN_PARAMETER)
                        : NOW_SERVER_SIDE_MODE);
        context.get(SINCE_DATE_PARAMETER, m -> parseSinceDateIfConstant(parameters));
    }
}