Browse Source

DATACMNS-1141 - Polishing.

Remove superfluous null checks in places where state cannot be null. Add nullable annotations to nullable variables. Remove whitespaces.
pull/236/merge
Mark Paluch 9 years ago
parent
commit
67f52d5d70
  1. 8
      src/main/java/org/springframework/data/mapping/Association.java
  2. 11
      src/main/java/org/springframework/data/repository/init/Jackson2ResourceReader.java
  3. 24
      src/main/java/org/springframework/data/repository/init/ResourceReaderRepositoryPopulator.java
  4. 14
      src/main/java/org/springframework/data/repository/query/parser/OrderBySource.java
  5. 34
      src/main/java/org/springframework/data/repository/query/parser/PartTree.java

8
src/main/java/org/springframework/data/mapping/Association.java

@ -13,9 +13,10 @@ @@ -13,9 +13,10 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.data.mapping;
import org.springframework.lang.Nullable;
/**
* Value object to capture {@link Association}s.
*
@ -26,7 +27,7 @@ package org.springframework.data.mapping; @@ -26,7 +27,7 @@ package org.springframework.data.mapping;
public class Association<P extends PersistentProperty<P>> {
private final P inverse;
private final P obverse;
private final @Nullable P obverse;
/**
* Creates a new {@link Association} between the two given {@link PersistentProperty}s.
@ -34,7 +35,7 @@ public class Association<P extends PersistentProperty<P>> { @@ -34,7 +35,7 @@ public class Association<P extends PersistentProperty<P>> {
* @param inverse
* @param obverse
*/
public Association(P inverse, P obverse) {
public Association(P inverse, @Nullable P obverse) {
this.inverse = inverse;
this.obverse = obverse;
}
@ -43,6 +44,7 @@ public class Association<P extends PersistentProperty<P>> { @@ -43,6 +44,7 @@ public class Association<P extends PersistentProperty<P>> {
return inverse;
}
@Nullable
public P getObverse() {
return obverse;
}

11
src/main/java/org/springframework/data/repository/init/Jackson2ResourceReader.java

@ -33,9 +33,10 @@ import com.fasterxml.jackson.databind.ObjectMapper; @@ -33,9 +33,10 @@ import com.fasterxml.jackson.databind.ObjectMapper;
/**
* A {@link ResourceReader} using Jackson to read JSON into objects.
*
*
* @author Oliver Gierke
* @author Christoph Strobl
* @author Mark Paluch
* @since 1.6
*/
public class Jackson2ResourceReader implements ResourceReader {
@ -59,7 +60,7 @@ public class Jackson2ResourceReader implements ResourceReader { @@ -59,7 +60,7 @@ public class Jackson2ResourceReader implements ResourceReader {
/**
* Creates a new {@link Jackson2ResourceReader} using the given {@link ObjectMapper}.
*
*
* @param mapper
*/
public Jackson2ResourceReader(@Nullable ObjectMapper mapper) {
@ -69,7 +70,7 @@ public class Jackson2ResourceReader implements ResourceReader { @@ -69,7 +70,7 @@ public class Jackson2ResourceReader implements ResourceReader {
/**
* Configures the JSON document's key to lookup the type to instantiate the object. Defaults to
* {@link Jackson2ResourceReader#DEFAULT_TYPE_KEY}.
*
*
* @param typeKey
*/
public void setTypeKey(@Nullable String typeKey) {
@ -105,7 +106,7 @@ public class Jackson2ResourceReader implements ResourceReader { @@ -105,7 +106,7 @@ public class Jackson2ResourceReader implements ResourceReader {
/**
* Reads the given {@link JsonNode} into an instance of the type encoded in it using the configured type key.
*
*
* @param node must not be {@literal null}.
* @param classLoader can be {@literal null}.
* @return
@ -118,7 +119,7 @@ public class Jackson2ResourceReader implements ResourceReader { @@ -118,7 +119,7 @@ public class Jackson2ResourceReader implements ResourceReader {
throw new IllegalArgumentException(String.format("Could not find type for type key '%s'!", typeKey));
}
String typeName = typeNode == null ? null : typeNode.asText();
String typeName = typeNode.asText();
Class<?> type = ClassUtils.resolveClassName(typeName, classLoader);
return mapper.readerFor(type).readValue(node);

24
src/main/java/org/springframework/data/repository/init/ResourceReaderRepositoryPopulator.java

@ -36,7 +36,7 @@ import org.springframework.util.Assert; @@ -36,7 +36,7 @@ import org.springframework.util.Assert;
/**
* A {@link RepositoryPopulator} using a {@link ResourceReader} to read objects from the configured {@link Resource}s.
*
*
* @author Oliver Gierke
* @author Christoph Strobl
* @since 1.4
@ -45,16 +45,16 @@ public class ResourceReaderRepositoryPopulator implements RepositoryPopulator, A @@ -45,16 +45,16 @@ public class ResourceReaderRepositoryPopulator implements RepositoryPopulator, A
private static final Logger LOGGER = LoggerFactory.getLogger(ResourceReaderRepositoryPopulator.class);
private final ResourcePatternResolver resolver;
private final ResourceReader reader;
private final ClassLoader classLoader;
private final @Nullable ClassLoader classLoader;
private final ResourcePatternResolver resolver;
private @Nullable ApplicationEventPublisher publisher;
private Collection<Resource> resources = Collections.emptySet();
/**
* Creates a new {@link ResourceReaderRepositoryPopulator} using the given {@link ResourceReader}.
*
*
* @param reader must not be {@literal null}.
*/
public ResourceReaderRepositoryPopulator(ResourceReader reader) {
@ -64,7 +64,7 @@ public class ResourceReaderRepositoryPopulator implements RepositoryPopulator, A @@ -64,7 +64,7 @@ public class ResourceReaderRepositoryPopulator implements RepositoryPopulator, A
/**
* Creates a new {@link ResourceReaderRepositoryPopulator} using the given {@link ResourceReader} and
* {@link ClassLoader}.
*
*
* @param reader must not be {@literal null}.
* @param classLoader can be {@literal null}.
*/
@ -80,7 +80,7 @@ public class ResourceReaderRepositoryPopulator implements RepositoryPopulator, A @@ -80,7 +80,7 @@ public class ResourceReaderRepositoryPopulator implements RepositoryPopulator, A
/**
* Configures the location of the {@link Resource}s to be used to initialize the repositories.
*
*
* @param location must not be {@literal null} or empty.
* @throws IOException
*/
@ -91,22 +91,22 @@ public class ResourceReaderRepositoryPopulator implements RepositoryPopulator, A @@ -91,22 +91,22 @@ public class ResourceReaderRepositoryPopulator implements RepositoryPopulator, A
/**
* Configures the {@link Resource}s to be used to initialize the repositories.
*
*
* @param resources
*/
public void setResources(Resource... resources) {
this.resources = Arrays.asList(resources);
}
/*
/*
* (non-Javadoc)
* @see org.springframework.context.ApplicationEventPublisherAware#setApplicationEventPublisher(org.springframework.context.ApplicationEventPublisher)
*/
public void setApplicationEventPublisher(@Nullable ApplicationEventPublisher publisher) {
public void setApplicationEventPublisher(ApplicationEventPublisher publisher) {
this.publisher = publisher;
}
/*
/*
* (non-Javadoc)
* @see org.springframework.data.repository.init.RepositoryPopulator#initialize()
*/
@ -142,7 +142,7 @@ public class ResourceReaderRepositoryPopulator implements RepositoryPopulator, A @@ -142,7 +142,7 @@ public class ResourceReaderRepositoryPopulator implements RepositoryPopulator, A
/**
* Reads the given resource into an {@link Object} using the configured {@link ResourceReader}.
*
*
* @param resource must not be {@literal null}.
* @return
*/
@ -156,7 +156,7 @@ public class ResourceReaderRepositoryPopulator implements RepositoryPopulator, A @@ -156,7 +156,7 @@ public class ResourceReaderRepositoryPopulator implements RepositoryPopulator, A
/**
* Persists the given {@link Object} using a suitable repository.
*
*
* @param object must not be {@literal null}.
* @param invokerFactory must not be {@literal null}.
*/

14
src/main/java/org/springframework/data/repository/query/parser/OrderBySource.java

@ -34,14 +34,14 @@ import org.springframework.util.StringUtils; @@ -34,14 +34,14 @@ import org.springframework.util.StringUtils;
* Simple helper class to create a {@link Sort} instance from a method name end. It expects the last part of the method
* name to be given and supports lining up multiple properties ending with the sorting direction. So the following
* method ends are valid: {@code LastnameUsernameDesc}, {@code LastnameAscUsernameDesc}.
*
*
* @author Oliver Gierke
* @author Christoph Strobl
* @author Mark Paluch
*/
class OrderBySource {
public static OrderBySource EMPTY = new OrderBySource("");
static OrderBySource EMPTY = new OrderBySource("");
private static final String BLOCK_SPLIT = "(?<=Asc|Desc)(?=\\p{Lu})";
private static final Pattern DIRECTION_SPLIT = Pattern.compile("(.+?)(Asc|Desc)?$");
@ -53,7 +53,7 @@ class OrderBySource { @@ -53,7 +53,7 @@ class OrderBySource {
/**
* Creates a new {@link OrderBySource} for the given String clause not doing any checks whether the referenced
* property actually exists.
*
*
* @param clause must not be {@literal null}.
*/
OrderBySource(String clause) {
@ -63,7 +63,7 @@ class OrderBySource { @@ -63,7 +63,7 @@ class OrderBySource {
/**
* Creates a new {@link OrderBySource} for the given clause, checking the property referenced exists on the given
* type.
*
*
* @param clause must not be {@literal null}.
* @param domainClass must not be {@literal null}.
*/
@ -98,7 +98,7 @@ class OrderBySource { @@ -98,7 +98,7 @@ class OrderBySource {
/**
* Creates an {@link Order} instance from the given property source, direction and domain class. If the domain class
* is given, we will use it for nested property traversal checks.
*
*
* @param propertySource
* @param direction must not be {@literal null}.
* @param domainClass must not be {@literal null}.
@ -120,10 +120,10 @@ class OrderBySource { @@ -120,10 +120,10 @@ class OrderBySource {
/**
* Returns the clause as {@link Sort}.
*
*
* @return the {@link Sort}.
*/
public Sort toSort() {
Sort toSort() {
return Sort.by(this.orders);
}

34
src/main/java/org/springframework/data/repository/query/parser/PartTree.java

@ -38,7 +38,7 @@ import org.springframework.util.StringUtils; @@ -38,7 +38,7 @@ import org.springframework.util.StringUtils;
* Takes a domain class as well to validate that each of the {@link Part}s are referring to a property of the domain
* class. The {@link PartTree} can then be used to build queries based on its API instead of parsing the method name for
* each query execution.
*
*
* @author Oliver Gierke
* @author Thomas Darimont
* @author Christoph Strobl
@ -76,7 +76,7 @@ public class PartTree implements Streamable<OrPart> { @@ -76,7 +76,7 @@ public class PartTree implements Streamable<OrPart> {
/**
* Creates a new {@link PartTree} by parsing the given {@link String}.
*
*
* @param source the {@link String} to parse
* @param domainClass the domain class to check individual parts against to ensure they refer to a property of the
* class
@ -116,7 +116,7 @@ public class PartTree implements Streamable<OrPart> { @@ -116,7 +116,7 @@ public class PartTree implements Streamable<OrPart> {
/**
* Returns whether we indicate distinct lookup of entities.
*
*
* @return {@literal true} if distinct
*/
public boolean isDistinct() {
@ -125,7 +125,7 @@ public class PartTree implements Streamable<OrPart> { @@ -125,7 +125,7 @@ public class PartTree implements Streamable<OrPart> {
/**
* Returns whether a count projection shall be applied.
*
*
* @return
*/
public boolean isCountProjection() {
@ -144,7 +144,7 @@ public class PartTree implements Streamable<OrPart> { @@ -144,7 +144,7 @@ public class PartTree implements Streamable<OrPart> {
/**
* return true if the created {@link PartTree} is meant to be used for delete operation.
*
*
* @return
* @since 1.8
*/
@ -154,7 +154,7 @@ public class PartTree implements Streamable<OrPart> { @@ -154,7 +154,7 @@ public class PartTree implements Streamable<OrPart> {
/**
* Return {@literal true} if the create {@link PartTree} is meant to be used for a query with limited maximal results.
*
*
* @return
* @since 1.9
*/
@ -164,7 +164,7 @@ public class PartTree implements Streamable<OrPart> { @@ -164,7 +164,7 @@ public class PartTree implements Streamable<OrPart> {
/**
* Return the number of maximal results to return or {@literal null} if not restricted.
*
*
* @return {@literal null} if not restricted.
* @since 1.9
*/
@ -175,7 +175,7 @@ public class PartTree implements Streamable<OrPart> { @@ -175,7 +175,7 @@ public class PartTree implements Streamable<OrPart> {
/**
* Returns an {@link Iterable} of all parts contained in the {@link PartTree}.
*
*
* @return the iterable {@link Part}s
*/
public Streamable<Part> getParts() {
@ -184,7 +184,7 @@ public class PartTree implements Streamable<OrPart> { @@ -184,7 +184,7 @@ public class PartTree implements Streamable<OrPart> {
/**
* Returns all {@link Part}s of the {@link PartTree} of the given {@link Type}.
*
*
* @param type
* @return
*/
@ -194,7 +194,7 @@ public class PartTree implements Streamable<OrPart> { @@ -194,7 +194,7 @@ public class PartTree implements Streamable<OrPart> {
/**
* Returns whether the {@link PartTree} contains predicate {@link Part}s.
*
*
* @return
*/
public boolean hasPredicate() {
@ -215,7 +215,7 @@ public class PartTree implements Streamable<OrPart> { @@ -215,7 +215,7 @@ public class PartTree implements Streamable<OrPart> {
/**
* Splits the given text at the given keywords. Expects camel-case style to only match concrete keywords and not
* derivatives of it.
*
*
* @param text the text to split
* @param keyword the keyword to split around
* @return an array of split items
@ -236,7 +236,7 @@ public class PartTree implements Streamable<OrPart> { @@ -236,7 +236,7 @@ public class PartTree implements Streamable<OrPart> {
/**
* Creates a new {@link OrPart}.
*
*
* @param source the source to split up into {@literal And} parts in turn.
* @param domainClass the domain class to check the resulting {@link Part}s against.
* @param alwaysIgnoreCase if always ignoring case
@ -264,7 +264,7 @@ public class PartTree implements Streamable<OrPart> { @@ -264,7 +264,7 @@ public class PartTree implements Streamable<OrPart> {
/**
* Represents the subject part of the query. E.g. {@code findDistinctUserByNameOrderByAge} would have the subject
* {@code DistinctUser}.
*
*
* @author Phil Webb
* @author Oliver Gierke
* @author Christoph Strobl
@ -317,7 +317,7 @@ public class PartTree implements Streamable<OrPart> { @@ -317,7 +317,7 @@ public class PartTree implements Streamable<OrPart> {
/**
* Returns {@literal true} if {@link Subject} matches {@link #DELETE_BY_TEMPLATE}.
*
*
* @return
* @since 1.8
*/
@ -354,7 +354,7 @@ public class PartTree implements Streamable<OrPart> { @@ -354,7 +354,7 @@ public class PartTree implements Streamable<OrPart> {
/**
* Represents the predicate part of the query.
*
*
* @author Oliver Gierke
* @author Phil Webb
*/
@ -376,7 +376,7 @@ public class PartTree implements Streamable<OrPart> { @@ -376,7 +376,7 @@ public class PartTree implements Streamable<OrPart> {
}
this.nodes = Arrays.stream(split(parts[0], "Or")) //
.filter(part -> StringUtils.hasText(part)) //
.filter(StringUtils::hasText) //
.map(part -> new OrPart(part, domainClass, alwaysIgnoreCase)) //
.collect(Collectors.toList());
@ -396,7 +396,7 @@ public class PartTree implements Streamable<OrPart> { @@ -396,7 +396,7 @@ public class PartTree implements Streamable<OrPart> {
return predicate;
}
/*
/*
* (non-Javadoc)
* @see java.lang.Iterable#iterator()
*/

Loading…
Cancel
Save