Skip to content

Commit

Permalink
Merge pull request #5944 from slub/replace_equals_with_isEmpty
Browse files Browse the repository at this point in the history
Use efficient isEmpty call over inefficient empty string comparison
  • Loading branch information
solth authored Feb 28, 2024
2 parents ea08007 + b598388 commit 6d0431a
Show file tree
Hide file tree
Showing 11 changed files with 17 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public class FileNameBeginsAndEndsWithFilter implements FilenameFilter {
* Strings
*/
public FileNameBeginsAndEndsWithFilter(String begin, String end) {
if (begin == null || begin.equals("") || end == null || end.equals("")) {
if (begin == null || begin.isEmpty() || end == null || end.isEmpty()) {
throw new IllegalArgumentException("No filter or empty filter for file begin or end is given.");
}
this.begin = begin;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public class FileNameEndsAndDoesNotBeginWithFilter implements FilenameFilter {
* Strings
*/
public FileNameEndsAndDoesNotBeginWithFilter(String notBegin, String end) {
if (notBegin == null || notBegin.equals("") || end == null || end.equals("")) {
if (notBegin == null || notBegin.isEmpty() || end == null || end.isEmpty()) {
throw new IllegalArgumentException("No filter or empty filter for file begin or end is given.");
}
this.notBegin = notBegin;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public class FileNameEndsWithFilter implements FilenameFilter {
* it is thrown in case parameter is null or empty String
*/
public FileNameEndsWithFilter(String end) {
if (end == null || end.equals("")) {
if (end == null || end.isEmpty()) {
throw new IllegalArgumentException("No filter or empty filter for file end is given.");
}
this.end = end;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public class FileNameMatchesFilter implements FilenameFilter {
* it is thrown in case parameter is null or empty String
*/
public FileNameMatchesFilter(String name) {
if (name == null || name.equals("")) {
if (name == null || name.isEmpty()) {
throw new IllegalArgumentException("No filter or empty name is given.");
}
this.name = name;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ public void addDocStruc(boolean preview) {
private void addMultiDocStruc() {
Optional<LogicalDivision> selectedStructure = dataEditor.getSelectedStructure();
if (selectedStructure.isPresent()) {
if (selectedMetadata != "") {
if (!selectedMetadata.isEmpty()) {
MetadataViewInterface metadataView = getMetadataViewFromKey(
docStructAddTypeSelectionSelectedItem, selectedMetadata);
MetadataEditor.addMultipleStructuresWithMetadata(elementsToAddSpinnerValue,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,7 @@ public static String getDateAsFormattedString(Date date) {
* @return the date or null if it can not be parsed
*/
public static Date parseDateFromFormattedString(String date) {
if (Objects.isNull(date) || date.equals("")) {
if (Objects.isNull(date) || date.isEmpty()) {
return null;
}
try {
Expand Down
5 changes: 3 additions & 2 deletions Kitodo/src/main/java/org/kitodo/production/ldap/LdapUser.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
import javax.naming.directory.SearchResult;

import org.apache.commons.codec.binary.Base64;
import org.apache.commons.lang3.StringUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.bouncycastle.crypto.digests.MD4Digest;
Expand Down Expand Up @@ -278,7 +279,7 @@ public static String toHexString(byte[] bytes) {

@Override
public Attributes getAttributes(String name) throws NamingException {
if (!name.equals("")) {
if (StringUtils.isBlank(name)) {
throw new NameNotFoundException();
}
return (Attributes) this.attributes.clone();
Expand All @@ -291,7 +292,7 @@ public Attributes getAttributes(Name name) throws NamingException {

@Override
public Attributes getAttributes(String name, String[] ids) throws NamingException {
if (!name.isEmpty()) {
if (StringUtils.isBlank(name)) {
throw new NameNotFoundException();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -329,16 +329,16 @@ public boolean isAutogenerated() {
*/
public boolean showDependingOnDoctype() {
// if nothing was specified, then show
if (this.isDocType.equals("") && this.isNotDoctype.equals("")) {
if (this.isDocType.isEmpty() && this.isNotDoctype.isEmpty()) {
return true;
}

// if obligatory was specified
if (!this.isDocType.equals("") && !StringUtils.containsIgnoreCase(this.isDocType, this.docType)) {
if (!this.isDocType.isEmpty() && !StringUtils.containsIgnoreCase(this.isDocType, this.docType)) {
return false;
}

// if only "may not" was specified
return !(!this.isNotDoctype.equals("") && StringUtils.containsIgnoreCase(this.isNotDoctype, this.docType));
return !(!this.isNotDoctype.isEmpty() && StringUtils.containsIgnoreCase(this.isNotDoctype, this.docType));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1183,14 +1183,14 @@ private List<String> getCanonicalFileNamePartsAndSanitizeAbsoluteURIs(Workpiece
physicalDivision.getMediaFiles().put(entry.getKey(), mediaFile);
}
String fileCanonical = subfolder.getCanonical(mediaFile);
if ("".equals(unitCanonical)) {
if (StringUtils.isBlank(unitCanonical)) {
unitCanonical = fileCanonical;
} else if (!unitCanonical.equals(fileCanonical)) {
throw new InvalidImagesException("Ambiguous canonical file name part in the same physical division: \""
+ unitCanonical + "\" and \"" + fileCanonical + "\"!");
}
}
if (physicalDivision.getMediaFiles().size() > 0 && "".equals(unitCanonical)) {
if (!physicalDivision.getMediaFiles().isEmpty() && StringUtils.isBlank(unitCanonical)) {
throw new InvalidImagesException("Missing canonical file name part in physical division " + physicalDivision);
}
canonicals.add(unitCanonical);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import javax.json.JsonReader;

import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.kitodo.config.ConfigCore;
Expand Down Expand Up @@ -426,7 +427,7 @@ public int getProgress(ObjectType currentType, PushContext pollingChannel) throw
public String createMapping() throws IOException, CustomResponseException {
for (String mappingType : KitodoRestClient.MAPPING_TYPES) {
String mapping = readMapping(mappingType);
if ("".equals(mapping)) {
if (StringUtils.isBlank(mapping)) {
if (indexRestClient.createIndex(null, mappingType)) {
currentState = IndexStates.CREATING_MAPPING_SUCCESSFUL;
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ private String getWebElementText(WebElement webElement) {
};

Predicate<WebElement> isInputValueNotEmpty = (webElement) -> {
return !webElement.getAttribute("value").equals("");
return !webElement.getAttribute("value").isEmpty();
};

Predicate<File> isFileDownloaded = (file) -> {
Expand Down

0 comments on commit 6d0431a

Please sign in to comment.