Skip to content

Commit 2b08535

Browse files
author
taylor.smock
committed
See #23671: Deprecate Utils#isBlank and replace instances of it with Utils#isStripEmpty
As noted in r19079, the two functions were identical in behavior. git-svn-id: https://josm.openstreetmap.de/svn/trunk@19080 0c6e7542-c601-0410-84e7-c038aed88b3b
1 parent eaebeeb commit 2b08535

38 files changed

+61
-50
lines changed

src/org/openstreetmap/josm/actions/downloadtasks/DownloadGeoJsonTask.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
import java.util.Optional;
77
import java.util.concurrent.Future;
8+
import java.util.function.Predicate;
89

910
import org.openstreetmap.josm.data.Bounds;
1011
import org.openstreetmap.josm.data.osm.DataSet;
@@ -56,7 +57,7 @@ class InternalDownloadTask extends DownloadTask {
5657
@Override
5758
protected String generateLayerName() {
5859
return Optional.of(url.substring(url.lastIndexOf('/')+1))
59-
.filter(it -> !Utils.isStripEmpty(it))
60+
.filter(Predicate.not(Utils::isStripEmpty))
6061
.orElse(super.generateLayerName());
6162
}
6263

src/org/openstreetmap/josm/actions/downloadtasks/DownloadOsmTask.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// License: GPL. For details, see LICENSE file.
22
package org.openstreetmap.josm.actions.downloadtasks;
33

4+
import static java.util.function.Predicate.not;
45
import static org.openstreetmap.josm.tools.I18n.tr;
56

67
import java.io.IOException;
@@ -298,7 +299,7 @@ protected OsmDataLayer getFirstModifiableDataLayer() {
298299
*/
299300
protected String generateLayerName() {
300301
return Optional.ofNullable(settings.getLayerName())
301-
.filter(layerName -> !Utils.isStripEmpty(layerName))
302+
.filter(not(Utils::isStripEmpty))
302303
.orElse(OsmDataLayer.createNewName());
303304
}
304305

@@ -359,7 +360,7 @@ protected OsmDataLayer addNewLayerIfRequired(String newLayerName) {
359360
if (settings.isNewLayer() || numDataLayers == 0 || (numDataLayers > 1 && getEditLayer() == null)) {
360361
// the user explicitly wants a new layer, we don't have any layer at all
361362
// or it is not clear which layer to merge to
362-
final OsmDataLayer layer = createNewLayer(Optional.ofNullable(newLayerName).filter(it -> !Utils.isStripEmpty(it)));
363+
final OsmDataLayer layer = createNewLayer(Optional.ofNullable(newLayerName).filter(not(Utils::isStripEmpty)));
363364
MainApplication.getLayerManager().addLayer(layer, zoomAfterDownload);
364365
return layer;
365366
}

src/org/openstreetmap/josm/data/UserIdentityManager.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ public User asUser() {
214214
public void initFromPreferences() {
215215
String credentialsUserName = CredentialsManager.getInstance().getUsername();
216216
if (isAnonymous()) {
217-
if (!Utils.isBlank(credentialsUserName)) {
217+
if (!Utils.isStripEmpty(credentialsUserName)) {
218218
setPartiallyIdentified(credentialsUserName);
219219
}
220220
} else {
@@ -279,7 +279,7 @@ public void preferenceChanged(PreferenceChangeEvent evt) {
279279
if (evt.getNewValue() instanceof StringSetting) {
280280
newUserName = ((StringSetting) evt.getNewValue()).getValue();
281281
}
282-
if (Utils.isBlank(newUserName)) {
282+
if (Utils.isStripEmpty(newUserName)) {
283283
setAnonymous();
284284
} else if (!newUserName.equals(userName)) {
285285
setPartiallyIdentified(newUserName);
@@ -290,7 +290,7 @@ public void preferenceChanged(PreferenceChangeEvent evt) {
290290
if (evt.getNewValue() instanceof StringSetting) {
291291
newUrl = ((StringSetting) evt.getNewValue()).getValue();
292292
}
293-
if (Utils.isBlank(newUrl)) {
293+
if (Utils.isStripEmpty(newUrl)) {
294294
setAnonymous();
295295
} else if (isFullyIdentified()) {
296296
setPartiallyIdentified(getUserName());

src/org/openstreetmap/josm/data/gpx/GpxExtension.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ public void remove() {
174174
parent.getExtensions().remove(this);
175175
if (parent instanceof GpxExtension) {
176176
GpxExtension gpx = ((GpxExtension) parent);
177-
if (Utils.isBlank(gpx.getValue())
177+
if (Utils.isStripEmpty(gpx.getValue())
178178
&& Utils.isEmpty(gpx.getAttributes())
179179
&& Utils.isEmpty(gpx.getExtensions())) {
180180
gpx.remove();
@@ -190,7 +190,7 @@ public void hide() {
190190
visible = false;
191191
if (parent != null && parent instanceof GpxExtension) {
192192
GpxExtension gpx = (GpxExtension) parent;
193-
if (Utils.isBlank(gpx.getValue())
193+
if (Utils.isStripEmpty(gpx.getValue())
194194
&& gpx.getAttributes().isEmpty()
195195
&& !gpx.getExtensions().isVisible()) {
196196
gpx.hide();

src/org/openstreetmap/josm/data/imagery/vectortile/mapbox/style/Layers.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ private String parsePaintSymbol(
272272
boolean iconImage = false;
273273
if (layoutObject.containsKey("icon-image")) {
274274
sb.append(/* NO-ICON */"icon-image:concat(");
275-
if (!Utils.isBlank(this.styleId)) {
275+
if (!Utils.isStripEmpty(this.styleId)) {
276276
sb.append('"').append(this.styleId).append('/').append("\",");
277277
}
278278
Matcher matcher = CURLY_BRACES.matcher(layoutObject.getString("icon-image"));

src/org/openstreetmap/josm/data/imagery/vectortile/mapbox/style/MapboxVectorStyle.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ public MapboxVectorStyle(JsonObject jsonObject) {
142142
MainApplication.worker.execute(() -> this.save((source == null ? data.hashCode() : source.getName()) + ".mapcss", style));
143143
this.sources.put(source, new ElemStyles(Collections.singleton(style)));
144144
}
145-
if (!Utils.isBlank(this.spriteUrl)) {
145+
if (!Utils.isStripEmpty(this.spriteUrl)) {
146146
MainApplication.worker.execute(this::fetchSprites);
147147
}
148148
} else {

src/org/openstreetmap/josm/data/oauth/OAuth20Token.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ public OAuth20Token(IOAuthParameters oauthParameters, String json) throws OAuth2
8181

8282
@Override
8383
public void sign(HttpClient client) throws OAuthException {
84-
if (!Utils.isBlank(this.oauthParameters.getApiUrl())
84+
if (!Utils.isStripEmpty(this.oauthParameters.getApiUrl())
8585
&& !this.oauthParameters.getApiUrl().contains(client.getURL().getHost())) {
8686
String host = URI.create(this.oauthParameters.getAccessTokenUrl()).getHost();
8787
throw new IllegalArgumentException("Cannot sign URL with token for different host: Expected " + host

src/org/openstreetmap/josm/data/osm/AbstractPrimitive.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -718,7 +718,7 @@ public void putAll(Map<String, String> tags) {
718718
Map<String, String> originalKeys = getKeys();
719719
List<Map.Entry<String, String>> tagsToAdd = new ArrayList<>(tags.size());
720720
for (Map.Entry<String, String> tag : tags.entrySet()) {
721-
if (!Utils.isBlank(tag.getKey())) {
721+
if (!Utils.isStripEmpty(tag.getKey())) {
722722
int keyIndex = indexOfKey(newKeys, tag.getKey());
723723
// Realistically, we will not hit the newKeys == null branch. If it is null, keyIndex is always < 0
724724
if (keyIndex < 0 || newKeys == null) {

src/org/openstreetmap/josm/data/validation/tests/TagChecker.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1402,7 +1402,7 @@ public Command fixError(TestError testError) {
14021402
for (Entry<String, String> prop: tags.entrySet()) {
14031403
String key = prop.getKey();
14041404
String value = prop.getValue();
1405-
if (Utils.isBlank(value)) {
1405+
if (Utils.isStripEmpty(value)) {
14061406
commands.add(new ChangePropertyCommand(p, key, null));
14071407
} else if (value.startsWith(" ") || value.endsWith(" ") || value.contains(" ")) {
14081408
commands.add(new ChangePropertyCommand(p, key, Utils.removeWhiteSpaces(value)));

src/org/openstreetmap/josm/gui/MapView.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
// License: GPL. For details, see LICENSE file.
22
package org.openstreetmap.josm.gui;
33

4+
import static java.util.function.Predicate.not;
5+
46
import java.awt.AlphaComposite;
57
import java.awt.BasicStroke;
68
import java.awt.Color;
@@ -826,8 +828,9 @@ public void destroy() {
826828
*/
827829
public String getLayerInformationForSourceTag() {
828830
return layerManager.getVisibleLayersInZOrder().stream()
829-
.filter(layer -> !Utils.isBlank(layer.getChangesetSourceTag()))
830-
.map(layer -> layer.getChangesetSourceTag().trim())
831+
.map(Layer::getChangesetSourceTag)
832+
.filter(not(Utils::isStripEmpty))
833+
.map(String::trim)
831834
.distinct()
832835
.collect(Collectors.joining("; "));
833836
}

src/org/openstreetmap/josm/gui/PleaseWaitDialog.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ protected void adjustLayout() {
106106
*/
107107
@Override
108108
public void setCustomText(String text) {
109-
if (Utils.isBlank(text)) {
109+
if (Utils.isStripEmpty(text)) {
110110
customText.setVisible(false);
111111
adjustLayout();
112112
return;
@@ -131,7 +131,7 @@ public void setCurrentAction(String text) {
131131
*/
132132
@Override
133133
public void appendLogMessage(String message) {
134-
if (Utils.isBlank(message))
134+
if (Utils.isStripEmpty(message))
135135
return;
136136
if (!spLog.isVisible()) {
137137
spLog.setVisible(true);

src/org/openstreetmap/josm/gui/dialogs/changeset/AbstractCellRenderer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ protected void renderId(long id) {
5656
}
5757

5858
protected void renderUser(User user) {
59-
if (user == null || Utils.isBlank(user.getName())) {
59+
if (user == null || Utils.isStripEmpty(user.getName())) {
6060
setFont(UIManager.getFont("Table.font").deriveFont(Font.ITALIC));
6161
setText(tr("anonymous"));
6262
} else {

src/org/openstreetmap/josm/gui/dialogs/changeset/query/UidInputFieldValidator.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public boolean isValid() {
3939
@Override
4040
public void validate() {
4141
String value = getComponent().getText();
42-
if (Utils.isBlank(value)) {
42+
if (Utils.isStripEmpty(value)) {
4343
feedbackInvalid("");
4444
return;
4545
}
@@ -62,7 +62,7 @@ public void validate() {
6262
*/
6363
public int getUid() {
6464
String value = getComponent().getText();
65-
if (Utils.isBlank(value)) return 0;
65+
if (Utils.isStripEmpty(value)) return 0;
6666
try {
6767
int uid = Integer.parseInt(value.trim());
6868
return Math.max(uid, 0);

src/org/openstreetmap/josm/gui/dialogs/relation/actions/SetRoleAction.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ protected void updateEnabledState() {
4444
}
4545

4646
protected boolean isEmptyRole() {
47-
return Utils.isBlank(tfRole.getText());
47+
return Utils.isStripEmpty(tfRole.getText());
4848
}
4949

5050
protected boolean confirmSettingEmptyRole(int onNumMembers) {

src/org/openstreetmap/josm/gui/help/HelpUtil.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ private static String getHelpTopicPrefix(LocaleType type) {
149149
*/
150150
public static String buildAbsoluteHelpTopic(String topic, LocaleType type) {
151151
String prefix = getHelpTopicPrefix(type);
152-
if (prefix == null || Utils.isBlank(topic) || "/".equals(topic.trim()))
152+
if (prefix == null || Utils.isStripEmpty(topic) || "/".equals(topic.trim()))
153153
return prefix;
154154
prefix += '/' + topic;
155155
return prefix.replaceAll("\\/+", "\\/"); // collapse sequences of //

src/org/openstreetmap/josm/gui/io/LayerNameAndFilePathTableCell.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ public boolean shouldSelectCell(EventObject anEvent) {
229229

230230
@Override
231231
public boolean stopCellEditing() {
232-
if (Utils.isBlank(tfFilename.getText())) {
232+
if (Utils.isStripEmpty(tfFilename.getText())) {
233233
value = null;
234234
} else {
235235
value = new File(tfFilename.getText());

src/org/openstreetmap/josm/gui/layer/NoteLayer.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -311,10 +311,10 @@ public static String getNoteToolTip(Note note) {
311311
for (NoteComment comment : note.getComments()) {
312312
String commentText = comment.getText();
313313
//closing a note creates an empty comment that we don't want to show
314-
if (!Utils.isBlank(commentText)) {
314+
if (!Utils.isStripEmpty(commentText)) {
315315
sb.append("<hr/>");
316316
String userName = XmlWriter.encode(comment.getUser().getName());
317-
if (Utils.isBlank(userName)) {
317+
if (Utils.isStripEmpty(userName)) {
318318
userName = "&lt;Anonymous&gt;";
319319
}
320320
sb.append(userName)

src/org/openstreetmap/josm/gui/layer/geoimage/GeoImageLayer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ public GeoImageLayer(final List<ImageEntry> data, GpxLayer gpxLayer, final Strin
185185
* @since 18078
186186
*/
187187
public GeoImageLayer(final List<ImageEntry> data, GpxData gpxData, final String name, boolean useThumbs) {
188-
super(!Utils.isBlank(name) ? name : tr("Geotagged Images"));
188+
super(!Utils.isStripEmpty(name) ? name : tr("Geotagged Images"));
189189
this.data = new ImageData(data);
190190
this.gpxData = gpxData;
191191
this.useThumbs = useThumbs;

src/org/openstreetmap/josm/gui/layer/geoimage/ImageDisplay.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -771,7 +771,7 @@ private void paintErrorMessage(Graphics g, IImageEntry<?> imageEntry, IImageEntr
771771
} else {
772772
errorMessage = null;
773773
}
774-
if (!Utils.isBlank(errorMessage)) {
774+
if (!Utils.isStripEmpty(errorMessage)) {
775775
Rectangle2D errorStringSize = g.getFontMetrics(g.getFont()).getStringBounds(errorMessage, g);
776776
if (Boolean.TRUE.equals(ERROR_MESSAGE_BACKGROUND.get())) {
777777
int height = g.getFontMetrics().getHeight();

src/org/openstreetmap/josm/gui/layer/markerlayer/ImageMarker.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ RemoteEntry getRemoteEntry() {
6161
if (this.isLatLonKnown()) {
6262
remoteEntry.setPos(this);
6363
}
64-
if (!Utils.isBlank(this.getText())) {
64+
if (!Utils.isStripEmpty(this.getText())) {
6565
remoteEntry.setDisplayName(this.getText());
6666
}
6767
return remoteEntry;

src/org/openstreetmap/josm/gui/mappaint/styleelement/LabelCompositionStrategy.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
// License: GPL. For details, see LICENSE file.
22
package org.openstreetmap.josm.gui.mappaint.styleelement;
33

4+
import static java.util.function.Predicate.not;
5+
46
import java.util.ArrayList;
57
import java.util.Arrays;
68
import java.util.Collections;
@@ -185,7 +187,7 @@ private static List<String> buildNameTags(List<String> nameTags) {
185187
return new ArrayList<>();
186188
}
187189
return nameTags.stream()
188-
.filter(tag -> !Utils.isStripEmpty(tag))
190+
.filter(not(Utils::isStripEmpty))
189191
.collect(Collectors.toList());
190192
}
191193

src/org/openstreetmap/josm/gui/preferences/SourceEditor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -763,7 +763,7 @@ public SourceEntry setValue(int index, SourceEntry value) {
763763
}
764764

765765
private static void prepareFileChooser(String url, AbstractFileChooser fc) {
766-
if (Utils.isBlank(url)) return;
766+
if (Utils.isStripEmpty(url)) return;
767767
URL sourceUrl;
768768
try {
769769
sourceUrl = new URL(url);

src/org/openstreetmap/josm/gui/preferences/display/GPXSettingsPanel.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ public static void putLayerPrefLocal(GpxLayer layer, String key, String value) {
292292
public static void putDataPrefLocal(IGpxLayerPrefs data, String key, String value) {
293293
if (data == null) return;
294294
data.setModified(true);
295-
if (Utils.isBlank(value) ||
295+
if (Utils.isStripEmpty(value) ||
296296
(getLayerPref(null, key).equals(value) && DEFAULT_PREFS.get(key) != null && DEFAULT_PREFS.get(key).toString().equals(value))) {
297297
data.getLayerPrefs().remove(key);
298298
} else {

src/org/openstreetmap/josm/gui/preferences/plugin/PluginListPanel.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public PluginListPanel(PluginPreferencesModel model) {
6363

6464
protected static String formatPluginRemoteVersion(PluginInformation pi) {
6565
StringBuilder sb = new StringBuilder();
66-
if (Utils.isBlank(pi.version)) {
66+
if (Utils.isStripEmpty(pi.version)) {
6767
sb.append(tr("unknown"));
6868
} else {
6969
sb.append(pi.version);
@@ -77,7 +77,7 @@ protected static String formatPluginRemoteVersion(PluginInformation pi) {
7777
protected static String formatPluginLocalVersion(PluginInformation pi) {
7878
if (pi == null)
7979
return tr("unknown");
80-
if (Utils.isBlank(pi.localversion))
80+
if (Utils.isStripEmpty(pi.localversion))
8181
return tr("unknown");
8282
return pi.localversion;
8383
}

src/org/openstreetmap/josm/gui/progress/CLIProgressMonitor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public CLIProgressMonitor() {
3737

3838
@Override
3939
protected void doBeginTask() {
40-
if (!Utils.isBlank(this.title)) {
40+
if (!Utils.isStripEmpty(this.title)) {
4141
Logging.info(tr("Beginning task {2}: {0}{1}", this.title, this.customText,
4242
Optional.ofNullable(this.taskId).map(ProgressTaskId::getId).map(id -> ' ' + id).orElse("")));
4343
}

src/org/openstreetmap/josm/gui/tagging/TagEditorModel.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// License: GPL. For details, see LICENSE file.
22
package org.openstreetmap.josm.gui.tagging;
33

4+
import static java.util.function.Predicate.not;
45
import static org.openstreetmap.josm.tools.I18n.trn;
56

67
import java.beans.PropertyChangeListener;
@@ -531,7 +532,7 @@ protected Command createDeleteTagsCommand(Collection<OsmPrimitive> primitives) {
531532
public List<String> getKeys() {
532533
return tags.stream()
533534
.map(TagModel::getName)
534-
.filter(name -> !Utils.isStripEmpty(name))
535+
.filter(not(Utils::isStripEmpty))
535536
.collect(Collectors.toList());
536537
}
537538

src/org/openstreetmap/josm/gui/widgets/AbstractIdTextField.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ public void tryToPasteFromClipboard() {
8181
* @return true if text has been pasted and valid ids have been read
8282
*/
8383
public boolean tryToPasteFrom(String contents) {
84-
if (!Utils.isBlank(contents)) {
84+
if (!Utils.isStripEmpty(contents)) {
8585
setText(contents.trim());
8686
clearTextIfInvalid();
8787
return readIds();

src/org/openstreetmap/josm/gui/widgets/ChangesetIdTextField.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ public void validate() {
7474
*/
7575
public boolean readChangesetId() {
7676
String value = getComponent().getText();
77-
if (!Utils.isBlank(value)) {
77+
if (!Utils.isStripEmpty(value)) {
7878
value = value.trim();
7979
id = 0;
8080
try {

src/org/openstreetmap/josm/gui/widgets/OsmIdTextField.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ public void validate() {
9494
public boolean readOsmIds() {
9595
String value = getComponent().getText();
9696
char c;
97-
if (Utils.isBlank(value)) {
97+
if (Utils.isStripEmpty(value)) {
9898
return false;
9999
}
100100
ids.clear();

src/org/openstreetmap/josm/io/BoundingBoxDownloader.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ private GpxData downloadRawGps(Bounds b, ProgressMonitor progressMonitor) throws
7575
Object trackUrl = track.get("url");
7676
if (trackUrl instanceof String) {
7777
String sTrackUrl = (String) trackUrl;
78-
if (!Utils.isBlank(sTrackUrl) && !sTrackUrl.startsWith("http")) {
78+
if (!Utils.isStripEmpty(sTrackUrl) && !sTrackUrl.startsWith("http")) {
7979
track.put("url", browseUrl + sTrackUrl);
8080
}
8181
}

0 commit comments

Comments
 (0)