From 06306f91499db610fdef12bbd4ecd7790f5b9370 Mon Sep 17 00:00:00 2001 From: Chris Beams Date: Wed, 16 Nov 2011 04:20:53 +0000 Subject: [PATCH] Extract various constants in DefaultKeyGenerator --- .../cache/interceptor/DefaultKeyGenerator.java | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/org.springframework.context/src/main/java/org/springframework/cache/interceptor/DefaultKeyGenerator.java b/org.springframework.context/src/main/java/org/springframework/cache/interceptor/DefaultKeyGenerator.java index 1ebe4f5ec4..7d80b372d9 100644 --- a/org.springframework.context/src/main/java/org/springframework/cache/interceptor/DefaultKeyGenerator.java +++ b/org.springframework.context/src/main/java/org/springframework/cache/interceptor/DefaultKeyGenerator.java @@ -21,25 +21,30 @@ import java.lang.reflect.Method; import org.springframework.cache.interceptor.KeyGenerator; /** - * Default key generator. Returns 0 if no param is given, the param itself if - * only one is given or a hash code computed from all given params hash code. - * Uses a constant (53) for null objects. + * Default key generator. Returns {@value #NO_PARAM_KEY} if no parameters are provided, + * the parameter itself if only one is given or a hash code computed from all given + * parameters' hash code values. Uses the constant value {@value #NULL_PARAM_KEY} for any + * {@code null} parameters given. * * @author Costin Leau + * @author Chris Beams * @since 3.1 */ public class DefaultKeyGenerator implements KeyGenerator { + public static final int NO_PARAM_KEY = 0; + public static final int NULL_PARAM_KEY = 53; + public Object extract(Object target, Method method, Object... params) { if (params.length == 1) { - return (params[0] == null ? 53 : params[0]); + return (params[0] == null ? NULL_PARAM_KEY : params[0]); } if (params.length == 0) { - return 0; + return NO_PARAM_KEY; } int hashCode = 17; for (Object object : params) { - hashCode = 31 * hashCode + (object == null ? 53 : object.hashCode()); + hashCode = 31 * hashCode + (object == null ? NULL_PARAM_KEY : object.hashCode()); } return Integer.valueOf(hashCode); }