Browse Source

Polishing

pull/576/head
Juergen Hoeller 11 years ago
parent
commit
db616dc438
  1. 9
      spring-context/src/main/java/org/springframework/validation/beanvalidation/SpringValidatorAdapter.java
  2. 65
      spring-core/src/main/java/org/springframework/util/ConcurrentReferenceHashMap.java

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

@ -1,5 +1,5 @@ @@ -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. @@ -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<Class> groups = new LinkedHashSet<Class>();
Set<Class<?>> groups = new LinkedHashSet<Class<?>>();
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);
}
}

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

@ -224,23 +224,23 @@ public class ConcurrentReferenceHashMap<K, V> extends AbstractMap<K, V> implemen @@ -224,23 +224,23 @@ public class ConcurrentReferenceHashMap<K, V> extends AbstractMap<K, V> implemen
@Override
public V get(Object key) {
Reference<K, V> reference = getReference(key, Restructure.WHEN_NECESSARY);
Entry<K, V> entry = (reference == null ? null : reference.get());
Entry<K, V> entry = (reference != null ? reference.get() : null);
return (entry != null ? entry.getValue() : null);
}
@Override
public boolean containsKey(Object key) {
Reference<K, V> reference = getReference(key, Restructure.WHEN_NECESSARY);
Entry<K, V> entry = (reference == null ? null : reference.get());
Entry<K, V> 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<K, V> getReference(Object key, Restructure restructure) {
int hash = getHash(key);
@ -400,14 +400,10 @@ public class ConcurrentReferenceHashMap<K, V> extends AbstractMap<K, V> implemen @@ -400,14 +400,10 @@ public class ConcurrentReferenceHashMap<K, V> extends AbstractMap<K, V> 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<K, V> extends AbstractMap<K, V> implemen @@ -462,8 +458,8 @@ public class ConcurrentReferenceHashMap<K, V> extends AbstractMap<K, V> 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<K, V> extends AbstractMap<K, V> implemen @@ -474,7 +470,7 @@ public class ConcurrentReferenceHashMap<K, V> extends AbstractMap<K, V> 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<K, V> extends AbstractMap<K, V> implemen @@ -482,12 +478,12 @@ public class ConcurrentReferenceHashMap<K, V> extends AbstractMap<K, V> implemen
final int index = getIndex(hash, this.references);
final Reference<K, V> head = this.references[index];
Reference<K, V> reference = findInChain(head, key, hash);
Entry<K, V> entry = (reference == null ? null : reference.get());
Entry<K, V> entry = (reference != null ? reference.get() : null);
Entries entries = new Entries() {
@Override
public void add(V value) {
@SuppressWarnings("unchecked")
Entry<K, V> newEntry = new Entry<K, V>((K)key, value);
Entry<K, V> newEntry = new Entry<K, V>((K) key, value);
Reference<K, V> newReference = Segment.this.referenceManager.createReference(newEntry, hash, head);
Segment.this.references[index] = newReference;
Segment.this.count++;
@ -514,7 +510,8 @@ public class ConcurrentReferenceHashMap<K, V> extends AbstractMap<K, V> implemen @@ -514,7 +510,8 @@ public class ConcurrentReferenceHashMap<K, V> extends AbstractMap<K, V> implemen
try {
setReferences(createReferenceArray(this.initialSize));
this.count = 0;
} finally {
}
finally {
unlock();
}
}
@ -545,10 +542,10 @@ public class ConcurrentReferenceHashMap<K, V> extends AbstractMap<K, V> implemen @@ -545,10 +542,10 @@ public class ConcurrentReferenceHashMap<K, V> extends AbstractMap<K, V> 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;
}
@ -578,7 +575,8 @@ public class ConcurrentReferenceHashMap<K, V> extends AbstractMap<K, V> implemen @@ -578,7 +575,8 @@ public class ConcurrentReferenceHashMap<K, V> extends AbstractMap<K, V> implemen
setReferences(restructured);
}
this.count = Math.max(countAfterRestructure, 0);
} finally {
}
finally {
unlock();
}
}
@ -606,7 +604,7 @@ public class ConcurrentReferenceHashMap<K, V> extends AbstractMap<K, V> implemen @@ -606,7 +604,7 @@ public class ConcurrentReferenceHashMap<K, V> extends AbstractMap<K, V> implemen
}
private int getIndex(int hash, Reference<K, V>[] references) {
return hash & (references.length - 1);
return (hash & (references.length - 1));
}
/**
@ -700,27 +698,26 @@ public class ConcurrentReferenceHashMap<K, V> extends AbstractMap<K, V> implemen @@ -700,27 +698,26 @@ public class ConcurrentReferenceHashMap<K, V> extends AbstractMap<K, V> 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;
}
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<K, V> extends AbstractMap<K, V> implemen @@ -802,7 +799,7 @@ public class ConcurrentReferenceHashMap<K, V> extends AbstractMap<K, V> implemen
if (o != null && o instanceof Map.Entry<?, ?>) {
Map.Entry<?, ?> entry = (java.util.Map.Entry<?, ?>) o;
Reference<K, V> reference = ConcurrentReferenceHashMap.this.getReference(entry.getKey(), Restructure.NEVER);
Entry<K, V> other = (reference == null ? null : reference.get());
Entry<K, V> other = (reference != null ? reference.get() : null);
if (other != null) {
return ObjectUtils.nullSafeEquals(entry.getValue(), other.getValue());
}
@ -855,7 +852,7 @@ public class ConcurrentReferenceHashMap<K, V> extends AbstractMap<K, V> implemen @@ -855,7 +852,7 @@ public class ConcurrentReferenceHashMap<K, V> extends AbstractMap<K, V> implemen
@Override
public boolean hasNext() {
getNextIfNecessary();
return this.next != null;
return (this.next != null);
}
@Override
@ -987,7 +984,6 @@ public class ConcurrentReferenceHashMap<K, V> extends AbstractMap<K, V> implemen @@ -987,7 +984,6 @@ public class ConcurrentReferenceHashMap<K, V> extends AbstractMap<K, V> implemen
enqueue();
clear();
}
}
@ -1021,7 +1017,6 @@ public class ConcurrentReferenceHashMap<K, V> extends AbstractMap<K, V> implemen @@ -1021,7 +1017,6 @@ public class ConcurrentReferenceHashMap<K, V> extends AbstractMap<K, V> implemen
enqueue();
clear();
}
}
}

Loading…
Cancel
Save