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

com.github.houbb.valid.jsr.constraint.PastConstraint Maven / Gradle / Ivy

There is a newer version: 0.3.0
Show newest version
package com.github.houbb.valid.jsr.constraint;

import com.github.houbb.heaven.annotation.ThreadSafe;
import com.github.houbb.valid.api.api.constraint.IConstraintContext;
import com.github.houbb.valid.core.api.constraint.AbstractCombineConstraint;
import com.github.houbb.valid.core.api.constraint.AbstractConstraint;
import com.github.houbb.valid.jsr.util.JsrSupportClassUtil;

import java.util.Calendar;
import java.util.Date;
import java.util.List;

/**
 * 判断当前时间,是否在过去
 *
 * @author binbin.hou
 * @since 0.0.3
 */
@ThreadSafe
class PastConstraint extends AbstractCombineConstraint {

    /**
     * 预期值
     * @since 0.0.3
     */
    private final Object expect;

    /**
     * 构造器
     * @param expect 预期值
     * @since 0.0.3
     */
    public PastConstraint(Object expect) {
        this.expect = expect;
    }

    @Override
    protected List getSupportClassList() {
        return JsrSupportClassUtil.getPastFutureSupportClassList();
    }

    @Override
    protected AbstractConstraint getConstraintInstance(IConstraintContext context) {
        final Object value = context.value();
        if(value instanceof Date) {
            Date exceptDate = (Date)expect;
            return new DatePastConstraint(exceptDate);
        }

        Calendar exceptCalendar = (Calendar)value;
        return new CalendarPastConstraint(exceptCalendar);
    }
    
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy