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

org.joo.libra.logic.EqualsPredicate Maven / Gradle / Ivy

There is a newer version: 2.1.2
Show newest version
package org.joo.libra.logic;

import org.joo.libra.common.BinaryPredicate;
import org.joo.libra.common.HasValue;
import org.joo.libra.support.NumericComparator;

/**
 * Represents a 'equal' predicate. It is used to check if both objects are equal
 * to each other. If both object are Number, they will be converted
 * to {@link java.math.BigDecimal} before comparing, so 5,
 * 5.0 and 5L are equally. Otherwise they will be
 * compared using equals method.
 * 
 * @author griever
 *
 */
@SuppressWarnings("rawtypes")
public class EqualsPredicate extends BinaryPredicate {

	@SuppressWarnings("unchecked")
	public EqualsPredicate(final HasValue one, final HasValue other) {
		super(one, other);
	}

	@Override
	protected boolean doSatisifiedBy(final Object one, final Object other) {
		if (one instanceof Number && other instanceof Number) {
			return NumericComparator.compare((Number) one, (Number) other) == 0;
		}
		return one.equals(other);
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy