@Test public void shouldNotPopulateIfExpectedAnnotationNotRequireKeyProvider() throws Exception { final Class<? extends Annotation> expected = InvalidateAssignCache.class; final Method targetMethod = null; builder.populate(data, null, expected, targetMethod); assertTrue(data.getKeyIndexes().isEmpty()); assertFalse(data.isReturnKeyIndex()); }
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; } 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())); } 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); } 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(); }
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; } 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())); } 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); } 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(); } }
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; } 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())); } 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); } 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(); }  }
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; } 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())); } 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); } 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(); }   }
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; } 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())); } 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); } 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(); }    }