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

com.github.rutledgepaulv.qbuilders.delegates.virtual.InstantLikePropertyDelegate Maven / Gradle / Ivy

package com.github.rutledgepaulv.qbuilders.delegates.virtual;

import com.github.rutledgepaulv.qbuilders.builders.QBuilder;
import com.github.rutledgepaulv.qbuilders.conditions.Condition;
import com.github.rutledgepaulv.qbuilders.operators.ComparisonOperator;
import com.github.rutledgepaulv.qbuilders.properties.virtual.InstantLikeProperty;
import com.github.rutledgepaulv.qbuilders.structures.FieldPath;

import java.time.Instant;
import java.util.Collections;

@SuppressWarnings("unchecked")
public abstract class InstantLikePropertyDelegate, S>
        extends EquitablePropertyDelegate implements InstantLikeProperty {

    public InstantLikePropertyDelegate(FieldPath field, T canonical) {
        super(field, canonical);
    }

    @Override
    public final Condition before(S dateTime, boolean exclusive) {
        return condition(getField(), exclusive ? ComparisonOperator.LT : ComparisonOperator.LTE,
                Collections.singletonList(normalize(dateTime)));
    }

    @Override
    public final Condition after(S dateTime, boolean exclusive) {
        return condition(getField(), exclusive ? ComparisonOperator.GT : ComparisonOperator.GTE,
                Collections.singletonList(normalize(dateTime)));
    }

    @Override
    public final Condition between(S after, boolean exclusiveAfter, S before, boolean exclusiveBefore) {
        Condition afterCondition = new QBuilder().instant(getField().asKey()).after(after, exclusiveAfter);
        Condition beforeCondition = new QBuilder().instant(getField().asKey()).before(before, exclusiveBefore);
        return and(afterCondition, beforeCondition);
    }

    protected abstract Instant normalize(S dateTime);

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy