public int compare()

in cassandra-analytics-common/src/main/java/org/apache/cassandra/spark/utils/ComparisonUtils.java [47:92]


        public int compare(Object first, Object second)
        {
            if (first instanceof Comparable && second instanceof Comparable)
            {
                return ((Comparable) first).compareTo(second);
            }
            else if (first instanceof Object[] && second instanceof Object[])
            {
                Object[] array1 = (Object[]) first;
                Object[] array2 = (Object[]) second;
                int position = 0;
                while (position < array1.length && position < array2.length)
                {
                    int comparison = NESTED_COMPARATOR.compare(array1[position], array2[position]);
                    if (comparison != 0)
                    {
                        return comparison;
                    }
                    position++;
                }
                return Integer.compare(array1.length, array2.length);
            }
            else if (first instanceof Map && second instanceof Map)
            {
                Map<?, ?> map1 = (Map<?, ?>) first;
                Map<?, ?> map2 = (Map<?, ?>) second;
                for (Object key : map1.keySet())
                {
                    int comparison = NESTED_COMPARATOR.compare(map1.get(key), map2.get(key));
                    if (comparison != 0)
                    {
                        return comparison;
                    }
                }
                return Integer.compare(map1.size(), map2.size());
            }
            else if (first instanceof Collection && second instanceof Collection)
            {
                return NESTED_COMPARATOR.compare(((Collection) first).toArray(new Object[0]), ((Collection) second).toArray(new Object[0]));
            }
            else if (first instanceof Inet4Address && second instanceof Inet4Address)
            {
                return INET_COMPARATOR.compare(first, second);
            }
            throw new IllegalStateException("Unexpected comparable type: " + first.getClass().getName());
        }