Polishing

This commit is contained in:
Juergen Hoeller
2013-12-10 12:00:32 +01:00
parent 6d7ce439b1
commit 4fe52d1953
3 changed files with 10 additions and 20 deletions

View File

@@ -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) + "]";
}
}

View File

@@ -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);