Compare two object approximately. - Android App

Android examples for App:APK Information

Description

Compare two object approximately.

Demo Code

/*//from   w  ww .j a  v  a  2s.c om
 * File: $RCSfile: ObjectUtilities.java,v $
 *
 * Copyright (c) 2009 Kewill,
 *
 * All Rights Reserved.
 *
 * This software is the confidential and proprietary information
 * of Kewill ("Confidential Information"). You shall not
 * disclose such Confidential Information and shall use it only in
 * accordance with the terms of the license agreement you entered
 * into with Kewill.
 */
//package com.java2s;

public class Main {
    /**
     * Compare two object approximately. If types of o1 and o2 are string, then
     * if o1 begin with o2, return false.
     *
     * @param o1 <code>java.lang.Object</code>
     * @param o2 <code>java.lang.Object</code>
     * @return boolean value denotes whether two objects are different.
     */
    public static boolean approxDifferent(Object o1, Object o2) {
        boolean isDifferent = false;
        if (o1 != null ^ o2 != null) {
            isDifferent = true;
        } else {
            if (o1 != null) {
                if (o1 instanceof String && o2 instanceof String) {
                    String s1 = ((String) o1).trim().toLowerCase();
                    String s2 = (((String) o2)).trim().toLowerCase();
                    if (!s1.startsWith(s2)) {
                        isDifferent = true;
                    }
                } else if (!o1.equals(o2)) {
                    isDifferent = true;
                }
            }
        }
        return isDifferent;
    }
}

Related Tutorials