Skip to content

Commit

Permalink
[style] use StringUtils.hasText() (#858)
Browse files Browse the repository at this point in the history
Co-authored-by: Carpe-Wang <wangcarpe@126.com>
  • Loading branch information
Carpe-Wang and Carpe-Wang authored Apr 8, 2023
1 parent 36be42a commit 9a3f7ac
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
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

0 comments on commit 9a3f7ac

Please sign in to comment.