DATACMNS-1101 - Remove Optional from PersistentProperty.getComponentType(…)/getMapValueType(…).

This commit is contained in:
Mark Paluch
2017-06-29 10:42:32 +02:00
committed by Oliver Gierke
parent eb9854f18f
commit 2064c72a85
4 changed files with 11 additions and 17 deletions

View File

@@ -20,7 +20,6 @@ import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.Collection;
import java.util.Map;
import java.util.Optional;
import org.springframework.core.annotation.AnnotationUtils;
import org.springframework.data.util.TypeInformation;
@@ -179,10 +178,10 @@ public interface PersistentProperty<P extends PersistentProperty<P>> {
* Returns the component type of the type if it is a {@link java.util.Collection}. Will return the type of the key if
* the property is a {@link java.util.Map}.
*
* @return the component type, the map's key type or {@link Optional#empty()} if neither {@link java.util.Collection}
* nor {@link java.util.Map}.
* @return the component type, the map's key type or {@literal null} if neither {@link java.util.Collection} nor
* {@link java.util.Map}.
*/
Optional<Class<?>> getComponentType();
Class<?> getComponentType();
/**
* Returns the raw type as it's pulled from from the reflected property.
@@ -194,9 +193,9 @@ public interface PersistentProperty<P extends PersistentProperty<P>> {
/**
* Returns the type of the values if the property is a {@link java.util.Map}.
*
* @return the map's value type or {@link Optional#empty()} if no {@link java.util.Map}
* @return the map's value type or {@literal null} if no {@link java.util.Map}
*/
Optional<Class<?>> getMapValueType();
Class<?> getMapValueType();
/**
* Returns the actual type of the property. This will be the original property type if no generics were used, the

View File

@@ -258,13 +258,8 @@ public abstract class AbstractPersistentProperty<P extends PersistentProperty<P>
* @see org.springframework.data.mapping.PersistentProperty#getComponentType()
*/
@Override
public Optional<Class<?>> getComponentType() {
if (!isMap() && !isCollectionLike()) {
return Optional.empty();
}
return Optional.of(information.getRequiredComponentType().getType());
public Class<?> getComponentType() {
return isMap() || isCollectionLike() ? information.getRequiredComponentType().getType() : null;
}
/*
@@ -272,8 +267,8 @@ public abstract class AbstractPersistentProperty<P extends PersistentProperty<P>
* @see org.springframework.data.mapping.PersistentProperty#getMapValueType()
*/
@Override
public Optional<Class<?>> getMapValueType() {
return isMap() ? information.getMapValueType().map(TypeInformation::getType) : Optional.empty();
public Class<?> getMapValueType() {
return isMap() ? information.getMapValueType().map(TypeInformation::getType).orElse(null) : null;
}
/*