/*
 * StringDiffer.java
 *
 * Created on May 24, 2006, 2:50 PM
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package usda.weru.util.diff.differs;

import usda.weru.util.diff.*;

/**
 *
 * @author Joseph Levin
 */
public class NumberDiffer extends ObjectDiffer{

	/**
	 *
	 * @param a
	 * @param b
	 * @return
	 * @throws IncomparableObjectsException
	 */
	@Override
    public int diff(Object a, Object b) throws IncomparableObjectsException{
        test(Number.class, a, b);
        return diff((Number) a, (Number) b);                
    }

	/**
	 *
	 * @param a
	 * @param b
	 * @return
	 */
	public static int diff(Number a, Number b){           
        if (a == null && b == null) return DIFF_SAME;
        else if (a == null) return DIFF_ADDED;
        else if (b == null) return DIFF_REMOVED;
        else if (a.floatValue() == b.floatValue()) return DIFF_SAME;
        else if (a.floatValue() > b.floatValue()) return DIFF_DECREASED;
        else if (a.floatValue() < b.floatValue()) return DIFF_INCREASED;
        else return DIFF_CHANGED;
    }
}
