class KeyIndexesBuilder extends AbstractDataBuilder {

    private Collection<Integer> getKeyIndexes(final Method targetMethod, final boolean isMulti) {
        final Annotation[][] paramAnnotationArrays = targetMethod.getParameterAnnotations();
        final SortedMap<ParameterValueKeyProvider, Integer> keyProviders = new TreeMap<ParameterValueKeyProvider, Integer>(COMPARATOR);
        final Set<Integer> order = new HashSet<Integer>();

        if (paramAnnotationArrays == null || paramAnnotationArrays.length < 1) {
            return Collections.emptyList();
        }

        for (int ix = 0; ix < paramAnnotationArrays.length; ix++) {
            final ParameterValueKeyProvider keyProviderAnnotation = getAnnotation(ParameterValueKeyProvider.class,
                    paramAnnotationArrays[ix]);
            if (keyProviderAnnotation == null) {
                continue;
            }

            // throw if order below 0
            if (keyProviderAnnotation.order() < 0) {
                throw new InvalidParameterException(String.format(
                        "No valid order [%d] defined in annotation [%s] on method [%s], only no negative integers are allowed.",
                        keyProviderAnnotation.order(), ParameterValueKeyProvider.class.getName(), targetMethod.getName()));
            }
            // throw exception if there are two annotations with the same value of order
            if (!order.add(keyProviderAnnotation.order())) {
                throwException(
                        "No valid order defined in annotation [%s] on method [%s]. There are two annotations with the same order.",
                        ParameterValueKeyProvider.class, targetMethod);
            }
            // log warn if for non multi annotation one of Collection parameter is annotated as a ParameterValueKeyProvider
            if (!isMulti && Collection.class.isAssignableFrom(targetMethod.getParameterTypes()[ix])) {
                LOG.warn("ParameterValueKeyProvider is used on a list parameter {} in method {} with non multi cache annotation."
                        + "Consider changing to *MultiCache annotation or use another parameter for key. Using collections in such case "
                        + "may lead to unexpected consequences: key can exceed allowed memcached key length, key will be varied "
                        + "when order or size are changed." , targetMethod.getParameterTypes()[ix], targetMethod.getName());
            }

            keyProviders.put(keyProviderAnnotation, ix);
        }

        return keyProviders.values();
    }

}