From 4fe52d19534195717c742fd1e04fb096ba2eeb96 Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Tue, 10 Dec 2013 12:00:32 +0100 Subject: [PATCH] Polishing --- .../cache/interceptor/SimpleKey.java | 19 ++++++------------- .../cache/interceptor/SimpleKeyGenerator.java | 4 ++-- .../springframework/util/CollectionUtils.java | 7 ++----- 3 files changed, 10 insertions(+), 20 deletions(-) diff --git a/spring-context/src/main/java/org/springframework/cache/interceptor/SimpleKey.java b/spring-context/src/main/java/org/springframework/cache/interceptor/SimpleKey.java index 805edbbaad..80602321cb 100644 --- a/spring-context/src/main/java/org/springframework/cache/interceptor/SimpleKey.java +++ b/spring-context/src/main/java/org/springframework/cache/interceptor/SimpleKey.java @@ -29,12 +29,10 @@ import org.springframework.util.StringUtils; * @since 4.0 * @see SimpleKeyGenerator */ +@SuppressWarnings("serial") public final class SimpleKey implements Serializable { - private static final long serialVersionUID = 1; - - public static final SimpleKey EMPTY = new SimpleKey(new Object[] {}); - + public static final SimpleKey EMPTY = new SimpleKey(); private final Object[] params; @@ -43,7 +41,7 @@ public final class SimpleKey implements Serializable { * Create a new {@link SimpleKey} instance. * @param elements the elements of the key */ - public SimpleKey(Object[] elements) { + public SimpleKey(Object... elements) { Assert.notNull(elements, "Elements must not be null"); this.params = new Object[elements.length]; System.arraycopy(elements, 0, this.params, 0, elements.length); @@ -52,22 +50,17 @@ public final class SimpleKey implements Serializable { @Override public boolean equals(Object obj) { - if (obj == this) { - return true; - } - if (obj != null && getClass() == obj.getClass()) { - return Arrays.equals(this.params, ((SimpleKey) obj).params); - } - return false; + return (this == obj || (obj instanceof SimpleKey && Arrays.equals(this.params, ((SimpleKey) obj).params))); } @Override public int hashCode() { - return Arrays.hashCode(params); + return Arrays.hashCode(this.params); } @Override public String toString() { return "SimpleKey [" + StringUtils.arrayToCommaDelimitedString(this.params) + "]"; } + } diff --git a/spring-context/src/main/java/org/springframework/cache/interceptor/SimpleKeyGenerator.java b/spring-context/src/main/java/org/springframework/cache/interceptor/SimpleKeyGenerator.java index 7d6fc6f16d..826e7c9c2c 100644 --- a/spring-context/src/main/java/org/springframework/cache/interceptor/SimpleKeyGenerator.java +++ b/spring-context/src/main/java/org/springframework/cache/interceptor/SimpleKeyGenerator.java @@ -38,10 +38,10 @@ public class SimpleKeyGenerator implements KeyGenerator { @Override public Object generate(Object target, Method method, Object... params) { - if(params.length == 0) { + if (params.length == 0) { return SimpleKey.EMPTY; } - if(params.length == 1 && params[0] != null) { + if (params.length == 1 && params[0] != null) { return params[0]; } return new SimpleKey(params); diff --git a/spring-core/src/main/java/org/springframework/util/CollectionUtils.java b/spring-core/src/main/java/org/springframework/util/CollectionUtils.java index 5e84aee859..85bcd71346 100644 --- a/spring-core/src/main/java/org/springframework/util/CollectionUtils.java +++ b/spring-core/src/main/java/org/springframework/util/CollectionUtils.java @@ -335,8 +335,7 @@ public abstract class CollectionUtils { } /** - * Adapts a {@code Map>} to an {@code MultiValueMap}. - * + * Adapt a {@code Map>} to an {@code MultiValueMap}. * @param map the map * @return the multi-value map */ @@ -346,8 +345,7 @@ public abstract class CollectionUtils { } /** - * Returns an unmodifiable view of the specified multi-value map. - * + * Return an unmodifiable view of the specified multi-value map. * @param map the map for which an unmodifiable view is to be returned. * @return an unmodifiable view of the specified multi-value map. */ @@ -363,7 +361,6 @@ public abstract class CollectionUtils { } - /** * Iterator wrapping an Enumeration. */