This is an automated email from the ASF dual-hosted git repository. mgrigorov pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/wicket.git
The following commit(s) were added to refs/heads/master by this push: new 76778a2 WICKET-6829 Use String.isEmpty() instead of "".equals(...) 76778a2 is described below commit 76778a2bbd882b7f988e56973944e4e2238431df Author: Martin Tzvetanov Grigorov <mgrigo...@apache.org> AuthorDate: Thu Sep 10 15:28:54 2020 +0300 WICKET-6829 Use String.isEmpty() instead of "".equals(...) --- .../java/org/apache/wicket/ConverterLocator.java | 4 ++-- .../markup/html/form/AbstractSingleSelectChoice.java | 4 ++-- .../wicket/markup/html/image/ExternalImage.java | 2 +- .../org/apache/wicket/markup/html/image/Image.java | 2 +- .../wicket/markup/html/basic/SimplePageTest.java | 13 +++++++------ .../apache/wicket/examples/wizard/NewUserWizard.java | 5 +++-- .../ajax/markup/html/AjaxEditableLabel.java | 8 +------- .../ajax/markup/html/AjaxEditableMultiLineLabel.java | 10 ++-------- .../src/main/java/org/apache/wicket/request/Url.java | 20 +++++++++++--------- .../java/org/apache/wicket/request/UrlRenderer.java | 2 +- .../wicket/util/resource/ZipResourceStream.java | 8 +++----- .../java/org/apache/wicket/util/string/Strings.java | 4 ++-- 12 files changed, 36 insertions(+), 46 deletions(-) diff --git a/wicket-core/src/main/java/org/apache/wicket/ConverterLocator.java b/wicket-core/src/main/java/org/apache/wicket/ConverterLocator.java index dbef956..9b8def9 100644 --- a/wicket-core/src/main/java/org/apache/wicket/ConverterLocator.java +++ b/wicket-core/src/main/java/org/apache/wicket/ConverterLocator.java @@ -96,7 +96,7 @@ public class ConverterLocator implements IConverterLocator return null; } Class<C> theType = type.get(); - if ("".equals(value)) + if (value.isEmpty()) { if (String.class.equals(theType)) { @@ -130,7 +130,7 @@ public class ConverterLocator implements IConverterLocator @Override public String convertToString(C value, Locale locale) { - if (value == null || "".equals(value)) + if (value == null || (value instanceof String && ((String) value).isEmpty())) { return ""; } diff --git a/wicket-core/src/main/java/org/apache/wicket/markup/html/form/AbstractSingleSelectChoice.java b/wicket-core/src/main/java/org/apache/wicket/markup/html/form/AbstractSingleSelectChoice.java index 3ff86d0..d12f6d9 100644 --- a/wicket-core/src/main/java/org/apache/wicket/markup/html/form/AbstractSingleSelectChoice.java +++ b/wicket-core/src/main/java/org/apache/wicket/markup/html/form/AbstractSingleSelectChoice.java @@ -309,7 +309,7 @@ public abstract class AbstractSingleSelectChoice<T> extends AbstractChoice<T, T> buffer.append("\n<option"); // If null is selected, indicate that - if ("".equals(selectedValue)) + if (selectedValue != null && selectedValue.isEmpty()) { buffer.append(" selected=\"selected\""); } @@ -321,7 +321,7 @@ public abstract class AbstractSingleSelectChoice<T> extends AbstractChoice<T, T> else { // Null is not valid. Is it selected anyway? - if ("".equals(selectedValue)) + if (selectedValue != null && selectedValue.isEmpty()) { // Force the user to pick a non-null value String option = getNullKeyDisplayValue(); diff --git a/wicket-core/src/main/java/org/apache/wicket/markup/html/image/ExternalImage.java b/wicket-core/src/main/java/org/apache/wicket/markup/html/image/ExternalImage.java index 915bb72..ed650a5 100644 --- a/wicket-core/src/main/java/org/apache/wicket/markup/html/image/ExternalImage.java +++ b/wicket-core/src/main/java/org/apache/wicket/markup/html/image/ExternalImage.java @@ -217,7 +217,7 @@ public class ExternalImage extends WebComponent { sizes = sizes.substring(0, lastIndexOf); } - if (!"".equals(sizes)) + if (!sizes.isEmpty()) { tag.put("sizes", sizes); } diff --git a/wicket-core/src/main/java/org/apache/wicket/markup/html/image/Image.java b/wicket-core/src/main/java/org/apache/wicket/markup/html/image/Image.java index 0b31213..48c9382 100644 --- a/wicket-core/src/main/java/org/apache/wicket/markup/html/image/Image.java +++ b/wicket-core/src/main/java/org/apache/wicket/markup/html/image/Image.java @@ -487,7 +487,7 @@ public class Image extends WebComponent implements IRequestListener { sizes = sizes.substring(0, lastIndexOf); } - if (!"".equals(sizes)) + if (!sizes.isEmpty()) { tag.put("sizes", sizes); } diff --git a/wicket-core/src/test/java/org/apache/wicket/markup/html/basic/SimplePageTest.java b/wicket-core/src/test/java/org/apache/wicket/markup/html/basic/SimplePageTest.java index bb591da..f104e76 100644 --- a/wicket-core/src/test/java/org/apache/wicket/markup/html/basic/SimplePageTest.java +++ b/wicket-core/src/test/java/org/apache/wicket/markup/html/basic/SimplePageTest.java @@ -18,6 +18,7 @@ package org.apache.wicket.markup.html.basic; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertTrue; @@ -67,36 +68,36 @@ class SimplePageTest extends WicketTestCase label = (Label)tester.getLastRenderedPage().get("myPanel:label"); assertNotNull(label); - assertFalse("".equals(document)); + assertNotEquals("", document); assertTrue(document.contains("<span wicket:id=\"label\">mein Label</span>")); Border border = (Border)tester.getLastRenderedPage().get("myBorder"); assertNotNull(border); - assertFalse("".equals(document)); + assertNotEquals("", document); assertTrue(document.contains( "<wicket:border>before body - <wicket:body>border</wicket:body> - after body</wicket:border>")); border = (Border)tester.getLastRenderedPage().get("myBorder2"); assertNotNull(border); - assertFalse("".equals(document)); + assertNotEquals("", document); assertTrue(document.contains( "<span wicket:id=\"myBorder2\" testAttr=\"myValue\"><wicket:border>before body - <wicket:body>border</wicket:body> - after body</wicket:border></span>")); // do the same test twice. Igor reported a problem with that, so we have to test it. border = (Border)tester.getLastRenderedPage().get("myBorder2"); assertNotNull(border); - assertFalse("".equals(document)); + assertNotEquals("", document); assertTrue(document.contains( "<span wicket:id=\"myBorder2\" testAttr=\"myValue\"><wicket:border>before body - <wicket:body>border</wicket:body> - after body</wicket:border></span>")); WebMarkupContainer container = (WebMarkupContainer)tester.getLastRenderedPage().get("test"); assertNotNull(container); - assertFalse("".equals(document)); + assertNotEquals("", document); assertTrue(document.contains("body<span wicket:id=\"myLabel2\">Test Label2</span>")); label = (Label)tester.getLastRenderedPage().get("test:myLabel2"); assertNotNull(label); - assertFalse("".equals(document)); + assertNotEquals("", document); assertTrue(document.contains("<span wicket:id=\"myLabel2\">Test Label2</span>")); } diff --git a/wicket-examples/src/main/java/org/apache/wicket/examples/wizard/NewUserWizard.java b/wicket-examples/src/main/java/org/apache/wicket/examples/wizard/NewUserWizard.java index 17d234b..1129eeb 100644 --- a/wicket-examples/src/main/java/org/apache/wicket/examples/wizard/NewUserWizard.java +++ b/wicket-examples/src/main/java/org/apache/wicket/examples/wizard/NewUserWizard.java @@ -150,9 +150,10 @@ public class NewUserWizard extends Wizard public void validate(Form<?> form) { String rolesInput = rolesChoiceField.getInput(); - if (rolesInput != null && (!"".equals(rolesInput))) + if (rolesInput != null && !rolesInput.isEmpty()) { - if ("".equals(rolesSetNameField.getInput())) + final String rolesSetNameFieldInput = rolesSetNameField.getInput(); + if (rolesSetNameFieldInput == null || rolesSetNameFieldInput.isEmpty()) { rolesSetNameField.error(new ValidationError().addKey("error.noSetNameForRoles")); } diff --git a/wicket-extensions/src/main/java/org/apache/wicket/extensions/ajax/markup/html/AjaxEditableLabel.java b/wicket-extensions/src/main/java/org/apache/wicket/extensions/ajax/markup/html/AjaxEditableLabel.java index 6265441..91ce9b6 100644 --- a/wicket-extensions/src/main/java/org/apache/wicket/extensions/ajax/markup/html/AjaxEditableLabel.java +++ b/wicket-extensions/src/main/java/org/apache/wicket/extensions/ajax/markup/html/AjaxEditableLabel.java @@ -383,24 +383,18 @@ public class AjaxEditableLabel<T> extends Panel implements IGenericComponent<T, { private static final long serialVersionUID = 1L; - /** - * {@inheritDoc} - */ @Override public <C> IConverter<C> getConverter(final Class<C> type) { return AjaxEditableLabel.this.getConverter(type); } - /** - * {@inheritDoc} - */ @Override public void onComponentTagBody(final MarkupStream markupStream, final ComponentTag openTag) { Object modelObject = getDefaultModelObject(); - if ((modelObject == null) || "".equals(modelObject)) + if ((modelObject == null) || (modelObject instanceof String && ((String) modelObject).isEmpty())) { replaceComponentTagBody(markupStream, openTag, defaultNullLabel()); } diff --git a/wicket-extensions/src/main/java/org/apache/wicket/extensions/ajax/markup/html/AjaxEditableMultiLineLabel.java b/wicket-extensions/src/main/java/org/apache/wicket/extensions/ajax/markup/html/AjaxEditableMultiLineLabel.java index 8918246..db8c2a4 100644 --- a/wicket-extensions/src/main/java/org/apache/wicket/extensions/ajax/markup/html/AjaxEditableMultiLineLabel.java +++ b/wicket-extensions/src/main/java/org/apache/wicket/extensions/ajax/markup/html/AjaxEditableMultiLineLabel.java @@ -87,24 +87,18 @@ public class AjaxEditableMultiLineLabel<T> extends AjaxEditableLabel<T> { private static final long serialVersionUID = 1L; - /** - * {@inheritDoc} - */ @Override public <C> IConverter<C> getConverter(final Class<C> type) { return AjaxEditableMultiLineLabel.this.getConverter(type); } - - /** - * {@inheritDoc} - */ + @Override public void onComponentTagBody(final MarkupStream markupStream, final ComponentTag openTag) { Object modelObject = getDefaultModelObject(); - if ((modelObject == null) || "".equals(modelObject)) + if ((modelObject == null) || (modelObject instanceof String && ((String) modelObject).isEmpty())) { replaceComponentTagBody(markupStream, openTag, defaultNullLabel()); } diff --git a/wicket-request/src/main/java/org/apache/wicket/request/Url.java b/wicket-request/src/main/java/org/apache/wicket/request/Url.java index be52c5b..a056a22 100755 --- a/wicket-request/src/main/java/org/apache/wicket/request/Url.java +++ b/wicket-request/src/main/java/org/apache/wicket/request/Url.java @@ -1055,19 +1055,21 @@ public class Url implements Serializable // remove leading './' (current folder) and empty segments, process any ../ segments from // the relative url - while (!relative.getSegments().isEmpty()) + final List<String> relativeSegments = relative.getSegments(); + while (!relativeSegments.isEmpty()) { - if (".".equals(relative.getSegments().get(0))) + final String firstSegment = relativeSegments.get(0); + if (".".equals(firstSegment)) { - relative.getSegments().remove(0); + relativeSegments.remove(0); } - else if ("".equals(relative.getSegments().get(0))) + else if (firstSegment.isEmpty()) { - relative.getSegments().remove(0); + relativeSegments.remove(0); } - else if ("..".equals(relative.getSegments().get(0))) + else if ("..".equals(firstSegment)) { - relative.getSegments().remove(0); + relativeSegments.remove(0); if (getSegments().isEmpty() == false) { getSegments().remove(getSegments().size() - 1); @@ -1079,13 +1081,13 @@ public class Url implements Serializable } } - if (!getSegments().isEmpty() && relative.getSegments().isEmpty()) + if (!getSegments().isEmpty() && relativeSegments.isEmpty()) { getSegments().add(""); } // append the remaining relative segments - getSegments().addAll(relative.getSegments()); + getSegments().addAll(relativeSegments); // replace query params with the ones from relative parameters.clear(); diff --git a/wicket-request/src/main/java/org/apache/wicket/request/UrlRenderer.java b/wicket-request/src/main/java/org/apache/wicket/request/UrlRenderer.java index f4d8720..c02996a 100644 --- a/wicket-request/src/main/java/org/apache/wicket/request/UrlRenderer.java +++ b/wicket-request/src/main/java/org/apache/wicket/request/UrlRenderer.java @@ -322,7 +322,7 @@ public class UrlRenderer { // try to remove context/filter path only if the Url starts with '/', // i.e. has an empty segment in the beginning - if (segments.isEmpty() || "".equals(segments.get(0)) == false) + if ((segments.isEmpty() || segments.get(0).isEmpty()) == false) { return; } diff --git a/wicket-util/src/main/java/org/apache/wicket/util/resource/ZipResourceStream.java b/wicket-util/src/main/java/org/apache/wicket/util/resource/ZipResourceStream.java index d0b46f2..bc9d3c3 100644 --- a/wicket-util/src/main/java/org/apache/wicket/util/resource/ZipResourceStream.java +++ b/wicket-util/src/main/java/org/apache/wicket/util/resource/ZipResourceStream.java @@ -135,10 +135,8 @@ public class ZipResourceStream extends AbstractResourceStream { for (String file : files) { - if (log.isDebugEnabled()) - { - log.debug("Adding: '{}'", file); - } + log.debug("Adding: '{}'", file); + File f = new File(dir, file); if (f.isDirectory()) { @@ -168,7 +166,7 @@ public class ZipResourceStream extends AbstractResourceStream } } - if ("".equals(path)) + if (path.isEmpty()) { out.close(); } diff --git a/wicket-util/src/main/java/org/apache/wicket/util/string/Strings.java b/wicket-util/src/main/java/org/apache/wicket/util/string/Strings.java index 89cb379..b948292 100755 --- a/wicket-util/src/main/java/org/apache/wicket/util/string/Strings.java +++ b/wicket-util/src/main/java/org/apache/wicket/util/string/Strings.java @@ -755,7 +755,7 @@ public final class Strings // If searchFor is null or the empty string, then there is nothing to // replace, so returning s is the only option here. - if ((searchFor == null) || "".equals(searchFor)) + if ((searchFor == null) || searchFor.length() == 0) { return s; } @@ -862,7 +862,7 @@ public final class Strings // Stripping a null or empty string from the end returns the // original string. - if ((ending == null) || "".equals(ending)) + if (ending == null || ending.isEmpty()) { return s; }