Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[style] use StringUtils.hasText() #858

Merged
merged 1 commit into from
Apr 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import org.springframework.data.domain.Sort;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.http.ResponseEntity;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
Expand Down Expand Up @@ -80,7 +81,7 @@ public ResponseEntity<Message<Page<Monitor>>> getMonitors(
}
andList.add(inPredicate);
}
if (app != null && !app.chars().allMatch(Character::isSpaceChar)) {
if (StringUtils.hasText(app)) {
Predicate predicateApp = criteriaBuilder.equal(root.get("app"), app);
andList.add(predicateApp);
}
Expand All @@ -92,11 +93,11 @@ public ResponseEntity<Message<Page<Monitor>>> getMonitors(
Predicate andPredicate = criteriaBuilder.and(andList.toArray(andPredicates));

List<Predicate> orList = new ArrayList<>();
if (host != null && !host.chars().allMatch(Character::isSpaceChar)) {
if (StringUtils.hasText(host)) {
Predicate predicateHost = criteriaBuilder.like(root.get("host"), "%" + host + "%");
orList.add(predicateHost);
}
if (name != null && !name.chars().allMatch(Character::isSpaceChar)) {
if (StringUtils.hasText(name)) {
Predicate predicateName = criteriaBuilder.like(root.get("name"), "%" + name + "%");
orList.add(predicateName);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public class AppServiceImpl implements AppService, CommandLineRunner {

@Override
public List<ParamDefine> getAppParamDefines(String app) {
if (app == null || app.chars().allMatch(Character::isSpaceChar)) {
if (!StringUtils.hasText(app)) {
return Collections.emptyList();
}
Job appDefine = appDefines.get(app.toLowerCase());
Expand All @@ -82,7 +82,7 @@ public List<ParamDefine> getAppParamDefines(String app) {

@Override
public Job getAppDefine(String app) throws IllegalArgumentException {
if (app == null || app.chars().allMatch(Character::isSpaceChar)) {
if (!StringUtils.hasText(app)) {
throw new IllegalArgumentException("The app can not null.");
}
Job appDefine = appDefines.get(app.toLowerCase());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;

import java.time.LocalDateTime;
import java.util.*;
Expand Down Expand Up @@ -273,7 +274,7 @@ public void validate(MonitorDto monitorDto, Boolean isModify) throws IllegalArgu
param.setType(CommonConstants.PARAM_TYPE_NUMBER);
break;
case "textarea":
if (param.getValue().chars().allMatch(Character::isSpaceChar)){
if (StringUtils.hasText(param.getValue())){
throw new IllegalArgumentException("Params field " + field + " type "
+ paramDefine.getType() + " over limit " + param.getValue());
}
Expand Down