Example usage for java.lang Object equals

List of usage examples for java.lang Object equals

Introduction

In this page you can find the example usage for java.lang Object equals.

Prototype

public boolean equals(Object obj) 

Source Link

Document

Indicates whether some other object is "equal to" this one.

Usage

From source file:Main.java

private static boolean match(String methodName, Object o, Object... fieldNamesAndExpectedValues) {
    boolean matches = true;

    for (int i = 0; matches && i < fieldNamesAndExpectedValues.length; i += 2) {
        String fieldName = (String) fieldNamesAndExpectedValues[i];
        Object expectedValue = fieldNamesAndExpectedValues[i + 1];
        Object actualValue = getValue(o, fieldName);
        if (expectedValue == null) {
            matches = (actualValue == null);
        } else {/*from w  w w  .  java2s  .c o  m*/
            matches = actualValue != null && actualValue.equals(expectedValue);
        }
    }

    if (!matches) {
        println("LearnTestUtils." + methodName + "(...).new ArgumentMatcher() {...}.matches()");
        println(1, "<fieldName>: <actualValue> vs <expectedValue>");
        for (int i = 0; i < fieldNamesAndExpectedValues.length; i += 2) {
            String fieldName = (String) fieldNamesAndExpectedValues[i];
            Object expectedValue = fieldNamesAndExpectedValues[i + 1];
            println(o, fieldName, expectedValue);
        }
    }

    return matches;
}

From source file:Main.java

public static boolean containsAttribute(Element element, Object name, Object value) {
    if (element == null) {
        return false;
    }/*from w  w w  .j av a 2 s.c om*/

    Object attribute = element.getAttributes().getAttribute(name);

    if (attribute == null) {
        return containsAttribute(element.getParentElement(), name, value);
    }
    return value.equals(attribute.toString());
}

From source file:org.codehaus.groovy.grails.plugins.searchable.compass.mapping.SearchableGrailsDomainClassCompassMappingUtils.java

/**
 * Is the given GrailsDomainClass a root class in the Compass mapping?
 * @param grailsDomainClass the domain class to check for
 * @param searchableGrailsDomainClasses a collection of searchable GrailsDomainClass instances
 * @return true unless it's an embedded class in another domain class without explicit searchable declaration
 *///from w  w w.  ja v a 2s.  co m
public static boolean isRoot(GrailsDomainClass grailsDomainClass, Collection searchableGrailsDomainClasses) {
    // TODO log warning when used as both component and non-component
    Object value = SearchableUtils.getSearchablePropertyValue(grailsDomainClass);
    if (value instanceof Boolean) {
        return value.equals(Boolean.TRUE);
    }
    if (value == null) {
        return !SearchableUtils.isEmbeddedPropertyOfOtherDomainClass(grailsDomainClass,
                searchableGrailsDomainClasses);
    }
    return true;
}

From source file:Main.java

public static boolean equals(Collection<?> collection1, Collection<?> collection2) {
    if (collection1 == collection2) {
        return true;
    }/*from w  w  w .j a  v  a  2  s.c om*/

    if (collection1.size() != collection2.size()) {
        return false;
    }

    final Iterator<?> iterator1 = collection1.iterator();
    final Iterator<?> iterator2 = collection2.iterator();

    while (iterator1.hasNext()) {
        final Object object1 = iterator1.next();
        final Object object2 = iterator2.next();

        if ((object1 == null && object2 != null) || (object1 != null && object2 == null)) {
            return false;
        }

        if (object1 != null && !object1.equals(object2)) {
            return false;
        }
    }

    return true;
}

From source file:Main.java

public static boolean contains(final Object[] array, final Object... values) {
    if (array == null || values == null)
        return false;
    for (final Object item : array) {
        for (final Object value : values) {
            if (item == null || value == null) {
                if (item == value)
                    return true;
                continue;
            }/*from w w w  .j a v  a2  s.c o m*/
            if (item.equals(value))
                return true;
        }
    }
    return false;
}

From source file:com.hueemulator.lighting.utils.TestUtils.java

/**
 * Tests two JSON strings for equality by performing a deep comparison.
 *
 * @param json1 represents a JSON object to compare with json2
 * @param json2 represents a JSON object to compare with json1
 * @return true if the JSON objects are equal, false otherwise
 *///  www  .  ja v a  2 s  .co  m
public static boolean jsonsArrayEqual(String json1, String json2) throws Exception {
    Object obj1Converted = convertJsonElement(new JSONArray(json1));
    Object obj2Converted = convertJsonElement(new JSONArray(json2));
    return obj1Converted.equals(obj2Converted);
}

From source file:com.hueemulator.lighting.utils.TestUtils.java

/**
 * Tests two JSON strings for equality by performing a deep comparison.
 *
 * @param json1 represents a JSON object to compare with json2
 * @param json2 represents a JSON object to compare with json1
 * @return true if the JSON objects are equal, false otherwise
 *///from ww w .j a  v  a  2 s .  c o  m
public static boolean jsonsEqual(String json1, String json2) throws Exception {
    Object obj1Converted = convertJsonElement(new JSONObject(json1));
    Object obj2Converted = convertJsonElement(new JSONObject(json2));
    return obj1Converted.equals(obj2Converted);
}

From source file:org.codehaus.groovy.grails.plugins.searchable.SearchableUtils.java

/**
 * Should the named property be included in the mapping, according to the value of "searchable"?
 * @param propertyName// w ww .j  a v  a2 s . co m
 * @param searchable
 * @return true if included
 */
public static boolean isIncludedProperty(String propertyName, Object searchable) {
    if (searchable == null || (searchable instanceof Boolean && searchable.equals(Boolean.TRUE))) {
        return true;
    }
    if (!(searchable instanceof Map)) {
        return false;
    }
    Object only = ((Map) searchable).get(ONLY);
    if (only != null) {
        return isOrContains(propertyName, only);
    }
    return !isOrContains(propertyName, ((Map) searchable).get(EXCEPT));
}

From source file:org.killbill.billing.plugin.meter.timeline.samples.ScalarSample.java

public static boolean sameSampleValues(final Object o1, final Object o2) {
    if (o1 == o2) {
        return true;
    } else if (o1.getClass() == o2.getClass()) {
        return o1.equals(o2);
    } else {/*from   ww  w.  j a  v  a2  s . c  o  m*/
        return false;
    }
}

From source file:mml.handler.json.Dialect.java

private static boolean compareObjects(JSONObject o1, JSONObject o2) {
    boolean res = true;
    Set<String> keys = o1.keySet();
    Iterator<String> iter = keys.iterator();
    while (iter.hasNext() && res) {
        String key = iter.next();
        Object obj1 = o1.get(key);
        Object obj2 = o2.get(key);
        if (obj1 != null && obj2 != null && obj1.getClass().equals(obj2.getClass())) {
            if (obj1 instanceof String)
                res = obj1.equals(obj2);
            else if (obj1 instanceof Number)
                return obj1.equals(obj2);
            else if (obj1 instanceof JSONArray)
                res = compareArrays((JSONArray) obj1, (JSONArray) obj2);
            else if (obj1 instanceof JSONObject)
                res = compareObjects((JSONObject) obj1, (JSONObject) obj2);
            else if (obj1 instanceof Boolean)
                res = obj1.equals(obj2);
            else//  ww w  .  j a v  a  2s .com
                res = false;
        } else
            res = false;
    }
    return res;
}