All Downloads are FREE. Search and download functionalities are using the official Maven repository.

dev.vality.fraudo.payment.resolver.PaymentTimeWindowResolver Maven / Gradle / Ivy

There is a newer version: 1.0.7
Show newest version
package dev.vality.fraudo.payment.resolver;

import dev.vality.fraudo.FraudoPaymentParser;
import dev.vality.fraudo.model.TimeWindow;
import dev.vality.fraudo.resolver.TimeWindowResolver;
import dev.vality.fraudo.utils.TextUtil;
import org.antlr.v4.runtime.tree.TerminalNode;

import java.util.List;
import java.util.Objects;

import static dev.vality.fraudo.constant.TimeUnit.HOURS;


public class PaymentTimeWindowResolver implements TimeWindowResolver {

    @Override
    public TimeWindow resolve(FraudoPaymentParser.Time_windowContext ctx) {
        TimeWindow.TimeWindowBuilder builder = TimeWindow.builder();
        List times = ctx.INTEGER();
        String start = TextUtil.safeGetText(times.get(0));
        builder
                .start(Integer.parseInt(start))
                .timeUnit(HOURS);
        if (times.size() == 2) {
            String end = TextUtil.safeGetText(times.get(1));
            builder
                    .end(Integer.parseInt(end));
        }
        if (Objects.nonNull(ctx.time_unit())) {
            String timeUnit = ctx.time_unit().getText();
            builder
                    .timeUnit(timeUnit);
        }
        return builder.build();
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy