private static boolean groupTogether(Object key1, Object key2, int groupLevel) {
        if (groupLevel == 0 || !(key1 instanceof List) || !(key2 instanceof List)) {
            return key1.equals(key2);
        }
        @SuppressWarnings("unchecked")
        List<Object> key1List = (List<Object>) key1;
        @SuppressWarnings("unchecked")
        List<Object> key2List = (List<Object>) key2;

        // if either key list is smaller than groupLevel and the key lists are different
        // sizes, they cannot be equal.
        if ((key1List.size() < groupLevel || key2List.size() < groupLevel) &&
                key1List.size() != key2List.size()) {
            return false;
        }

        int end = Math.min(groupLevel, Math.min(key1List.size(), key2List.size()));
        for (int i = 0; i < end; ++i) {
            if (key1List.get(i) != null && !key1List.get(i).equals(key2List.get(i)))
                return false;
            else if (key1List.get(i) == null && key2List.get(i) != null)
                return false;
        }
        return true;
    }
private static boolean groupTogether ( Object key1 , Object key2 , int groupLevel ) { if ( groupLevel == 0 || ! ( key1 instanceof List ) || ! ( key2 instanceof List ) ) { return key1 . equals ( key2 ) ; } @ SuppressWarnings ( "unchecked" ) List < Object > key1List = ( List < Object > ) key1 ; @ SuppressWarnings ( "unchecked" ) List < Object > key2List = ( List < Object > ) key2 ; if ( ( key1List . size ( ) < groupLevel || key2List . size ( ) < groupLevel ) && key1List . size ( ) != key2List . size ( ) ) { return false ; } int end = Math . min ( groupLevel , Math . min ( key1List . size ( ) , key2List . size ( ) ) ) ; for ( int i = 0 ; i < end ; ++ i ) { if ( key1List . get ( i ) != null && ! key1List . get ( i ) . equals ( key2List . get ( i ) ) ) return false ; else if ( key1List . get ( i ) == null && key2List . get ( i ) != null ) return false ; } return true ; }
Are key1 and key2 grouped together at this groupLevel?