From db616dc438566b6308bc467c2480d16a88c721c9 Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Mon, 30 Jun 2014 14:55:43 +0200 Subject: [PATCH] Polishing --- .../SpringValidatorAdapter.java | 9 ++- .../util/ConcurrentReferenceHashMap.java | 67 +++++++++---------- 2 files changed, 35 insertions(+), 41 deletions(-) diff --git a/spring-context/src/main/java/org/springframework/validation/beanvalidation/SpringValidatorAdapter.java b/spring-context/src/main/java/org/springframework/validation/beanvalidation/SpringValidatorAdapter.java index 7733b98b87..6e019b38dd 100644 --- a/spring-context/src/main/java/org/springframework/validation/beanvalidation/SpringValidatorAdapter.java +++ b/spring-context/src/main/java/org/springframework/validation/beanvalidation/SpringValidatorAdapter.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2013 the original author or authors. + * Copyright 2002-2014 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -94,19 +94,18 @@ public class SpringValidatorAdapter implements SmartValidator, javax.validation. } @Override - @SuppressWarnings("rawtypes") public void validate(Object target, Errors errors, Object... validationHints) { if (this.targetValidator != null) { - Set groups = new LinkedHashSet(); + Set> groups = new LinkedHashSet>(); if (validationHints != null) { for (Object hint : validationHints) { if (hint instanceof Class) { - groups.add((Class) hint); + groups.add((Class) hint); } } } processConstraintViolations( - this.targetValidator.validate(target, groups.toArray(new Class[groups.size()])), errors); + this.targetValidator.validate(target, groups.toArray(new Class[groups.size()])), errors); } } diff --git a/spring-core/src/main/java/org/springframework/util/ConcurrentReferenceHashMap.java b/spring-core/src/main/java/org/springframework/util/ConcurrentReferenceHashMap.java index e0b7e028f8..3bb6471f67 100644 --- a/spring-core/src/main/java/org/springframework/util/ConcurrentReferenceHashMap.java +++ b/spring-core/src/main/java/org/springframework/util/ConcurrentReferenceHashMap.java @@ -224,23 +224,23 @@ public class ConcurrentReferenceHashMap extends AbstractMap implemen @Override public V get(Object key) { Reference reference = getReference(key, Restructure.WHEN_NECESSARY); - Entry entry = (reference == null ? null : reference.get()); + Entry entry = (reference != null ? reference.get() : null); return (entry != null ? entry.getValue() : null); } @Override public boolean containsKey(Object key) { Reference reference = getReference(key, Restructure.WHEN_NECESSARY); - Entry entry = (reference == null ? null : reference.get()); + Entry entry = (reference != null ? reference.get() : null); return (entry != null && ObjectUtils.nullSafeEquals(entry.getKey(), key)); } /** - * Returns a {@link Reference} to the {@link Entry} for the specified {@code key} or - * {@code null} if not found. + * Return a {@link Reference} to the {@link Entry} for the specified {@code key}, + * or {@code null} if not found. * @param key the key (can be {@code null}) * @param restructure types of restructure allowed during this call - * @return the reference or {@code null} + * @return the reference, or {@code null} if not found */ protected final Reference getReference(Object key, Restructure restructure) { int hash = getHash(key); @@ -400,14 +400,10 @@ public class ConcurrentReferenceHashMap extends AbstractMap implemen */ public static enum ReferenceType { - /** - * Use {@link SoftReference}s. - */ + /** Use {@link SoftReference}s */ SOFT, - /** - * Use {@link WeakReference}s. - */ + /** Use {@link WeakReference}s */ WEAK } @@ -462,8 +458,8 @@ public class ConcurrentReferenceHashMap extends AbstractMap implemen } /** - * Apply an update operation to this segment. The segment will be locked - * during update. + * Apply an update operation to this segment. + * The segment will be locked during the update. * @param hash the hash of the key * @param key the key * @param task the update operation @@ -474,7 +470,7 @@ public class ConcurrentReferenceHashMap extends AbstractMap implemen if (task.hasOption(TaskOption.RESTRUCTURE_BEFORE)) { restructureIfNecessary(resize); } - if (task.hasOption(TaskOption.SKIP_IF_EMPTY) && (this.count == 0)) { + if (task.hasOption(TaskOption.SKIP_IF_EMPTY) && this.count == 0) { return task.execute(null, null, null); } lock(); @@ -482,12 +478,12 @@ public class ConcurrentReferenceHashMap extends AbstractMap implemen final int index = getIndex(hash, this.references); final Reference head = this.references[index]; Reference reference = findInChain(head, key, hash); - Entry entry = (reference == null ? null : reference.get()); + Entry entry = (reference != null ? reference.get() : null); Entries entries = new Entries() { @Override public void add(V value) { @SuppressWarnings("unchecked") - Entry newEntry = new Entry((K)key, value); + Entry newEntry = new Entry((K) key, value); Reference newReference = Segment.this.referenceManager.createReference(newEntry, hash, head); Segment.this.references[index] = newReference; Segment.this.count++; @@ -514,7 +510,8 @@ public class ConcurrentReferenceHashMap extends AbstractMap implemen try { setReferences(createReferenceArray(this.initialSize)); this.count = 0; - } finally { + } + finally { unlock(); } } @@ -545,16 +542,16 @@ public class ConcurrentReferenceHashMap extends AbstractMap implemen // Recalculate taking into account count inside lock and items that // will be purged - needsResize = ((countAfterRestructure > 0) && (countAfterRestructure >= this.resizeThreshold)); + needsResize = (countAfterRestructure > 0 && countAfterRestructure >= this.resizeThreshold); boolean resizing = false; int restructureSize = this.references.length; - if (allowResize && needsResize && (restructureSize < MAXIMUM_SEGMENT_SIZE)) { + if (allowResize && needsResize && restructureSize < MAXIMUM_SEGMENT_SIZE) { restructureSize <<= 1; resizing = true; } // Either create a new table or reuse the existing one - Reference[] restructured = (resizing ? createReferenceArray(restructureSize) : this.references); + Reference[] restructured = (resizing ? createReferenceArray(restructureSize) : this.references); // Restructure for (int i = 0; i < this.references.length; i++) { @@ -578,7 +575,8 @@ public class ConcurrentReferenceHashMap extends AbstractMap implemen setReferences(restructured); } this.count = Math.max(countAfterRestructure, 0); - } finally { + } + finally { unlock(); } } @@ -606,7 +604,7 @@ public class ConcurrentReferenceHashMap extends AbstractMap implemen } private int getIndex(int hash, Reference[] references) { - return hash & (references.length - 1); + return (hash & (references.length - 1)); } /** @@ -700,27 +698,26 @@ public class ConcurrentReferenceHashMap extends AbstractMap implemen @Override public String toString() { - return this.key + "=" + this.value; + return (this.key + "=" + this.value); } @Override @SuppressWarnings("rawtypes") - public final boolean equals(Object o) { - if (o == this) { + public final boolean equals(Object other) { + if (this == other) { return true; } - if (o != null && o instanceof Map.Entry) { - Map.Entry other = (Map.Entry) o; - return ObjectUtils.nullSafeEquals(getKey(), other.getKey()) - && ObjectUtils.nullSafeEquals(getValue(), other.getValue()); + if (!(other instanceof Map.Entry)) { + return false; } - return false; + Map.Entry otherEntry = (Map.Entry) other; + return (ObjectUtils.nullSafeEquals(getKey(), otherEntry.getKey()) && + ObjectUtils.nullSafeEquals(getValue(), otherEntry.getValue())); } @Override public final int hashCode() { - return ObjectUtils.nullSafeHashCode(this.key) - ^ ObjectUtils.nullSafeHashCode(this.value); + return (ObjectUtils.nullSafeHashCode(this.key) ^ ObjectUtils.nullSafeHashCode(this.value)); } } @@ -802,7 +799,7 @@ public class ConcurrentReferenceHashMap extends AbstractMap implemen if (o != null && o instanceof Map.Entry) { Map.Entry entry = (java.util.Map.Entry) o; Reference reference = ConcurrentReferenceHashMap.this.getReference(entry.getKey(), Restructure.NEVER); - Entry other = (reference == null ? null : reference.get()); + Entry other = (reference != null ? reference.get() : null); if (other != null) { return ObjectUtils.nullSafeEquals(entry.getValue(), other.getValue()); } @@ -855,7 +852,7 @@ public class ConcurrentReferenceHashMap extends AbstractMap implemen @Override public boolean hasNext() { getNextIfNecessary(); - return this.next != null; + return (this.next != null); } @Override @@ -987,7 +984,6 @@ public class ConcurrentReferenceHashMap extends AbstractMap implemen enqueue(); clear(); } - } @@ -1021,7 +1017,6 @@ public class ConcurrentReferenceHashMap extends AbstractMap implemen enqueue(); clear(); } - } }