Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 package com.fasterxml.jackson.databind.util;
Helper class for constructing objects for comparing content values
 public class Comparators
Helper method used for constructing simple value comparator used for comparing arrays for content equality.

Note: current implementation is not optimized for speed; if performance ever becomes an issue, it is possible to construct much more efficient typed instances (one for Object[] and sub-types; one per primitive type).

    public static Object getArrayComparator(final Object defaultValue)
        final int length = Array.getLength(defaultValue);
        return new Object() {
            public boolean equals(Object other) {
                if (other == thisreturn true;
                if (other == null || other.getClass() != defaultValue.getClass()) {
                    return false;
                if (Array.getLength(other) != lengthreturn false;
                // so far so good: compare actual equality; but only shallow one
                for (int i = 0; i < length; ++i) {
                    Object value1 = Array.get(defaultValuei);
                    Object value2 = Array.get(otheri);
                    if (value1 == value2continue;
                    if (value1 != null) {
                        if (!value1.equals(value2)) {
                            return false;
                return true;
New to GrepCode? Check out our FAQ X