public double bestEqual(String string, Object patterns, boolean equality) {
        String[] array;
        double value = Double.POSITIVE_INFINITY;
        
        if (patterns instanceof String[]) {
            array = (String[]) patterns;
        } else if (patterns instanceof Collection) {
            Collection<?> c = (Collection<?>) patterns; 
            array = c.toArray(new String[c.size()]);
        } else {
            throw new IllegalArgumentException();
        } // else
        
        resultIndex = -1;
        
        for (int i = 0; i < array.length; i++) {
            double cur = equality ? similarity(string, array[i]) : containability(string, array[i]);
            if (cur < value) {
                value = cur;
                resultIndex = i;
                matchedPattern = array[i];
            } // if
        } // for
        
        return value;
    } // bestEqual