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

com.bq.oss.lib.queries.NumericQueryLiteral Maven / Gradle / Ivy

package com.bq.oss.lib.queries;

import java.math.BigDecimal;

import com.bq.oss.lib.queries.exception.QueryMatchingException;
import com.bq.oss.lib.queries.request.QueryLiteral;

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;
	};

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




© 2015 - 2025 Weber Informatics LLC | Privacy Policy