/*
* Copyright 2016-2020 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
*
* https://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.support;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
import java.util.Collection;
import org.springframework.data.domain.ExampleMatcher;
import org.springframework.data.domain.ExampleMatcher.PropertySpecifier;
import org.springframework.data.domain.ExampleMatcher.StringMatcher;
Accessor for the ExampleMatcher
to use in modules that support query by example (QBE) querying. Author: Mark Paluch, Oliver Gierke, Christoph Strobl, Jens Schauder Since: 1.12
/**
* Accessor for the {@link ExampleMatcher} to use in modules that support query by example (QBE) querying.
*
* @author Mark Paluch
* @author Oliver Gierke
* @author Christoph Strobl
* @author Jens Schauder
* @since 1.12
*/
@RequiredArgsConstructor
public class ExampleMatcherAccessor {
private final @NonNull ExampleMatcher matcher;
Returns the PropertySpecifier
s of the underlying ExampleMatcher
. Returns: unmodifiable Collection
of PropertySpecifier
s.
/**
* Returns the {@link PropertySpecifier}s of the underlying {@link ExampleMatcher}.
*
* @return unmodifiable {@link Collection} of {@link ExampleMatcher.PropertySpecifier}s.
*/
public Collection<ExampleMatcher.PropertySpecifier> getPropertySpecifiers() {
return matcher.getPropertySpecifiers().getSpecifiers();
}
Returns whether the underlying ExampleMatcher
contains a PropertySpecifier
for the given path. Params: - path – the dot-path identifying a property.
Returns: true in case PropertySpecifier
defined for given path.
/**
* Returns whether the underlying {@link ExampleMatcher} contains a {@link PropertySpecifier} for the given path.
*
* @param path the dot-path identifying a property.
* @return {@literal true} in case {@link ExampleMatcher.PropertySpecifier} defined for given path.
*/
public boolean hasPropertySpecifier(String path) {
return matcher.getPropertySpecifiers().hasSpecifierForPath(path);
}
Get the PropertySpecifier
for given path.
Please check if hasPropertySpecifier(String)
to avoid running into null values. Params: - path – Dot-Path to property.
Returns: null when no PropertySpecifier
defined for path.
/**
* Get the {@link ExampleMatcher.PropertySpecifier} for given path. <br />
* Please check if {@link #hasPropertySpecifier(String)} to avoid running into {@literal null} values.
*
* @param path Dot-Path to property.
* @return {@literal null} when no {@link ExampleMatcher.PropertySpecifier} defined for path.
*/
public ExampleMatcher.PropertySpecifier getPropertySpecifier(String path) {
return matcher.getPropertySpecifiers().getForPath(path);
}
Returns: true if at least one PropertySpecifier
defined.
/**
* @return true if at least one {@link ExampleMatcher.PropertySpecifier} defined.
*/
public boolean hasPropertySpecifiers() {
return matcher.getPropertySpecifiers().hasValues();
}
Get the StringMatcher
for a given path or return the default one if none defined. Params: - path –
Returns: never null.
/**
* Get the {@link ExampleMatcher.StringMatcher} for a given path or return the default one if none defined.
*
* @param path
* @return never {@literal null}.
*/
public ExampleMatcher.StringMatcher getStringMatcherForPath(String path) {
if (!hasPropertySpecifier(path)) {
return matcher.getDefaultStringMatcher();
}
ExampleMatcher.PropertySpecifier specifier = getPropertySpecifier(path);
StringMatcher stringMatcher = specifier.getStringMatcher();
return stringMatcher != null ? stringMatcher : matcher.getDefaultStringMatcher();
}
Get defined null handling.
Returns: never null
/**
* Get defined null handling.
*
* @return never {@literal null}
*/
public ExampleMatcher.NullHandler getNullHandler() {
return matcher.getNullHandler();
}
Get defined StringMatcher
. Returns: never null.
/**
* Get defined {@link ExampleMatcher.StringMatcher}.
*
* @return never {@literal null}.
*/
public ExampleMatcher.StringMatcher getDefaultStringMatcher() {
return matcher.getDefaultStringMatcher();
}
Returns: true if String
should be matched with ignore case option.
/**
* @return {@literal true} if {@link String} should be matched with ignore case option.
*/
public boolean isIgnoreCaseEnabled() {
return matcher.isIgnoreCaseEnabled();
}
Params: - path –
Returns: return true if path was set to be ignored.
/**
* @param path
* @return return {@literal true} if path was set to be ignored.
*/
public boolean isIgnoredPath(String path) {
return matcher.isIgnoredPath(path);
}
Get the ignore case flag for a given path or return the default one if none defined.
Params: - path –
Returns: never null.
/**
* Get the ignore case flag for a given path or return the default one if none defined.
*
* @param path
* @return never {@literal null}.
*/
public boolean isIgnoreCaseForPath(String path) {
if (!hasPropertySpecifier(path)) {
return matcher.isIgnoreCaseEnabled();
}
ExampleMatcher.PropertySpecifier specifier = getPropertySpecifier(path);
Boolean ignoreCase = specifier.getIgnoreCase();
return ignoreCase != null ? ignoreCase : matcher.isIgnoreCaseEnabled();
}
Get the ignore case flag for a given path or return NoOpPropertyValueTransformer
if none defined. Params: - path –
Returns: never null.
/**
* Get the ignore case flag for a given path or return {@link ExampleMatcher.NoOpPropertyValueTransformer} if none
* defined.
*
* @param path
* @return never {@literal null}.
*/
public ExampleMatcher.PropertyValueTransformer getValueTransformerForPath(String path) {
if (!hasPropertySpecifier(path)) {
return ExampleMatcher.NoOpPropertyValueTransformer.INSTANCE;
}
return getPropertySpecifier(path).getPropertyValueTransformer();
}
}