Skip to content

Commit db616dc

Browse files
committed
Polishing
1 parent cee53e9 commit db616dc

File tree

2 files changed

+35
-41
lines changed

2 files changed

+35
-41
lines changed

spring-context/src/main/java/org/springframework/validation/beanvalidation/SpringValidatorAdapter.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2013 the original author or authors.
2+
* Copyright 2002-2014 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -94,19 +94,18 @@ public void validate(Object target, Errors errors) {
9494
}
9595

9696
@Override
97-
@SuppressWarnings("rawtypes")
9897
public void validate(Object target, Errors errors, Object... validationHints) {
9998
if (this.targetValidator != null) {
100-
Set<Class> groups = new LinkedHashSet<Class>();
99+
Set<Class<?>> groups = new LinkedHashSet<Class<?>>();
101100
if (validationHints != null) {
102101
for (Object hint : validationHints) {
103102
if (hint instanceof Class) {
104-
groups.add((Class) hint);
103+
groups.add((Class<?>) hint);
105104
}
106105
}
107106
}
108107
processConstraintViolations(
109-
this.targetValidator.validate(target, groups.toArray(new Class[groups.size()])), errors);
108+
this.targetValidator.validate(target, groups.toArray(new Class<?>[groups.size()])), errors);
110109
}
111110
}
112111

spring-core/src/main/java/org/springframework/util/ConcurrentReferenceHashMap.java

Lines changed: 31 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -224,23 +224,23 @@ protected int getHash(Object o) {
224224
@Override
225225
public V get(Object key) {
226226
Reference<K, V> reference = getReference(key, Restructure.WHEN_NECESSARY);
227-
Entry<K, V> entry = (reference == null ? null : reference.get());
227+
Entry<K, V> entry = (reference != null ? reference.get() : null);
228228
return (entry != null ? entry.getValue() : null);
229229
}
230230

231231
@Override
232232
public boolean containsKey(Object key) {
233233
Reference<K, V> reference = getReference(key, Restructure.WHEN_NECESSARY);
234-
Entry<K, V> entry = (reference == null ? null : reference.get());
234+
Entry<K, V> entry = (reference != null ? reference.get() : null);
235235
return (entry != null && ObjectUtils.nullSafeEquals(entry.getKey(), key));
236236
}
237237

238238
/**
239-
* Returns a {@link Reference} to the {@link Entry} for the specified {@code key} or
240-
* {@code null} if not found.
239+
* Return a {@link Reference} to the {@link Entry} for the specified {@code key},
240+
* or {@code null} if not found.
241241
* @param key the key (can be {@code null})
242242
* @param restructure types of restructure allowed during this call
243-
* @return the reference or {@code null}
243+
* @return the reference, or {@code null} if not found
244244
*/
245245
protected final Reference<K, V> getReference(Object key, Restructure restructure) {
246246
int hash = getHash(key);
@@ -400,14 +400,10 @@ protected static int calculateShift(int minimumValue, int maximumValue) {
400400
*/
401401
public static enum ReferenceType {
402402

403-
/**
404-
* Use {@link SoftReference}s.
405-
*/
403+
/** Use {@link SoftReference}s */
406404
SOFT,
407405

408-
/**
409-
* Use {@link WeakReference}s.
410-
*/
406+
/** Use {@link WeakReference}s */
411407
WEAK
412408
}
413409

@@ -462,8 +458,8 @@ public Reference<K, V> getReference(Object key, int hash, Restructure restructur
462458
}
463459

464460
/**
465-
* Apply an update operation to this segment. The segment will be locked
466-
* during update.
461+
* Apply an update operation to this segment.
462+
* The segment will be locked during the update.
467463
* @param hash the hash of the key
468464
* @param key the key
469465
* @param task the update operation
@@ -474,20 +470,20 @@ public <T> T doTask(final int hash, final Object key, final Task<T> task) {
474470
if (task.hasOption(TaskOption.RESTRUCTURE_BEFORE)) {
475471
restructureIfNecessary(resize);
476472
}
477-
if (task.hasOption(TaskOption.SKIP_IF_EMPTY) && (this.count == 0)) {
473+
if (task.hasOption(TaskOption.SKIP_IF_EMPTY) && this.count == 0) {
478474
return task.execute(null, null, null);
479475
}
480476
lock();
481477
try {
482478
final int index = getIndex(hash, this.references);
483479
final Reference<K, V> head = this.references[index];
484480
Reference<K, V> reference = findInChain(head, key, hash);
485-
Entry<K, V> entry = (reference == null ? null : reference.get());
481+
Entry<K, V> entry = (reference != null ? reference.get() : null);
486482
Entries entries = new Entries() {
487483
@Override
488484
public void add(V value) {
489485
@SuppressWarnings("unchecked")
490-
Entry<K, V> newEntry = new Entry<K, V>((K)key, value);
486+
Entry<K, V> newEntry = new Entry<K, V>((K) key, value);
491487
Reference<K, V> newReference = Segment.this.referenceManager.createReference(newEntry, hash, head);
492488
Segment.this.references[index] = newReference;
493489
Segment.this.count++;
@@ -514,7 +510,8 @@ public void clear() {
514510
try {
515511
setReferences(createReferenceArray(this.initialSize));
516512
this.count = 0;
517-
} finally {
513+
}
514+
finally {
518515
unlock();
519516
}
520517
}
@@ -545,16 +542,16 @@ protected final void restructureIfNecessary(boolean allowResize) {
545542

546543
// Recalculate taking into account count inside lock and items that
547544
// will be purged
548-
needsResize = ((countAfterRestructure > 0) && (countAfterRestructure >= this.resizeThreshold));
545+
needsResize = (countAfterRestructure > 0 && countAfterRestructure >= this.resizeThreshold);
549546
boolean resizing = false;
550547
int restructureSize = this.references.length;
551-
if (allowResize && needsResize && (restructureSize < MAXIMUM_SEGMENT_SIZE)) {
548+
if (allowResize && needsResize && restructureSize < MAXIMUM_SEGMENT_SIZE) {
552549
restructureSize <<= 1;
553550
resizing = true;
554551
}
555552

556553
// Either create a new table or reuse the existing one
557-
Reference<K, V>[] restructured = (resizing ? createReferenceArray(restructureSize) : this.references);
554+
Reference<K, V>[] restructured = (resizing ? createReferenceArray(restructureSize) : this.references);
558555

559556
// Restructure
560557
for (int i = 0; i < this.references.length; i++) {
@@ -578,7 +575,8 @@ protected final void restructureIfNecessary(boolean allowResize) {
578575
setReferences(restructured);
579576
}
580577
this.count = Math.max(countAfterRestructure, 0);
581-
} finally {
578+
}
579+
finally {
582580
unlock();
583581
}
584582
}
@@ -606,7 +604,7 @@ private Reference<K, V>[] createReferenceArray(int size) {
606604
}
607605

608606
private int getIndex(int hash, Reference<K, V>[] references) {
609-
return hash & (references.length - 1);
607+
return (hash & (references.length - 1));
610608
}
611609

612610
/**
@@ -700,27 +698,26 @@ public V setValue(V value) {
700698

701699
@Override
702700
public String toString() {
703-
return this.key + "=" + this.value;
701+
return (this.key + "=" + this.value);
704702
}
705703

706704
@Override
707705
@SuppressWarnings("rawtypes")
708-
public final boolean equals(Object o) {
709-
if (o == this) {
706+
public final boolean equals(Object other) {
707+
if (this == other) {
710708
return true;
711709
}
712-
if (o != null && o instanceof Map.Entry) {
713-
Map.Entry other = (Map.Entry) o;
714-
return ObjectUtils.nullSafeEquals(getKey(), other.getKey())
715-
&& ObjectUtils.nullSafeEquals(getValue(), other.getValue());
710+
if (!(other instanceof Map.Entry)) {
711+
return false;
716712
}
717-
return false;
713+
Map.Entry otherEntry = (Map.Entry) other;
714+
return (ObjectUtils.nullSafeEquals(getKey(), otherEntry.getKey()) &&
715+
ObjectUtils.nullSafeEquals(getValue(), otherEntry.getValue()));
718716
}
719717

720718
@Override
721719
public final int hashCode() {
722-
return ObjectUtils.nullSafeHashCode(this.key)
723-
^ ObjectUtils.nullSafeHashCode(this.value);
720+
return (ObjectUtils.nullSafeHashCode(this.key) ^ ObjectUtils.nullSafeHashCode(this.value));
724721
}
725722
}
726723

@@ -802,7 +799,7 @@ public boolean contains(Object o) {
802799
if (o != null && o instanceof Map.Entry<?, ?>) {
803800
Map.Entry<?, ?> entry = (java.util.Map.Entry<?, ?>) o;
804801
Reference<K, V> reference = ConcurrentReferenceHashMap.this.getReference(entry.getKey(), Restructure.NEVER);
805-
Entry<K, V> other = (reference == null ? null : reference.get());
802+
Entry<K, V> other = (reference != null ? reference.get() : null);
806803
if (other != null) {
807804
return ObjectUtils.nullSafeEquals(entry.getValue(), other.getValue());
808805
}
@@ -855,7 +852,7 @@ public EntryIterator() {
855852
@Override
856853
public boolean hasNext() {
857854
getNextIfNecessary();
858-
return this.next != null;
855+
return (this.next != null);
859856
}
860857

861858
@Override
@@ -987,7 +984,6 @@ public void release() {
987984
enqueue();
988985
clear();
989986
}
990-
991987
}
992988

993989

@@ -1021,7 +1017,6 @@ public void release() {
10211017
enqueue();
10221018
clear();
10231019
}
1024-
10251020
}
10261021

10271022
}

0 commit comments

Comments
 (0)