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

io.github.jinghui70.rainbow.dbaccess.Range Maven / Gradle / Ivy

There is a newer version: 5.2.11
Show newest version
package io.github.jinghui70.rainbow.dbaccess;

import cn.hutool.core.lang.Assert;

import java.util.Objects;

/**
 * 值范围对象,from为空表示无下限,to为空表示无上限。不能同时为空
 *
 * @param  值的泛型
 * @author lijinghui
 */
public class Range> {

    private T from;

    private T to;

    public Range() {
    }

    public static > Range of(T from, T to) {
        Range result = new Range<>();
        result.setFrom(from);
        result.setTo(to);
        result.regular();
        return result;
    }

    public T getFrom() {
        return from;
    }

    public void setFrom(T from) {
        this.from = from;
    }

    public T getTo() {
        return to;
    }

    public void setTo(T to) {
        this.to = to;
    }

    public void regular() {
        if (from == null) {
            Assert.notNull(to);
        } else {
            if (to != null && from.compareTo(to) > 0) {
                T mid = from;
                from = to;
                to = mid;
            }
        }
    }

    public boolean fullRange() {
        return from != null && to != null;
    }

    public boolean singleValue() {
        return Objects.equals(to, from);
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy