Skip to content

Commit

Permalink
Use is(Not)Blank instead of is(Not)Empty
Browse files Browse the repository at this point in the history
This also considers non-empty strings that consist of white space only
as empty, which, as far as I can see, is the more correct choice in all
places.
  • Loading branch information
matthias-ronge committed May 21, 2024
1 parent 797f7a4 commit 77ba25a
Show file tree
Hide file tree
Showing 14 changed files with 18 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ default String getWorkflowStatus() {
*/
@Deprecated
default void setWorkflowStatus(String status) {
setStatus(StringUtils.isNotEmpty(status) ? WorkflowStatus.valueOf(status) : null);
setStatus(StringUtils.isNotBlank(status) ? WorkflowStatus.valueOf(status) : null);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public class IllustratedSelectItemConverter implements Converter, Serializable {

@Override
public Object getAsObject(FacesContext context, UIComponent component, String value) {
if (StringUtils.isNotEmpty(value)) {
if (StringUtils.isNotBlank(value)) {
List<IllustratedSelectItem> illustratedSelectItems = (List<IllustratedSelectItem>) component.getAttributes()
.get("illustratedSelectItems");
for (IllustratedSelectItem illustratedSelectItem : illustratedSelectItems) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public class OcrdWorkflowConverter extends BeanConverter implements Converter<Ob

@Override
public Object getAsObject(FacesContext context, UIComponent component, String value) {
if (StringUtils.isNotEmpty(value)) {
if (StringUtils.isNotBlank(value)) {
return ServiceManager.getOcrdWorkflowService().getOcrdWorkflow(value);
}
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ public void setTasks(List<? extends TaskInterface> tasks) {
*/
public Date getCreationDate() {
try {
return StringUtils.isNotEmpty(this.creationDate)
return StringUtils.isNotBlank(this.creationDate)
? new SimpleDateFormat(DATE_FORMAT).parse(this.creationDate)
: null;
} catch (ParseException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ public void setHasProcesses(boolean hasProcesses) {
@Override
public Date getStartDate() {
try {
return StringUtils.isNotEmpty(this.startDate) ? new SimpleDateFormat(DATE_FORMAT).parse(this.startDate)
return StringUtils.isNotBlank(this.startDate) ? new SimpleDateFormat(DATE_FORMAT).parse(this.startDate)
: null;
} catch (ParseException e) {
throw new IllegalStateException(e.getMessage(), e);
Expand All @@ -332,7 +332,7 @@ public void setStartDate(Date startDate) {
@Override
public Date getEndDate() {
try {
return StringUtils.isNotEmpty(this.endDate) ? new SimpleDateFormat(DATE_FORMAT).parse(this.endDate) : null;
return StringUtils.isNotBlank(this.endDate) ? new SimpleDateFormat(DATE_FORMAT).parse(this.endDate) : null;
} catch (ParseException e) {
throw new IllegalStateException(e.getMessage(), e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public void setCreationTime(String creationDate) {
@Override
public Date getCreationDate() {
try {
return StringUtils.isNotEmpty(this.creationDate)
return StringUtils.isNotBlank(this.creationDate)
? new SimpleDateFormat(DATE_FORMAT).parse(this.creationDate)
: null;
} catch (ParseException e) {
Expand Down
6 changes: 3 additions & 3 deletions Kitodo/src/main/java/org/kitodo/production/dto/TaskDTO.java
Original file line number Diff line number Diff line change
Expand Up @@ -565,7 +565,7 @@ public void setCorrectionCommentStatus(Integer status) {
@Override
public Date getProcessingTime() {
try {
return StringUtils.isNotEmpty(this.processingTime)
return StringUtils.isNotBlank(this.processingTime)
? new SimpleDateFormat(DATE_FORMAT).parse(this.processingTime)
: null;
} catch (ParseException e) {
Expand All @@ -582,7 +582,7 @@ public void setProcessingTime(Date processingTime) {
@Override
public Date getProcessingBegin() {
try {
return StringUtils.isNotEmpty(this.processingBegin)
return StringUtils.isNotBlank(this.processingBegin)
? new SimpleDateFormat(DATE_FORMAT).parse(this.processingBegin)
: null;
} catch (ParseException e) {
Expand All @@ -600,7 +600,7 @@ public void setProcessingBegin(Date processingBegin) {
@Override
public Date getProcessingEnd() {
try {
return StringUtils.isNotEmpty(this.processingEnd)
return StringUtils.isNotBlank(this.processingEnd)
? new SimpleDateFormat(DATE_FORMAT).parse(this.processingEnd)
: null;
} catch (ParseException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public void setWorkflowStatus(String status) {

@Override
public WorkflowStatus getStatus() {
return StringUtils.isNotEmpty(status) ? WorkflowStatus.valueOf(status) : null;
return StringUtils.isNotBlank(status) ? WorkflowStatus.valueOf(status) : null;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public String getValidationError() {
* @return True if validation error is not empty.
*/
public boolean hasValidationError() {
return StringUtils.isNotEmpty(validationError);
return StringUtils.isNotBlank(validationError);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ private static void setMessage(String control, String message, String descriptio

String compoundMessage = msg.replaceFirst(":\\s*$", "");
if (createCompoundMessage) {
if (StringUtils.isNotEmpty(descript)) {
if (StringUtils.isNotBlank(descript)) {
compoundMessage += ": " + descript;
}
detail = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ private String determineReplacementForOcrdWorkflowId(Matcher variableFinder) {
return variableFinder.group(1);
}

if (StringUtils.isNotEmpty(process.getOcrdWorkflowId())) {
if (StringUtils.isNotBlank(process.getOcrdWorkflowId())) {
return variableFinder.group(1) + process.getOcrdWorkflowId();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public static OcrdWorkflowService getInstance() {
*/
public List<Pair<?, ?>> getOcrdWorkflows() {
String ocrdWorkflowsDirectoryConfig = ConfigCore.getParameterOrDefaultValue(ParameterCore.OCRD_WORKFLOWS_DIR);
if (StringUtils.isNotEmpty(ocrdWorkflowsDirectoryConfig)) {
if (StringUtils.isNotBlank(ocrdWorkflowsDirectoryConfig)) {
Path ocrdWorkflowsDirectory = Path.of(ocrdWorkflowsDirectoryConfig);
if (Files.isDirectory(ocrdWorkflowsDirectory)) {
try (Stream<Path> ocrProfilePaths = Files.walk(ocrdWorkflowsDirectory, FileVisitOption.FOLLOW_LINKS)) {
Expand Down Expand Up @@ -92,7 +92,7 @@ public static OcrdWorkflowService getInstance() {
* @return The OCR-D workflow
*/
public Pair<?, ?> getOcrdWorkflow(String ocrdWorkflowId) {
if (StringUtils.isNotEmpty(ocrdWorkflowId)) {
if (StringUtils.isNotBlank(ocrdWorkflowId)) {
return getOcrdWorkflows().stream().filter(pair -> pair.getKey().equals(ocrdWorkflowId)).findFirst()
.orElse(null);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ private void assignViewsFromChildrenRecursive(LogicalDivision logicalDivision) {
}

private void set(Workpiece workpiece, MdSec domain, String key, String value) {
if (StringUtils.isNotEmpty(value)) {
if (StringUtils.isNotBlank(value)) {
MetadataEntry entry = new MetadataEntry();
entry.setKey(key);
entry.setDomain(domain);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ private static void processAction(Integer taskId, String action, String message,
MapMessageObjectReader mapMessageObjectReader = mock(MapMessageObjectReader.class);
when(mapMessageObjectReader.getMandatoryInteger(TaskActionProcessor.KEY_TASK_ID)).thenReturn(taskId);
when(mapMessageObjectReader.getMandatoryString(TaskActionProcessor.KEY_TASK_ACTION)).thenReturn(action);
if (StringUtils.isNotEmpty(message)) {
if (StringUtils.isNotBlank(message)) {
when(mapMessageObjectReader.hasField(TaskActionProcessor.KEY_MESSAGE)).thenReturn(Boolean.TRUE);
when(mapMessageObjectReader.getMandatoryString(TaskActionProcessor.KEY_MESSAGE)).thenReturn(message);
}
Expand Down

0 comments on commit 77ba25a

Please sign in to comment.