From 04165ab000bb890decde4f64c1fcf83810475833 Mon Sep 17 00:00:00 2001 From: Oliver Gierke Date: Wed, 7 Sep 2011 07:59:51 +0200 Subject: [PATCH] DATACMNS-72 - A lot of improvements related to Sonar results. Fixed quite a lot of FindBugs and Checkstyle warnings. Removed unused classes, polished JavaDoc. --- .../data/mapping/PersistentProperty.java | 12 ++- .../context/AbstractMappingContext.java | 80 ++++++++++++------- .../mapping/context/MappingContextAware.java | 33 -------- .../MappingContextAwareBeanPostProcessor.java | 78 ------------------ .../mapping/model/BasicPersistentEntity.java | 4 +- .../data/mapping/model/BeanWrapper.java | 3 + .../model/MappingConfigurationException.java | 35 -------- .../data/querydsl/QueryDslUtils.java | 8 +- .../support/PropertiesBasedNamedQueries.java | 2 +- .../query/parser/OrderBySource.java | 4 +- .../data/repository/query/parser/Part.java | 31 +++---- .../repository/query/parser/PartTree.java | 7 +- .../repository/query/parser/Property.java | 2 +- .../support/DomainClassPropertyEditor.java | 37 ++++----- .../data/repository/util/ClassUtils.java | 1 - .../data/util/ClassTypeInformation.java | 2 - .../util/GenericArrayTypeInformation.java | 14 ++-- .../data/util/TypeDiscoverer.java | 7 +- .../data/util/TypeInformation.java | 33 +++++--- .../data/web/PageableArgumentResolver.java | 9 +-- 20 files changed, 147 insertions(+), 255 deletions(-) delete mode 100644 spring-data-commons-core/src/main/java/org/springframework/data/mapping/context/MappingContextAware.java delete mode 100644 spring-data-commons-core/src/main/java/org/springframework/data/mapping/context/MappingContextAwareBeanPostProcessor.java delete mode 100644 spring-data-commons-core/src/main/java/org/springframework/data/mapping/model/MappingConfigurationException.java diff --git a/spring-data-commons-core/src/main/java/org/springframework/data/mapping/PersistentProperty.java b/spring-data-commons-core/src/main/java/org/springframework/data/mapping/PersistentProperty.java index 5343a49ab..c3c5980cf 100644 --- a/spring-data-commons-core/src/main/java/org/springframework/data/mapping/PersistentProperty.java +++ b/spring-data-commons-core/src/main/java/org/springframework/data/mapping/PersistentProperty.java @@ -2,8 +2,6 @@ package org.springframework.data.mapping; import java.beans.PropertyDescriptor; import java.lang.reflect.Field; -import java.util.Collection; -import java.util.Map; import org.springframework.data.util.TypeInformation; @@ -61,10 +59,10 @@ public interface PersistentProperty

> { boolean isEntity(); /** - * Returns the component type of the type if it is a {@link Collection}. Will return the type of the key if the - * property is a {@link Map}. + * 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 {@literal null} if neither {@link Collection} nor {@link Map}. + * @return the component type, the map's key type or {@literal null} if neither {@link java.util.Collection} nor {@link java.util.Map}. */ Class getComponentType(); @@ -76,9 +74,9 @@ public interface PersistentProperty

> { Class getRawType(); /** - * Returns the type of the values if the property is a {@link Map}. + * Returns the type of the values if the property is a {@link java.util.Map}. * - * @return the map's value type or {@literal null} if no {@link Map} + * @return the map's value type or {@literal null} if no {@link java.util.Map} */ Class getMapValueType(); diff --git a/spring-data-commons-core/src/main/java/org/springframework/data/mapping/context/AbstractMappingContext.java b/spring-data-commons-core/src/main/java/org/springframework/data/mapping/context/AbstractMappingContext.java index 52b6edb99..d9cf0538c 100644 --- a/spring-data-commons-core/src/main/java/org/springframework/data/mapping/context/AbstractMappingContext.java +++ b/spring-data-commons-core/src/main/java/org/springframework/data/mapping/context/AbstractMappingContext.java @@ -241,35 +241,7 @@ public abstract class AbstractMappingContext nestedType = getNestedTypeToAdd(property, entity); - if (nestedType != null) { - addPersistentEntity(nestedType); - } - } - }, new ReflectionUtils.FieldFilter() { + ReflectionUtils.doWithFields(type, new PersistentPropertyCreator(entity, descriptors), new ReflectionUtils.FieldFilter() { public boolean matches(Field field) { return !Modifier.isStatic(field.getModifiers()) && !UNMAPPED_FIELDS.contains(field.getName()); } @@ -372,4 +344,54 @@ public abstract class AbstractMappingContext descriptors; + + /** + * Creates a new {@link PersistentPropertyCreator} for the given {@link PersistentEntity} and + * {@link PropertyDescriptor}s. + * + * @param entity + * @param descriptors + */ + private PersistentPropertyCreator(E entity, Map descriptors) { + this.entity = entity; + this.descriptors = descriptors; + } + + public void doWith(Field field) { + + PropertyDescriptor descriptor = descriptors.get(field.getName()); + + ReflectionUtils.makeAccessible(field); + P property = createPersistentProperty(field, descriptor, entity, simpleTypeHolder); + + if (property.isTransient()) { + return; + } + + entity.addPersistentProperty(property); + + if (property.isAssociation()) { + entity.addAssociation(property.getAssociation()); + } + + if (property.isIdProperty()) { + entity.setIdProperty(property); + } + + TypeInformation nestedType = getNestedTypeToAdd(property, entity); + if (nestedType != null) { + addPersistentEntity(nestedType); + } + } + } } diff --git a/spring-data-commons-core/src/main/java/org/springframework/data/mapping/context/MappingContextAware.java b/spring-data-commons-core/src/main/java/org/springframework/data/mapping/context/MappingContextAware.java deleted file mode 100644 index b3c5980d1..000000000 --- a/spring-data-commons-core/src/main/java/org/springframework/data/mapping/context/MappingContextAware.java +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2011 by the original author(s). - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.data.mapping.context; - -/** - * An interface to make beans aware of the active MappingContext in the current ApplicationContext. - * - * @author Jon Brisbin - */ -public interface MappingContextAware { - - /** - * The active MappingContext for the environment. - * - * @param mappingContext - */ - void setMappingContext(MappingContext mappingContext); - -} diff --git a/spring-data-commons-core/src/main/java/org/springframework/data/mapping/context/MappingContextAwareBeanPostProcessor.java b/spring-data-commons-core/src/main/java/org/springframework/data/mapping/context/MappingContextAwareBeanPostProcessor.java deleted file mode 100644 index dee4e921a..000000000 --- a/spring-data-commons-core/src/main/java/org/springframework/data/mapping/context/MappingContextAwareBeanPostProcessor.java +++ /dev/null @@ -1,78 +0,0 @@ -/* - * Copyright (c) 2011 by the original author(s). - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.data.mapping.context; - -import java.util.Map; - -import org.springframework.beans.BeansException; -import org.springframework.beans.factory.config.BeanPostProcessor; -import org.springframework.context.ApplicationContext; -import org.springframework.context.ApplicationContextAware; - -/** - * BeanPostProcessor to make Spring beans aware of the current MappingContext. If a MappingContext exists with the - * default bean name ("mappingContext"), then that bean is used. If there is no MappingContext registered under the - * default bean name, then the first MappingContext it finds is the one it chooses. - * - * @author Jon Brisbin - */ -public class MappingContextAwareBeanPostProcessor implements BeanPostProcessor, ApplicationContextAware { - - private ApplicationContext applicationContext; - private String mappingContextBeanName = "mappingContext"; - private MappingContext mappingContext; - - public MappingContextAwareBeanPostProcessor() { - } - - public MappingContextAwareBeanPostProcessor(MappingContext mappingContext) { - this.mappingContext = mappingContext; - } - - public String getMappingContextBeanName() { - return mappingContextBeanName; - } - - public void setMappingContextBeanName(String mappingContextBeanName) { - this.mappingContextBeanName = mappingContextBeanName; - } - - public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { - this.applicationContext = applicationContext; - } - - public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException { - return bean; - } - - @SuppressWarnings("rawtypes") - public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException { - if (bean instanceof MappingContextAware) { - if (null == mappingContext) { - Map mappingContexts = applicationContext.getBeansOfType(MappingContext.class); - if (mappingContexts.containsKey(mappingContextBeanName)) { - this.mappingContext = mappingContexts.get(mappingContextBeanName); - } else { - String firstBean = mappingContexts.keySet().iterator().next(); - this.mappingContext = applicationContext.getBean(firstBean, MappingContext.class); - } - } - ((MappingContextAware) bean).setMappingContext(mappingContext); - } - return bean; - } -} diff --git a/spring-data-commons-core/src/main/java/org/springframework/data/mapping/model/BasicPersistentEntity.java b/spring-data-commons-core/src/main/java/org/springframework/data/mapping/model/BasicPersistentEntity.java index 6f844a906..f4cddc226 100644 --- a/spring-data-commons-core/src/main/java/org/springframework/data/mapping/model/BasicPersistentEntity.java +++ b/spring-data-commons-core/src/main/java/org/springframework/data/mapping/model/BasicPersistentEntity.java @@ -15,6 +15,7 @@ */ package org.springframework.data.mapping.model; +import java.io.Serializable; import java.util.Comparator; import java.util.HashSet; import java.util.Set; @@ -186,8 +187,9 @@ public class BasicPersistentEntity> implement * @author Oliver Gierke */ private static final class AssociationComparator

> implements - Comparator> { + Comparator>, Serializable { + private static final long serialVersionUID = 4508054194886854513L; private final Comparator

delegate; public AssociationComparator(Comparator

delegate) { diff --git a/spring-data-commons-core/src/main/java/org/springframework/data/mapping/model/BeanWrapper.java b/spring-data-commons-core/src/main/java/org/springframework/data/mapping/model/BeanWrapper.java index cb8e9813c..06d80c4b6 100644 --- a/spring-data-commons-core/src/main/java/org/springframework/data/mapping/model/BeanWrapper.java +++ b/spring-data-commons-core/src/main/java/org/springframework/data/mapping/model/BeanWrapper.java @@ -104,6 +104,9 @@ public class BeanWrapper, T> { } catch (BeanInstantiationException e) { throw new MappingInstantiationException(e.getMessage(), e); } + + this.bean = bean; + return; } List params = new LinkedList(); diff --git a/spring-data-commons-core/src/main/java/org/springframework/data/mapping/model/MappingConfigurationException.java b/spring-data-commons-core/src/main/java/org/springframework/data/mapping/model/MappingConfigurationException.java deleted file mode 100644 index e79450169..000000000 --- a/spring-data-commons-core/src/main/java/org/springframework/data/mapping/model/MappingConfigurationException.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright (c) 2011 by the original author(s). - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.data.mapping.model; - -/** - * @author Jon Brisbin - */ -public class MappingConfigurationException extends Throwable { - /** - * - */ - private static final long serialVersionUID = 1L; - - public MappingConfigurationException(String s) { - super(s); - } - - public MappingConfigurationException(String s, Throwable throwable) { - super(s, throwable); - } -} diff --git a/spring-data-commons-core/src/main/java/org/springframework/data/querydsl/QueryDslUtils.java b/spring-data-commons-core/src/main/java/org/springframework/data/querydsl/QueryDslUtils.java index 6d9cfaf95..d70842c0f 100644 --- a/spring-data-commons-core/src/main/java/org/springframework/data/querydsl/QueryDslUtils.java +++ b/spring-data-commons-core/src/main/java/org/springframework/data/querydsl/QueryDslUtils.java @@ -16,10 +16,16 @@ package org.springframework.data.querydsl; /** + * Utility class for Querydsl. + * * @author Oliver Gierke */ -public class QueryDslUtils { +public abstract class QueryDslUtils { public static final boolean QUERY_DSL_PRESENT = org.springframework.util.ClassUtils.isPresent( "com.mysema.query.types.Predicate", QueryDslUtils.class.getClassLoader()); + + private QueryDslUtils() { + + } } diff --git a/spring-data-commons-core/src/main/java/org/springframework/data/repository/core/support/PropertiesBasedNamedQueries.java b/spring-data-commons-core/src/main/java/org/springframework/data/repository/core/support/PropertiesBasedNamedQueries.java index 04dff922e..c09502011 100644 --- a/spring-data-commons-core/src/main/java/org/springframework/data/repository/core/support/PropertiesBasedNamedQueries.java +++ b/spring-data-commons-core/src/main/java/org/springframework/data/repository/core/support/PropertiesBasedNamedQueries.java @@ -27,7 +27,7 @@ import org.springframework.util.Assert; */ public class PropertiesBasedNamedQueries implements NamedQueries { - public static NamedQueries EMPTY = new PropertiesBasedNamedQueries(new Properties()); + public static final NamedQueries EMPTY = new PropertiesBasedNamedQueries(new Properties()); private final Properties properties; diff --git a/spring-data-commons-core/src/main/java/org/springframework/data/repository/query/parser/OrderBySource.java b/spring-data-commons-core/src/main/java/org/springframework/data/repository/query/parser/OrderBySource.java index 6eaec2e92..8a67af1c3 100644 --- a/spring-data-commons-core/src/main/java/org/springframework/data/repository/query/parser/OrderBySource.java +++ b/spring-data-commons-core/src/main/java/org/springframework/data/repository/query/parser/OrderBySource.java @@ -34,8 +34,8 @@ import org.springframework.util.StringUtils; */ public class OrderBySource { - private final String BLOCK_SPLIT = "(?<=Asc|Desc)(?=[A-Z])"; - private final Pattern DIRECTION_SPLIT = Pattern.compile("(.+)(Asc|Desc)$"); + private static final String BLOCK_SPLIT = "(?<=Asc|Desc)(?=[A-Z])"; + private static final Pattern DIRECTION_SPLIT = Pattern.compile("(.+)(Asc|Desc)$"); private final List orders; diff --git a/spring-data-commons-core/src/main/java/org/springframework/data/repository/query/parser/Part.java b/spring-data-commons-core/src/main/java/org/springframework/data/repository/query/parser/Part.java index fefe9d69e..6f5520ffa 100644 --- a/spring-data-commons-core/src/main/java/org/springframework/data/repository/query/parser/Part.java +++ b/spring-data-commons-core/src/main/java/org/springframework/data/repository/query/parser/Part.java @@ -42,8 +42,8 @@ public class Part { * Creates a new {@link Part} from the given method name part, the {@link Class} the part originates from and the * start parameter index. * - * @param part - * @param clazz + * @param part must not be {@literal null}. + * @param clazz must not be {@l */ public Part(String part, Class clazz) { @@ -54,28 +54,31 @@ public class Part { * Creates a new {@link Part} from the given method name part, the {@link Class} the part originates from and the * start parameter index. * - * @param part - * @param clazz + * @param part must not be {@literal null}. + * @param clazz must not be {@literal null}. * @param alwaysIgnoreCase */ public Part(String part, Class clazz, boolean alwaysIgnoreCase) { - part = detectAndSetIgnoreCase(part); + String partToUse = detectAndSetIgnoreCase(part); if (alwaysIgnoreCase && ignoreCase != IgnoreCaseType.ALWAYS) { this.ignoreCase = IgnoreCaseType.WHEN_POSSIBLE; } - this.type = Type.fromProperty(part, clazz); - this.property = Property.from(type.extractProperty(part), clazz); + this.type = Type.fromProperty(partToUse); + this.property = Property.from(type.extractProperty(partToUse), clazz); } private String detectAndSetIgnoreCase(String part) { Matcher matcher = IGNORE_CASE.matcher(part); + String result = part; + if (matcher.find()) { ignoreCase = IgnoreCaseType.ALWAYS; - part = part.substring(0, matcher.start()) + part.substring(matcher.end(), part.length()); + result = part.substring(0, matcher.start()) + part.substring(matcher.end(), part.length()); } - return part; + + return result; } public boolean getParameterRequired() { @@ -221,18 +224,17 @@ public class Part { } /** - * Returns the {@link Type} of the {@link Part} for the given raw property and the given {@link Class}. This will + * Returns the {@link Type} of the {@link Part} for the given raw property. This will * try to detect e.g. keywords contained in the raw property that trigger special query creation. Returns * {@link #SIMPLE_PROPERTY} by default. * * @param rawProperty - * @param clazz * @return */ - public static Part.Type fromProperty(String rawProperty, Class clazz) { + public static Part.Type fromProperty(String rawProperty) { for (Part.Type type : ALL) { - if (type.supports(rawProperty, clazz)) { + if (type.supports(rawProperty)) { return type; } } @@ -245,10 +247,9 @@ public class Part { * ends with the registered keyword. Does not support the keyword if the property is a valid field as is. * * @param property - * @param clazz * @return */ - protected boolean supports(String property, Class clazz) { + protected boolean supports(String property) { if (keywords == null) { return true; diff --git a/spring-data-commons-core/src/main/java/org/springframework/data/repository/query/parser/PartTree.java b/spring-data-commons-core/src/main/java/org/springframework/data/repository/query/parser/PartTree.java index e5ba147df..f193e2179 100644 --- a/spring-data-commons-core/src/main/java/org/springframework/data/repository/query/parser/PartTree.java +++ b/spring-data-commons-core/src/main/java/org/springframework/data/repository/query/parser/PartTree.java @@ -202,17 +202,16 @@ public class PartTree implements Iterable { */ private static class Predicate { - private static Pattern ALL_IGNORE_CASE = Pattern.compile("AllIgnor(ing|e)Case"); + private static final Pattern ALL_IGNORE_CASE = Pattern.compile("AllIgnor(ing|e)Case"); private static final String ORDER_BY = "OrderBy"; private final List nodes = new ArrayList(); - private OrderBySource orderBySource; + private final OrderBySource orderBySource; private boolean alwaysIgnoreCase; public Predicate(String predicate, Class domainClass) { - predicate = detectAndSetAllIgnoreCase(predicate); - String[] parts = split(predicate, ORDER_BY); + String[] parts = split(detectAndSetAllIgnoreCase(predicate), ORDER_BY); if (parts.length > 2) { throw new IllegalArgumentException("OrderBy must not be used more than once in a method name!"); diff --git a/spring-data-commons-core/src/main/java/org/springframework/data/repository/query/parser/Property.java b/spring-data-commons-core/src/main/java/org/springframework/data/repository/query/parser/Property.java index 158a1eb01..b5492de98 100644 --- a/spring-data-commons-core/src/main/java/org/springframework/data/repository/query/parser/Property.java +++ b/spring-data-commons-core/src/main/java/org/springframework/data/repository/query/parser/Property.java @@ -190,7 +190,7 @@ public class Property { Property that = (Property) obj; - return this.name.equals(that.name) && this.type.equals(type); + return this.name.equals(that.name) && this.type.equals(that.type); } /* diff --git a/spring-data-commons-core/src/main/java/org/springframework/data/repository/support/DomainClassPropertyEditor.java b/spring-data-commons-core/src/main/java/org/springframework/data/repository/support/DomainClassPropertyEditor.java index e63103a35..0d090dffb 100644 --- a/spring-data-commons-core/src/main/java/org/springframework/data/repository/support/DomainClassPropertyEditor.java +++ b/spring-data-commons-core/src/main/java/org/springframework/data/repository/support/DomainClassPropertyEditor.java @@ -41,14 +41,15 @@ public class DomainClassPropertyEditor extends Prope * Creates a new {@link DomainClassPropertyEditor} for the given {@link CrudRepository}, {@link EntityInformation} and * {@link PropertyEditorRegistry}. * - * @param repository - * @param information - * @param registry + * @param repository must not be {@literal null}. + * @param information must not be {@literal null}. + * @param registry must not be {@literal null}. */ public DomainClassPropertyEditor(CrudRepository repository, EntityInformation information, PropertyEditorRegistry registry) { Assert.notNull(repository); + Assert.notNull(information); Assert.notNull(registry); this.repository = repository; @@ -57,12 +58,11 @@ public class DomainClassPropertyEditor extends Prope } /* - * (non-Javadoc) - * - * @see java.beans.PropertyEditorSupport#setAsText(java.lang.String) - */ + * (non-Javadoc) + * @see java.beans.PropertyEditorSupport#setAsText(java.lang.String) + */ @Override - public void setAsText(String idAsString) throws IllegalArgumentException { + public void setAsText(String idAsString) { if (!StringUtils.hasText(idAsString)) { setValue(null); @@ -73,10 +73,9 @@ public class DomainClassPropertyEditor extends Prope } /* - * (non-Javadoc) - * - * @see java.beans.PropertyEditorSupport#getAsText() - */ + * (non-Javadoc) + * @see java.beans.PropertyEditorSupport#getAsText() + */ @Override @SuppressWarnings("unchecked") public String getAsText() { @@ -127,10 +126,9 @@ public class DomainClassPropertyEditor extends Prope } /* - * (non-Javadoc) - * - * @see java.lang.Object#equals(java.lang.Object) - */ + * (non-Javadoc) + * @see java.lang.Object#equals(java.lang.Object) + */ @Override public boolean equals(Object obj) { @@ -149,10 +147,9 @@ public class DomainClassPropertyEditor extends Prope } /* - * (non-Javadoc) - * - * @see java.lang.Object#hashCode() - */ + * (non-Javadoc) + * @see java.lang.Object#hashCode() + */ @Override public int hashCode() { diff --git a/spring-data-commons-core/src/main/java/org/springframework/data/repository/util/ClassUtils.java b/spring-data-commons-core/src/main/java/org/springframework/data/repository/util/ClassUtils.java index 58d4df382..17d888c41 100644 --- a/spring-data-commons-core/src/main/java/org/springframework/data/repository/util/ClassUtils.java +++ b/spring-data-commons-core/src/main/java/org/springframework/data/repository/util/ClassUtils.java @@ -22,7 +22,6 @@ import java.lang.reflect.Type; import java.util.Arrays; import java.util.Collection; -import org.springframework.data.domain.Page; import org.springframework.data.repository.Repository; import org.springframework.util.ReflectionUtils; import org.springframework.util.StringUtils; diff --git a/spring-data-commons-core/src/main/java/org/springframework/data/util/ClassTypeInformation.java b/spring-data-commons-core/src/main/java/org/springframework/data/util/ClassTypeInformation.java index 641d32cec..ee3a6dc76 100644 --- a/spring-data-commons-core/src/main/java/org/springframework/data/util/ClassTypeInformation.java +++ b/spring-data-commons-core/src/main/java/org/springframework/data/util/ClassTypeInformation.java @@ -18,10 +18,8 @@ package org.springframework.data.util; import java.lang.reflect.Method; import java.lang.reflect.Type; import java.lang.reflect.TypeVariable; -import java.util.Collection; import java.util.Map; -import org.springframework.core.GenericCollectionTypeResolver; import org.springframework.util.Assert; /** diff --git a/spring-data-commons-core/src/main/java/org/springframework/data/util/GenericArrayTypeInformation.java b/spring-data-commons-core/src/main/java/org/springframework/data/util/GenericArrayTypeInformation.java index 6e8828c07..dd82e9df8 100644 --- a/spring-data-commons-core/src/main/java/org/springframework/data/util/GenericArrayTypeInformation.java +++ b/spring-data-commons-core/src/main/java/org/springframework/data/util/GenericArrayTypeInformation.java @@ -40,9 +40,10 @@ class GenericArrayTypeInformation extends ParameterizedTypeInformation { this.type = type; } - /* (non-Javadoc) - * @see org.springframework.data.util.TypeDiscoverer#getType() - */ + /* + * (non-Javadoc) + * @see org.springframework.data.util.TypeDiscoverer#getType() + */ @Override @SuppressWarnings("unchecked") public Class getType() { @@ -50,9 +51,10 @@ class GenericArrayTypeInformation extends ParameterizedTypeInformation { return (Class) Array.newInstance(resolveType(type.getGenericComponentType()), 0).getClass(); } - /* (non-Javadoc) - * @see org.springframework.data.util.TypeDiscoverer#getComponentType() - */ + /* + * (non-Javadoc) + * @see org.springframework.data.util.TypeDiscoverer#getComponentType() + */ @Override public TypeInformation getComponentType() { diff --git a/spring-data-commons-core/src/main/java/org/springframework/data/util/TypeDiscoverer.java b/spring-data-commons-core/src/main/java/org/springframework/data/util/TypeDiscoverer.java index ad6be4f7e..c31616746 100644 --- a/spring-data-commons-core/src/main/java/org/springframework/data/util/TypeDiscoverer.java +++ b/spring-data-commons-core/src/main/java/org/springframework/data/util/TypeDiscoverer.java @@ -141,7 +141,7 @@ class TypeDiscoverer implements TypeInformation { */ public TypeInformation getProperty(String fieldname) { - int separatorIndex = fieldname.indexOf("."); + int separatorIndex = fieldname.indexOf('.'); if (separatorIndex == -1) { if (fieldTypes.containsKey(fieldname)) { @@ -235,8 +235,7 @@ class TypeDiscoverer implements TypeInformation { * @see org.springframework.data.util.TypeInformation#isMap() */ public boolean isMap() { - Class rawType = getType(); - return rawType == null ? false : Map.class.isAssignableFrom(rawType); + return Map.class.isAssignableFrom(getType()); } /* (non-Javadoc) @@ -267,7 +266,7 @@ class TypeDiscoverer implements TypeInformation { public boolean isCollectionLike() { Class rawType = getType(); - return rawType == null ? null : rawType.isArray() || Iterable.class.isAssignableFrom(rawType); + return rawType.isArray() || Iterable.class.isAssignableFrom(rawType); } /* (non-Javadoc) diff --git a/spring-data-commons-core/src/main/java/org/springframework/data/util/TypeInformation.java b/spring-data-commons-core/src/main/java/org/springframework/data/util/TypeInformation.java index e3912bd6d..f6a6a4e5d 100644 --- a/spring-data-commons-core/src/main/java/org/springframework/data/util/TypeInformation.java +++ b/spring-data-commons-core/src/main/java/org/springframework/data/util/TypeInformation.java @@ -1,10 +1,23 @@ +/* + * Copyright 2008-2011 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package org.springframework.data.util; -import java.lang.reflect.Array; import java.lang.reflect.Constructor; -import java.util.Collection; + import java.util.List; -import java.util.Map; /** * Interface to access property types and resolving generics on the way. Starting with a {@link ClassTypeInformation} @@ -27,22 +40,22 @@ public interface TypeInformation { /** * Returns whether the type can be considered a collection, which means it's a container of elements, e.g. a - * {@link Collection} and {@link Array} or anything implementing {@link Iterable}. If this returns {@literal true} you - * can expect {@link #getComponentType()} to return a non-{@literal null} value. + * {@link java.util.Collection} and {@link java.lang.reflect.Array} or anything implementing {@link Iterable}. If this + * returns {@literal true} you can expect {@link #getComponentType()} to return a non-{@literal null} value. * * @return */ boolean isCollectionLike(); /** - * Returns the component type for {@link Collection}s or the key type for {@link Map}s. + * Returns the component type for {@link java.util.Collection}s or the key type for {@link java.util.Map}s. * * @return */ TypeInformation getComponentType(); /** - * Returns whether the property is a {@link Map}. If this returns {@literal true} you can expect + * Returns whether the property is a {@link java.util.Map}. If this returns {@literal true} you can expect * {@link #getComponentType()} as well as {@link #getMapValueType()} to return something not {@literal null}. * * @return @@ -50,7 +63,7 @@ public interface TypeInformation { boolean isMap(); /** - * Will return the type of the value in case the underlying type is a {@link Map}. + * Will return the type of the value in case the underlying type is a {@link java.util.Map}. * * @return */ @@ -64,8 +77,8 @@ public interface TypeInformation { Class getType(); /** - * Transparently returns the {@link Map} value type if the type is a {@link Map}, returns the component type if the - * type {@link #isCollectionLike()} or the simple type if none of this applies. + * Transparently returns the {@link java.util.Map} value type if the type is a {@link java.util.Map}, returns the + * component type if the type {@link #isCollectionLike()} or the simple type if none of this applies. * * @return */ diff --git a/spring-data-commons-core/src/main/java/org/springframework/data/web/PageableArgumentResolver.java b/spring-data-commons-core/src/main/java/org/springframework/data/web/PageableArgumentResolver.java index b639c0f81..8a1c9e5bd 100644 --- a/spring-data-commons-core/src/main/java/org/springframework/data/web/PageableArgumentResolver.java +++ b/spring-data-commons-core/src/main/java/org/springframework/data/web/PageableArgumentResolver.java @@ -261,12 +261,11 @@ public class PageableArgumentResolver implements WebArgumentResolver { } /* - * (non-Javadoc) - * - * @see java.beans.PropertyEditorSupport#setAsText(java.lang.String) - */ + * (non-Javadoc) + * @see java.beans.PropertyEditorSupport#setAsText(java.lang.String) + */ @Override - public void setAsText(String text) throws IllegalArgumentException { + public void setAsText(String text) { PropertyValue rawOrder = values.getPropertyValue(orderProperty); Direction order = null == rawOrder ? Direction.ASC : Direction.fromString(rawOrder.getValue().toString());