Skip to content

Commit

Permalink
Replace equals("") with more efficient isEmpty() calls
Browse files Browse the repository at this point in the history
  • Loading branch information
henning-gerhardt committed Feb 23, 2024
1 parent 4fa7db4 commit 8d985ad
Show file tree
Hide file tree
Showing 10 changed files with 13 additions and 13 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 @@ -411,7 +411,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
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ public static String toHexString(byte[] bytes) {

@Override
public Attributes getAttributes(String name) throws NamingException {
if (!name.equals("")) {
if (!name.isEmpty()) {
throw new NameNotFoundException();
}
return (Attributes) this.attributes.clone();
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 (unitCanonical.isEmpty()) {
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() && unitCanonical.isEmpty()) {
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 @@ -426,7 +426,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 (mapping.isEmpty()) {
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 8d985ad

Please sign in to comment.