/*
 * 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 StringDiffer extends ObjectDiffer{

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

	/**
	 *
	 * @param a
	 * @param b
	 * @return
	 */
	public static int diff(String a, String b){
        if (a == null || a.length() == 0) a = null;
        if (b == null || b.length() == 0) b = null;
              
        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.equals(b)) return DIFF_SAME;
        else return DIFF_CHANGED;
    }
}
