Polishing
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2012 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.
|
||||
@@ -62,6 +62,7 @@ public final class Property {
|
||||
|
||||
private Annotation[] annotations;
|
||||
|
||||
|
||||
public Property(Class<?> objectType, Method readMethod, Method writeMethod) {
|
||||
this(objectType, readMethod, writeMethod, null);
|
||||
}
|
||||
@@ -241,34 +242,25 @@ public final class Property {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int hashCode = 1;
|
||||
hashCode = prime * hashCode + ObjectUtils.nullSafeHashCode(this.objectType);
|
||||
hashCode = prime * hashCode + ObjectUtils.nullSafeHashCode(this.readMethod);
|
||||
hashCode = prime * hashCode + ObjectUtils.nullSafeHashCode(this.writeMethod);
|
||||
hashCode = prime * hashCode + ObjectUtils.nullSafeHashCode(this.name);
|
||||
return hashCode;
|
||||
public boolean equals(Object other) {
|
||||
if (this == other) {
|
||||
return true;
|
||||
}
|
||||
if (!(other instanceof Property)) {
|
||||
return false;
|
||||
}
|
||||
Property otherProperty = (Property) other;
|
||||
return (ObjectUtils.nullSafeEquals(this.objectType, otherProperty.objectType) &&
|
||||
ObjectUtils.nullSafeEquals(this.name, otherProperty.name) &&
|
||||
ObjectUtils.nullSafeEquals(this.readMethod, otherProperty.readMethod) &&
|
||||
ObjectUtils.nullSafeEquals(this.writeMethod, otherProperty.writeMethod));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj) {
|
||||
return true;
|
||||
}
|
||||
if (obj == null) {
|
||||
return false;
|
||||
}
|
||||
if (getClass() != obj.getClass()) {
|
||||
return false;
|
||||
}
|
||||
Property other = (Property) obj;
|
||||
boolean equals = true;
|
||||
equals &= ObjectUtils.nullSafeEquals(this.objectType, other.objectType);
|
||||
equals &= ObjectUtils.nullSafeEquals(this.readMethod, other.readMethod);
|
||||
equals &= ObjectUtils.nullSafeEquals(this.writeMethod, other.writeMethod);
|
||||
equals &= ObjectUtils.nullSafeEquals(this.name, other.name);
|
||||
return equals;
|
||||
public int hashCode() {
|
||||
return (ObjectUtils.nullSafeHashCode(this.objectType) * 31 + ObjectUtils.nullSafeHashCode(this.name));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2012 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.
|
||||
@@ -42,10 +42,12 @@ final class MapToMapConverter implements ConditionalGenericConverter {
|
||||
|
||||
private final ConversionService conversionService;
|
||||
|
||||
|
||||
public MapToMapConverter(ConversionService conversionService) {
|
||||
this.conversionService = conversionService;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Set<ConvertiblePair> getConvertibleTypes() {
|
||||
return Collections.singleton(new ConvertiblePair(Map.class, Map.class));
|
||||
@@ -88,6 +90,7 @@ final class MapToMapConverter implements ConditionalGenericConverter {
|
||||
return targetMap;
|
||||
}
|
||||
|
||||
|
||||
// internal helpers
|
||||
|
||||
private boolean canConvertKey(TypeDescriptor sourceType, TypeDescriptor targetType) {
|
||||
@@ -114,10 +117,12 @@ final class MapToMapConverter implements ConditionalGenericConverter {
|
||||
return this.conversionService.convert(sourceValue, sourceType.getMapValueTypeDescriptor(sourceValue), targetType);
|
||||
}
|
||||
|
||||
|
||||
private static class MapEntry {
|
||||
|
||||
private Object key;
|
||||
private Object value;
|
||||
private final Object key;
|
||||
|
||||
private final Object value;
|
||||
|
||||
public MapEntry(Object key, Object value) {
|
||||
this.key = key;
|
||||
@@ -125,7 +130,7 @@ final class MapToMapConverter implements ConditionalGenericConverter {
|
||||
}
|
||||
|
||||
public void addToMap(Map<Object, Object> map) {
|
||||
map.put(key, value);
|
||||
map.put(this.key, this.value);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2012 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.
|
||||
@@ -31,23 +31,22 @@ import org.springframework.util.Assert;
|
||||
* is required.
|
||||
*
|
||||
* @author Phillip Webb
|
||||
* @param <T> The type of objects being compared
|
||||
* @see CompoundComparator
|
||||
* @since 3.2
|
||||
* @param <T> the type of objects being compared
|
||||
* @see CompoundComparator
|
||||
*/
|
||||
public class InstanceComparator<T> implements Comparator<T> {
|
||||
|
||||
private Class<?>[] instanceOrder;
|
||||
private final Class<?>[] instanceOrder;
|
||||
|
||||
|
||||
/**
|
||||
* Create a new {@link InstanceComparator} instance.
|
||||
*
|
||||
* @param instanceOrder the ordered list of classes that should be used when comparing
|
||||
* objects. Classes earlier in the list will be be given a higher priority.
|
||||
*/
|
||||
public InstanceComparator(Class<?>... instanceOrder) {
|
||||
Assert.notNull(instanceOrder, "InstanceOrder must not be null");
|
||||
Assert.notNull(instanceOrder, "'instanceOrder' must not be null");
|
||||
this.instanceOrder = instanceOrder;
|
||||
}
|
||||
|
||||
@@ -61,13 +60,13 @@ public class InstanceComparator<T> implements Comparator<T> {
|
||||
|
||||
private int getOrder(T object) {
|
||||
if (object != null) {
|
||||
for (int i = 0; i < instanceOrder.length; i++) {
|
||||
if (instanceOrder[i].isInstance(object)) {
|
||||
for (int i = 0; i < this.instanceOrder.length; i++) {
|
||||
if (this.instanceOrder[i].isInstance(object)) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
}
|
||||
return instanceOrder.length;
|
||||
return this.instanceOrder.length;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user