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

io.corbel.lib.queries.NumericQueryLiteral Maven / Gradle / Ivy

There is a newer version: 0.16.0
Show newest version
package io.corbel.lib.queries;

import io.corbel.lib.queries.exception.QueryMatchingException;
import io.corbel.lib.queries.request.QueryLiteral;

import java.math.BigDecimal;

public class NumericQueryLiteral extends QueryLiteral {

    public NumericQueryLiteral() {
        super();
    }

    public NumericQueryLiteral(T literal) {
        super(literal);
    }

    @Override
    protected boolean eq(Object object) throws QueryMatchingException {
        return compare(object) == 0;
    }

    @Override
    protected boolean ne(Object object) throws QueryMatchingException {
        return compare(object) != 0;
    }

    @Override
    protected boolean gt(Object object) throws QueryMatchingException {
        return compare(object) == 1;
    }

    @Override
    protected boolean gte(Object object) throws QueryMatchingException {
        int result = compare(object);
        return result == 1 || result == 0;
    }

    @Override
    protected boolean lt(Object object) throws QueryMatchingException {
        return compare(object) == -1;
    }

    @Override
    protected boolean lte(Object object) throws QueryMatchingException {
        int result = compare(object);
        return result == -1 || result == 0;
    }

    protected int compare(Object object) {
        return new BigDecimal(object.toString()).compareTo(new BigDecimal(literal.toString()));
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy