From 17b0b997ebc078c5a867a98c7db0a84c17f20798 Mon Sep 17 00:00:00 2001 From: TacoTheDank Date: Thu, 19 Nov 2020 15:15:19 -0500 Subject: [PATCH 01/12] Performance: Bulk operation can be used instead of iteration --- .../src/main/java/net/osmand/binary/CachedOsmandIndexes.java | 4 +--- OsmAnd/src/net/osmand/plus/TargetPointsHelper.java | 4 +--- .../plus/activities/search/SearchPoiFilterFragment.java | 4 +--- OsmAnd/src/net/osmand/plus/development/LogcatActivity.java | 5 ++--- 4 files changed, 5 insertions(+), 12 deletions(-) diff --git a/OsmAnd-java/src/main/java/net/osmand/binary/CachedOsmandIndexes.java b/OsmAnd-java/src/main/java/net/osmand/binary/CachedOsmandIndexes.java index 4a4bec70a2..63c81d13fa 100644 --- a/OsmAnd-java/src/main/java/net/osmand/binary/CachedOsmandIndexes.java +++ b/OsmAnd-java/src/main/java/net/osmand/binary/CachedOsmandIndexes.java @@ -241,9 +241,7 @@ public class CachedOsmandIndexes { cblock.type = mr.getType(); mi.cities.add(cblock); } - for(String s : index.getAdditionalTagsList()) { - mi.attributeTagsTable.add(s); - } + mi.attributeTagsTable.addAll(index.getAdditionalTagsList()); reader.addressIndexes.add(mi); reader.indexes.add(mi); } diff --git a/OsmAnd/src/net/osmand/plus/TargetPointsHelper.java b/OsmAnd/src/net/osmand/plus/TargetPointsHelper.java index 07ef8df985..01ee06e16f 100644 --- a/OsmAnd/src/net/osmand/plus/TargetPointsHelper.java +++ b/OsmAnd/src/net/osmand/plus/TargetPointsHelper.java @@ -309,9 +309,7 @@ public class TargetPointsHelper { public List getIntermediatePointsNavigation() { List intermediatePoints = new ArrayList<>(); if (settings.USE_INTERMEDIATE_POINTS_NAVIGATION.get()) { - for (TargetPoint t : this.intermediatePoints) { - intermediatePoints.add(t); - } + intermediatePoints.addAll(this.intermediatePoints); } return intermediatePoints; } diff --git a/OsmAnd/src/net/osmand/plus/activities/search/SearchPoiFilterFragment.java b/OsmAnd/src/net/osmand/plus/activities/search/SearchPoiFilterFragment.java index a1c4d466e1..6b3de30970 100644 --- a/OsmAnd/src/net/osmand/plus/activities/search/SearchPoiFilterFragment.java +++ b/OsmAnd/src/net/osmand/plus/activities/search/SearchPoiFilterFragment.java @@ -166,9 +166,7 @@ public class SearchPoiFilterFragment extends OsmAndListFragment implements Searc } }); - for (AbstractPoiType p : res) { - filters.add(p); - } + filters.addAll(res); filters.add(poiFilters.getSearchByNamePOIFilter()); if (OsmandPlugin.getEnabledPlugin(OsmandRasterMapsPlugin.class) != null) { filters.add(poiFilters.getNominatimPOIFilter()); diff --git a/OsmAnd/src/net/osmand/plus/development/LogcatActivity.java b/OsmAnd/src/net/osmand/plus/development/LogcatActivity.java index 20f5c4ba4a..af0f6bbbfd 100644 --- a/OsmAnd/src/net/osmand/plus/development/LogcatActivity.java +++ b/OsmAnd/src/net/osmand/plus/development/LogcatActivity.java @@ -32,6 +32,7 @@ import java.io.IOException; import java.io.InputStreamReader; import java.lang.ref.WeakReference; import java.util.ArrayList; +import java.util.Arrays; import java.util.Collection; import java.util.List; @@ -298,9 +299,7 @@ public class LogcatActivity extends ActionBarProgressActivity { LogcatActivity activity = logcatActivity.get(); if (activity != null) { boolean autoscroll = !activity.recyclerView.canScrollVertically(1); - for(String s : values) { - activity.logs.add(s); - } + activity.logs.addAll(Arrays.asList(values)); activity.adapter.notifyDataSetChanged(); if(autoscroll) { activity.recyclerView.scrollToPosition(activity.logs.size() - 1); From a35050b2e7f8d5624ca1370b5d8cbec4ec74efb4 Mon Sep 17 00:00:00 2001 From: TacoTheDank Date: Thu, 19 Nov 2020 15:15:54 -0500 Subject: [PATCH 02/12] Performance: Call to 'Arrays.asList()' with too few arguments --- .../src/main/java/net/osmand/search/core/SearchPhrase.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/OsmAnd-java/src/main/java/net/osmand/search/core/SearchPhrase.java b/OsmAnd-java/src/main/java/net/osmand/search/core/SearchPhrase.java index 2a3fc59521..09dcdc372b 100644 --- a/OsmAnd-java/src/main/java/net/osmand/search/core/SearchPhrase.java +++ b/OsmAnd-java/src/main/java/net/osmand/search/core/SearchPhrase.java @@ -720,7 +720,7 @@ public class SearchPhrase { if (result.containsKey(currRegionName)) { result.get(currRegionName).add(r); } else { - result.put(currRegionName, new ArrayList<>(Arrays.asList(r))); + result.put(currRegionName, new ArrayList<>(Collections.singletonList(r))); } it.remove(); } From 830a2275078214a2b989e8155fc777288c186918 Mon Sep 17 00:00:00 2001 From: TacoTheDank Date: Thu, 19 Nov 2020 15:16:18 -0500 Subject: [PATCH 03/12] Performance: Class initializer may be 'static' --- OsmAnd/src/net/osmand/plus/OsmAndFormatter.java | 2 +- .../osmand/core/samples/android/sample1/SampleFormatter.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/OsmAndFormatter.java b/OsmAnd/src/net/osmand/plus/OsmAndFormatter.java index 92bcdef9a6..3fd1aa1adc 100644 --- a/OsmAnd/src/net/osmand/plus/OsmAndFormatter.java +++ b/OsmAnd/src/net/osmand/plus/OsmAndFormatter.java @@ -63,7 +63,7 @@ public class OsmAndFormatter { private static final char WEST = 'W'; private static final char EAST = 'E'; - { + static { fixed2.setMinimumFractionDigits(2); fixed1.setMinimumFractionDigits(1); fixed1.setMinimumIntegerDigits(1); diff --git a/OsmAndCore-sample/src/net/osmand/core/samples/android/sample1/SampleFormatter.java b/OsmAndCore-sample/src/net/osmand/core/samples/android/sample1/SampleFormatter.java index 9397f5ea7d..6a340aa528 100644 --- a/OsmAndCore-sample/src/net/osmand/core/samples/android/sample1/SampleFormatter.java +++ b/OsmAndCore-sample/src/net/osmand/core/samples/android/sample1/SampleFormatter.java @@ -23,7 +23,7 @@ public class SampleFormatter { public final static float FEET_IN_ONE_METER = YARDS_IN_ONE_METER * 3f; private static final DecimalFormat fixed2 = new DecimalFormat("0.00"); private static final DecimalFormat fixed1 = new DecimalFormat("0.0"); - { + static { fixed2.setMinimumFractionDigits(2); fixed1.setMinimumFractionDigits(1); fixed1.setMinimumIntegerDigits(1); From 270e7e873d52d9ae30b7889e2a967d10d96cc8cb Mon Sep 17 00:00:00 2001 From: TacoTheDank Date: Thu, 19 Nov 2020 15:17:52 -0500 Subject: [PATCH 04/12] Performance: 'Collection.toArray()' call style --- .../main/java/com/google/protobuf/ByteString.java | 2 +- .../mapbox_vector_tile/adapt/jts/MvtReader.java | 12 ++++++------ .../src/main/java/net/osmand/GPXUtilities.java | 2 +- .../main/java/net/osmand/data/Multipolygon.java | 4 ++-- .../java/net/osmand/map/TileSourceManager.java | 2 +- .../main/java/net/osmand/render/RenderingRule.java | 2 +- .../render/RenderingRuleStorageProperties.java | 2 +- .../net/osmand/render/RenderingRulesStorage.java | 4 ++-- .../main/java/net/osmand/router/GeneralRouter.java | 14 +++++++------- .../net/osmand/router/RoutePlannerFrontEnd.java | 2 +- .../net/osmand/router/RouteResultPreparation.java | 2 +- .../java/net/osmand/router/RoutingContext.java | 2 +- OsmAnd/src/net/osmand/access/NavigationInfo.java | 2 +- OsmAnd/src/net/osmand/plus/ContextMenuAdapter.java | 4 ++-- OsmAnd/src/net/osmand/plus/GpxSelectionHelper.java | 4 ++-- .../osmand/plus/activities/MapActivityActions.java | 2 +- .../plus/audionotes/AudioVideoNotesPlugin.java | 2 +- .../plus/dashboard/DashChooseAppDirFragment.java | 2 +- .../net/osmand/plus/dialogs/ConfigureMapMenu.java | 4 ++-- .../osmand/plus/download/DownloadFileHelper.java | 2 +- .../plus/download/ui/LocalIndexesFragment.java | 2 +- .../plus/download/ui/UpdatesIndexFragment.java | 4 ++-- .../net/osmand/plus/helpers/ExternalApiHelper.java | 2 +- .../DirectionIndicationDialogFragment.java | 2 +- .../plus/monitoring/OsmandMonitoringPlugin.java | 2 +- .../osmand/plus/myplaces/AvailableGPXFragment.java | 8 ++++---- .../osmand/plus/myplaces/TrackSegmentFragment.java | 2 +- .../src/net/osmand/plus/osmedit/AddPOIAction.java | 4 ++-- .../plus/osmedit/AdvancedEditPoiFragment.java | 4 ++-- .../net/osmand/plus/osmedit/OsmEditingPlugin.java | 2 +- .../net/osmand/plus/osmedit/OsmEditsFragment.java | 4 ++-- .../plus/osmedit/OsmEditsUploadListenerHelper.java | 2 +- .../osmedit/dialogs/PoiSubTypeDialogFragment.java | 2 +- .../osmedit/dialogs/PoiTypeDialogFragment.java | 2 +- .../net/osmand/plus/resources/ResourceManager.java | 6 +++--- .../src/net/osmand/plus/routing/RouteProvider.java | 2 +- .../src/net/osmand/plus/srtmplugin/SRTMPlugin.java | 2 +- .../net/osmand/plus/views/layers/AidlMapLayer.java | 2 +- .../osmand/plus/views/layers/MapControlsLayer.java | 2 +- .../plus/voice/AbstractPrologCommandPlayer.java | 2 +- .../plus/wikivoyage/data/TravelDbHelper.java | 4 ++-- .../wikivoyage/explore/ExploreTabFragment.java | 2 +- .../android/sample1/CurrentPositionHelper.java | 2 +- 43 files changed, 69 insertions(+), 69 deletions(-) diff --git a/OsmAnd-java/src/main/java/com/google/protobuf/ByteString.java b/OsmAnd-java/src/main/java/com/google/protobuf/ByteString.java index 73d831f6ee..cb1307d3b5 100644 --- a/OsmAnd-java/src/main/java/com/google/protobuf/ByteString.java +++ b/OsmAnd-java/src/main/java/com/google/protobuf/ByteString.java @@ -800,7 +800,7 @@ public abstract class ByteString implements Iterable { // Copy the information we need into local variables so as to hold // the lock for as short a time as possible. cachedFlushBuffers = - flushedBuffers.toArray(new ByteString[flushedBuffers.size()]); + flushedBuffers.toArray(new ByteString[0]); cachedBuffer = buffer; cachedBufferPos = bufferPos; } diff --git a/OsmAnd-java/src/main/java/com/wdtinc/mapbox_vector_tile/adapt/jts/MvtReader.java b/OsmAnd-java/src/main/java/com/wdtinc/mapbox_vector_tile/adapt/jts/MvtReader.java index 6083ca980e..73ce9eeb12 100644 --- a/OsmAnd-java/src/main/java/com/wdtinc/mapbox_vector_tile/adapt/jts/MvtReader.java +++ b/OsmAnd-java/src/main/java/com/wdtinc/mapbox_vector_tile/adapt/jts/MvtReader.java @@ -322,7 +322,7 @@ public final class MvtReader { geoms.add(geomFactory.createLineString(nextCoordSeq)); } - return geoms.size() == 1 ? geoms.get(0) : geomFactory.createMultiLineString(geoms.toArray(new LineString[geoms.size()])); + return geoms.size() == 1 ? geoms.get(0) : geomFactory.createMultiLineString(geoms.toArray(new LineString[0])); } /** @@ -450,7 +450,7 @@ public final class MvtReader { return polygons.get(0); } else { - return geomFactory.createMultiPolygon(polygons.toArray(new Polygon[polygons.size()])); + return geomFactory.createMultiPolygon(polygons.toArray(new Polygon[0])); } } @@ -512,7 +512,7 @@ public final class MvtReader { if (area > 0d) { if (outerPoly != null) { - polygons.add(geomFactory.createPolygon(outerPoly, holes.toArray(new LinearRing[holes.size()]))); + polygons.add(geomFactory.createPolygon(outerPoly, holes.toArray(new LinearRing[0]))); holes.clear(); } @@ -533,7 +533,7 @@ public final class MvtReader { if (outerPoly != null) { holes.toArray(); - polygons.add(geomFactory.createPolygon(outerPoly, holes.toArray(new LinearRing[holes.size()]))); + polygons.add(geomFactory.createPolygon(outerPoly, holes.toArray(new LinearRing[0]))); } return polygons; @@ -569,7 +569,7 @@ public final class MvtReader { if (outerPoly == null || (outerArea < 0 == area < 0)) { if (outerPoly != null) { - polygons.add(geomFactory.createPolygon(outerPoly, holes.toArray(new LinearRing[holes.size()]))); + polygons.add(geomFactory.createPolygon(outerPoly, holes.toArray(new LinearRing[0]))); holes.clear(); } @@ -590,7 +590,7 @@ public final class MvtReader { if (outerPoly != null) { holes.toArray(); - polygons.add(geomFactory.createPolygon(outerPoly, holes.toArray(new LinearRing[holes.size()]))); + polygons.add(geomFactory.createPolygon(outerPoly, holes.toArray(new LinearRing[0]))); } return polygons; diff --git a/OsmAnd-java/src/main/java/net/osmand/GPXUtilities.java b/OsmAnd-java/src/main/java/net/osmand/GPXUtilities.java index 1d1b1da020..b8835ff2c6 100644 --- a/OsmAnd-java/src/main/java/net/osmand/GPXUtilities.java +++ b/OsmAnd-java/src/main/java/net/osmand/GPXUtilities.java @@ -1247,7 +1247,7 @@ public class GPXUtilities { } } } - g.prepareInformation(fileTimestamp, splitSegments.toArray(new SplitSegment[splitSegments.size()])); + g.prepareInformation(fileTimestamp, splitSegments.toArray(new SplitSegment[0])); return g; } diff --git a/OsmAnd-java/src/main/java/net/osmand/data/Multipolygon.java b/OsmAnd-java/src/main/java/net/osmand/data/Multipolygon.java index bf8c0a4964..6fb6db0f3c 100644 --- a/OsmAnd-java/src/main/java/net/osmand/data/Multipolygon.java +++ b/OsmAnd-java/src/main/java/net/osmand/data/Multipolygon.java @@ -61,9 +61,9 @@ public class Multipolygon { innerLinearRings.add(innerRing.toLinearRing()); } } - polygons.add(geometryFactory.createPolygon(outerRing.toLinearRing(), innerLinearRings.toArray(new LinearRing[innerLinearRings.size()]))); + polygons.add(geometryFactory.createPolygon(outerRing.toLinearRing(), innerLinearRings.toArray(new LinearRing[0]))); } - return geometryFactory.createMultiPolygon(polygons.toArray(new Polygon[polygons.size()])); + return geometryFactory.createMultiPolygon(polygons.toArray(new Polygon[0])); } public long getId() { diff --git a/OsmAnd-java/src/main/java/net/osmand/map/TileSourceManager.java b/OsmAnd-java/src/main/java/net/osmand/map/TileSourceManager.java index 9885aa2fbf..0bdcda71c9 100644 --- a/OsmAnd-java/src/main/java/net/osmand/map/TileSourceManager.java +++ b/OsmAnd-java/src/main/java/net/osmand/map/TileSourceManager.java @@ -140,7 +140,7 @@ public class TileSourceManager { } } } - return randoms.toArray(new String[randoms.size()]); + return randoms.toArray(new String[0]); } public void setMinZoom(int minZoom) { diff --git a/OsmAnd-java/src/main/java/net/osmand/render/RenderingRule.java b/OsmAnd-java/src/main/java/net/osmand/render/RenderingRule.java index 0ae4314dd9..b402cca664 100644 --- a/OsmAnd-java/src/main/java/net/osmand/render/RenderingRule.java +++ b/OsmAnd-java/src/main/java/net/osmand/render/RenderingRule.java @@ -70,7 +70,7 @@ public class RenderingRule { i++; } } - properties = props.toArray(new RenderingRuleProperty[props.size()]); + properties = props.toArray(new RenderingRuleProperty[0]); } private int getPropertyIndex(String property){ diff --git a/OsmAnd-java/src/main/java/net/osmand/render/RenderingRuleStorageProperties.java b/OsmAnd-java/src/main/java/net/osmand/render/RenderingRuleStorageProperties.java index 3eafb803dd..4ae767561e 100644 --- a/OsmAnd-java/src/main/java/net/osmand/render/RenderingRuleStorageProperties.java +++ b/OsmAnd-java/src/main/java/net/osmand/render/RenderingRuleStorageProperties.java @@ -318,7 +318,7 @@ public class RenderingRuleStorageProperties { } public RenderingRuleProperty[] getPoperties() { - return rules.toArray(new RenderingRuleProperty[rules.size()]); + return rules.toArray(new RenderingRuleProperty[0]); } public List getCustomRules() { diff --git a/OsmAnd-java/src/main/java/net/osmand/render/RenderingRulesStorage.java b/OsmAnd-java/src/main/java/net/osmand/render/RenderingRulesStorage.java index d4d97d547c..11ac95cbd5 100644 --- a/OsmAnd-java/src/main/java/net/osmand/render/RenderingRulesStorage.java +++ b/OsmAnd-java/src/main/java/net/osmand/render/RenderingRulesStorage.java @@ -492,10 +492,10 @@ public class RenderingRulesStorage { } public String[] getRenderingAttributeNames() { - return renderingAttributes.keySet().toArray(new String[renderingAttributes.size()]); + return renderingAttributes.keySet().toArray(new String[0]); } public RenderingRule[] getRenderingAttributeValues() { - return renderingAttributes.values().toArray(new RenderingRule[renderingAttributes.size()]); + return renderingAttributes.values().toArray(new RenderingRule[0]); } public RenderingRule[] getRules(int state){ diff --git a/OsmAnd-java/src/main/java/net/osmand/router/GeneralRouter.java b/OsmAnd-java/src/main/java/net/osmand/router/GeneralRouter.java index 537e3a5f74..e6d19c1d58 100644 --- a/OsmAnd-java/src/main/java/net/osmand/router/GeneralRouter.java +++ b/OsmAnd-java/src/main/java/net/osmand/router/GeneralRouter.java @@ -754,21 +754,21 @@ public class GeneralRouter implements VehicleRouter { } public RouteAttributeEvalRule[] getRules() { - return rules.toArray(new RouteAttributeEvalRule[rules.size()]); + return rules.toArray(new RouteAttributeEvalRule[0]); } public String[] getParamKeys() { if(paramContext == null) { return new String[0]; } - return paramContext.vars.keySet().toArray(new String[paramContext.vars.size()]); + return paramContext.vars.keySet().toArray(new String[0]); } public String[] getParamValues() { if(paramContext == null) { return new String[0]; } - return paramContext.vars.values().toArray(new String[paramContext.vars.size()]); + return paramContext.vars.values().toArray(new String[0]); } private Object evaluate(RouteDataObject ro) { @@ -988,19 +988,19 @@ public class GeneralRouter implements VehicleRouter { public RouteAttributeExpression[] getExpressions() { - return expressions.toArray(new RouteAttributeExpression[expressions.size()]); + return expressions.toArray(new RouteAttributeExpression[0]); } public String[] getParameters() { - return parameters.toArray(new String[parameters.size()]); + return parameters.toArray(new String[0]); } public String[] getTagValueCondDefTag() { - return tagValueCondDefTag.toArray(new String[tagValueCondDefTag.size()]); + return tagValueCondDefTag.toArray(new String[0]); } public String[] getTagValueCondDefValue() { - return tagValueCondDefValue.toArray(new String[tagValueCondDefValue.size()]); + return tagValueCondDefValue.toArray(new String[0]); } public boolean[] getTagValueCondDefNot() { diff --git a/OsmAnd-java/src/main/java/net/osmand/router/RoutePlannerFrontEnd.java b/OsmAnd-java/src/main/java/net/osmand/router/RoutePlannerFrontEnd.java index 17eb567813..74dceb13a1 100644 --- a/OsmAnd-java/src/main/java/net/osmand/router/RoutePlannerFrontEnd.java +++ b/OsmAnd-java/src/main/java/net/osmand/router/RoutePlannerFrontEnd.java @@ -918,7 +918,7 @@ public class RoutePlannerFrontEnd { private List runNativeRouting(final RoutingContext ctx, RouteSegment recalculationEnd) throws IOException { refreshProgressDistance(ctx); - RouteRegion[] regions = ctx.reverseMap.keySet().toArray(new BinaryMapRouteReaderAdapter.RouteRegion[ctx.reverseMap.size()]); + RouteRegion[] regions = ctx.reverseMap.keySet().toArray(new RouteRegion[0]); ctx.checkOldRoutingFiles(ctx.startX, ctx.startY); ctx.checkOldRoutingFiles(ctx.targetX, ctx.targetY); diff --git a/OsmAnd-java/src/main/java/net/osmand/router/RouteResultPreparation.java b/OsmAnd-java/src/main/java/net/osmand/router/RouteResultPreparation.java index d7ebbaba8f..4df69c3adc 100644 --- a/OsmAnd-java/src/main/java/net/osmand/router/RouteResultPreparation.java +++ b/OsmAnd-java/src/main/java/net/osmand/router/RouteResultPreparation.java @@ -1717,7 +1717,7 @@ public class RouteResultPreparation { } } } - Integer[] array = possibleTurns.toArray(new Integer[possibleTurns.size()]); + Integer[] array = possibleTurns.toArray(new Integer[0]); Arrays.sort(array, new Comparator() { @Override diff --git a/OsmAnd-java/src/main/java/net/osmand/router/RoutingContext.java b/OsmAnd-java/src/main/java/net/osmand/router/RoutingContext.java index 3bfbaec0da..584be83bb3 100644 --- a/OsmAnd-java/src/main/java/net/osmand/router/RoutingContext.java +++ b/OsmAnd-java/src/main/java/net/osmand/router/RoutingContext.java @@ -802,7 +802,7 @@ public class RoutingContext { } public BinaryMapIndexReader[] getMaps() { - return map.keySet().toArray(new BinaryMapIndexReader[map.size()]); + return map.keySet().toArray(new BinaryMapIndexReader[0]); } public int getVisitedSegments() { diff --git a/OsmAnd/src/net/osmand/access/NavigationInfo.java b/OsmAnd/src/net/osmand/access/NavigationInfo.java index 3e087e27ae..edd296b38a 100644 --- a/OsmAnd/src/net/osmand/access/NavigationInfo.java +++ b/OsmAnd/src/net/osmand/access/NavigationInfo.java @@ -373,7 +373,7 @@ public class NavigationInfo implements OsmAndCompassListener, OsmAndLocationList dialog.cancel(); } }); - info.setItems(attributes.toArray(new String[attributes.size()]), new DialogInterface.OnClickListener() { + info.setItems(attributes.toArray(new String[0]), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { } diff --git a/OsmAnd/src/net/osmand/plus/ContextMenuAdapter.java b/OsmAnd/src/net/osmand/plus/ContextMenuAdapter.java index d85d6ddd68..d188a7d0ee 100644 --- a/OsmAnd/src/net/osmand/plus/ContextMenuAdapter.java +++ b/OsmAnd/src/net/osmand/plus/ContextMenuAdapter.java @@ -208,7 +208,7 @@ public class ContextMenuAdapter { } items.removeAll(itemsToRemove); return new ContextMenuArrayAdapter(activity, layoutId, R.id.title, - items.toArray(new ContextMenuItem[items.size()]), app, lightTheme, changeAppModeListener); + items.toArray(new ContextMenuItem[0]), app, lightTheme, changeAppModeListener); } public class ContextMenuArrayAdapter extends ArrayAdapter { @@ -643,7 +643,7 @@ public class ContextMenuAdapter { } public static OnItemDeleteAction makeDeleteAction(final List prefs) { - return makeDeleteAction(prefs.toArray(new OsmandPreference[prefs.size()])); + return makeDeleteAction(prefs.toArray(new OsmandPreference[0])); } private static void resetSetting(ApplicationMode appMode, OsmandPreference preference, boolean profileOnly) { diff --git a/OsmAnd/src/net/osmand/plus/GpxSelectionHelper.java b/OsmAnd/src/net/osmand/plus/GpxSelectionHelper.java index 2651e7b988..026987d13b 100644 --- a/OsmAnd/src/net/osmand/plus/GpxSelectionHelper.java +++ b/OsmAnd/src/net/osmand/plus/GpxSelectionHelper.java @@ -408,10 +408,10 @@ public class GpxSelectionHelper { boolean split = true; if (group.splitDistance > 0) { List trackSegments = r.splitByDistance(group.splitDistance, joinSegments); - as = trackSegments.toArray(new GPXTrackAnalysis[trackSegments.size()]); + as = trackSegments.toArray(new GPXTrackAnalysis[0]); } else if (group.splitTime > 0) { List trackSegments = r.splitByTime(group.splitTime, joinSegments); - as = trackSegments.toArray(new GPXTrackAnalysis[trackSegments.size()]); + as = trackSegments.toArray(new GPXTrackAnalysis[0]); } else { split = false; as = new GPXTrackAnalysis[] {GPXTrackAnalysis.segment(0, r)}; diff --git a/OsmAnd/src/net/osmand/plus/activities/MapActivityActions.java b/OsmAnd/src/net/osmand/plus/activities/MapActivityActions.java index 749c5371ea..5a6a7560a5 100644 --- a/OsmAnd/src/net/osmand/plus/activities/MapActivityActions.java +++ b/OsmAnd/src/net/osmand/plus/activities/MapActivityActions.java @@ -1148,7 +1148,7 @@ public class MapActivityActions implements DialogProvider { items.add(getString(R.string.show_location)); items.add(getString(R.string.shared_string_show_details)); AlertDialog.Builder menu = new AlertDialog.Builder(mapActivity); - menu.setItems(items.toArray(new String[items.size()]), new DialogInterface.OnClickListener() { + menu.setItems(items.toArray(new String[0]), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int item) { dialog.dismiss(); diff --git a/OsmAnd/src/net/osmand/plus/audionotes/AudioVideoNotesPlugin.java b/OsmAnd/src/net/osmand/plus/audionotes/AudioVideoNotesPlugin.java index b8d4ef0c92..92b991757b 100644 --- a/OsmAnd/src/net/osmand/plus/audionotes/AudioVideoNotesPlugin.java +++ b/OsmAnd/src/net/osmand/plus/audionotes/AudioVideoNotesPlugin.java @@ -1860,7 +1860,7 @@ public class AudioVideoNotesPlugin extends OsmandPlugin { protected Recording[] getRecordingsSorted() { checkRecordings(); Collection allObjects = getAllRecordings(); - Recording[] res = allObjects.toArray(new Recording[allObjects.size()]); + Recording[] res = allObjects.toArray(new Recording[0]); Arrays.sort(res, new Comparator() { @Override diff --git a/OsmAnd/src/net/osmand/plus/dashboard/DashChooseAppDirFragment.java b/OsmAnd/src/net/osmand/plus/dashboard/DashChooseAppDirFragment.java index 883010ea46..e976d0b4ea 100644 --- a/OsmAnd/src/net/osmand/plus/dashboard/DashChooseAppDirFragment.java +++ b/OsmAnd/src/net/osmand/plus/dashboard/DashChooseAppDirFragment.java @@ -223,7 +223,7 @@ public class DashChooseAppDirFragment { paths.add(""); types.add(OsmandSettings.EXTERNAL_STORAGE_TYPE_SPECIFIED); - editalert.setSingleChoiceItems(items.toArray(new String[items.size()]), selected, + editalert.setSingleChoiceItems(items.toArray(new String[0]), selected, new DialogInterface.OnClickListener() { @Override diff --git a/OsmAnd/src/net/osmand/plus/dialogs/ConfigureMapMenu.java b/OsmAnd/src/net/osmand/plus/dialogs/ConfigureMapMenu.java index 858f80e018..6e3b7fba8a 100644 --- a/OsmAnd/src/net/osmand/plus/dialogs/ConfigureMapMenu.java +++ b/OsmAnd/src/net/osmand/plus/dialogs/ConfigureMapMenu.java @@ -404,7 +404,7 @@ public class ConfigureMapMenu { bld.setTitle(R.string.map_magnifier); bld.setNegativeButton(R.string.shared_string_dismiss, null); DialogListItemAdapter dialogAdapter = DialogListItemAdapter.createSingleChoiceAdapter( - values.toArray(new String[values.size()]), nightMode, i, app, selectedProfileColor, themeRes, new View.OnClickListener() { + values.toArray(new String[0]), nightMode, i, app, selectedProfileColor, themeRes, new View.OnClickListener() { @Override public void onClick(View v) { int which = (int) v.getTag(); @@ -639,7 +639,7 @@ public class ConfigureMapMenu { return mp.get(lhs).compareTo(mp.get(rhs)); } }); - return lst.toArray(new String[lst.size()]); + return lst.toArray(new String[0]); } public static String[] getMapNamesValues(Context ctx, String[] ids) { diff --git a/OsmAnd/src/net/osmand/plus/download/DownloadFileHelper.java b/OsmAnd/src/net/osmand/plus/download/DownloadFileHelper.java index 36d2f21b85..c85d63361a 100644 --- a/OsmAnd/src/net/osmand/plus/download/DownloadFileHelper.java +++ b/OsmAnd/src/net/osmand/plus/download/DownloadFileHelper.java @@ -349,7 +349,7 @@ public class DownloadFileHelper { private int currentRead = 0; public CountingMultiInputStream(List streams) { - this.delegate = streams.toArray(new InputStream[streams.size()]); + this.delegate = streams.toArray(new InputStream[0]); } @Override diff --git a/OsmAnd/src/net/osmand/plus/download/ui/LocalIndexesFragment.java b/OsmAnd/src/net/osmand/plus/download/ui/LocalIndexesFragment.java index 4cf4f1154a..9160160973 100644 --- a/OsmAnd/src/net/osmand/plus/download/ui/LocalIndexesFragment.java +++ b/OsmAnd/src/net/osmand/plus/download/ui/LocalIndexesFragment.java @@ -582,7 +582,7 @@ public class LocalIndexesFragment extends OsmandExpandableListFragment implement operationTask = null; } if (operationTask != null) { - operationTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, selectedItems.toArray(new LocalIndexInfo[selectedItems.size()])); + operationTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, selectedItems.toArray(new LocalIndexInfo[0])); } if (actionMode != null) { actionMode.finish(); diff --git a/OsmAnd/src/net/osmand/plus/download/ui/UpdatesIndexFragment.java b/OsmAnd/src/net/osmand/plus/download/ui/UpdatesIndexFragment.java index 65baa93718..f7362edc76 100644 --- a/OsmAnd/src/net/osmand/plus/download/ui/UpdatesIndexFragment.java +++ b/OsmAnd/src/net/osmand/plus/download/ui/UpdatesIndexFragment.java @@ -166,12 +166,12 @@ public class UpdatesIndexFragment extends OsmAndListFragment implements Download dialog.setPositiveButton(R.string.shared_string_update, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { - getMyActivity().startDownload(indexItems.toArray(new IndexItem[indexItems.size()])); + getMyActivity().startDownload(indexItems.toArray(new IndexItem[0])); } }); dialog.create().show(); } else { - getMyActivity().startDownload(indexItems.toArray(new IndexItem[indexItems.size()])); + getMyActivity().startDownload(indexItems.toArray(new IndexItem[0])); } } }); diff --git a/OsmAnd/src/net/osmand/plus/helpers/ExternalApiHelper.java b/OsmAnd/src/net/osmand/plus/helpers/ExternalApiHelper.java index 6222663a00..da5f6359b0 100644 --- a/OsmAnd/src/net/osmand/plus/helpers/ExternalApiHelper.java +++ b/OsmAnd/src/net/osmand/plus/helpers/ExternalApiHelper.java @@ -871,7 +871,7 @@ public class ExternalApiHelper { searchTypes.add(HOUSE); searchTypes.add(STREET_INTERSECTION); } - searchSettings = searchSettings.setSearchTypes(searchTypes.toArray(new ObjectType[searchTypes.size()])); + searchSettings = searchSettings.setSearchTypes(searchTypes.toArray(new ObjectType[0])); core.search(searchQuery, false, null, searchSettings); } diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/DirectionIndicationDialogFragment.java b/OsmAnd/src/net/osmand/plus/mapmarkers/DirectionIndicationDialogFragment.java index d624ec7947..27ad98ece4 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/DirectionIndicationDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/DirectionIndicationDialogFragment.java @@ -277,7 +277,7 @@ public class DirectionIndicationDialogFragment extends BaseOsmAndDialogFragment } } ((ImageView) mainView.findViewById(R.id.action_bar_image)) - .setImageDrawable(new LayerDrawable(imgList.toArray(new Drawable[imgList.size()]))); + .setImageDrawable(new LayerDrawable(imgList.toArray(new Drawable[0]))); } else { mainView.findViewById(R.id.action_bar_image_container).setVisibility(View.GONE); } diff --git a/OsmAnd/src/net/osmand/plus/monitoring/OsmandMonitoringPlugin.java b/OsmAnd/src/net/osmand/plus/monitoring/OsmandMonitoringPlugin.java index ec255b1bbc..e6c5f2ff1b 100644 --- a/OsmAnd/src/net/osmand/plus/monitoring/OsmandMonitoringPlugin.java +++ b/OsmAnd/src/net/osmand/plus/monitoring/OsmandMonitoringPlugin.java @@ -73,7 +73,7 @@ public class OsmandMonitoringPlugin extends OsmandPlugin { super(app); liveMonitoringHelper = new LiveMonitoringHelper(app); final List am = ApplicationMode.allPossibleValues(); - ApplicationMode.regWidgetVisibility("monitoring", am.toArray(new ApplicationMode[am.size()])); + ApplicationMode.regWidgetVisibility("monitoring", am.toArray(new ApplicationMode[0])); settings = app.getSettings(); pluginPreferences.add(settings.SAVE_TRACK_TO_GPX); pluginPreferences.add(settings.SAVE_TRACK_INTERVAL); diff --git a/OsmAnd/src/net/osmand/plus/myplaces/AvailableGPXFragment.java b/OsmAnd/src/net/osmand/plus/myplaces/AvailableGPXFragment.java index 6bac2a31ea..48c1dca711 100644 --- a/OsmAnd/src/net/osmand/plus/myplaces/AvailableGPXFragment.java +++ b/OsmAnd/src/net/osmand/plus/myplaces/AvailableGPXFragment.java @@ -554,7 +554,7 @@ public class AvailableGPXFragment extends OsmandExpandableListFragment implement public void doAction(int actionResId) { if (actionResId == R.string.shared_string_delete) { operationTask = new DeleteGpxTask(); - operationTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, selectedItems.toArray(new GpxInfo[selectedItems.size()])); + operationTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, selectedItems.toArray(new GpxInfo[0])); } else { operationTask = null; } @@ -1009,7 +1009,7 @@ public class AvailableGPXFragment extends OsmandExpandableListFragment implement List progress = new ArrayList<>(); loadGPXFolder(mapPath, result, loadTask, progress, ""); if (!progress.isEmpty()) { - loadTask.loadFile(progress.toArray(new GpxInfo[progress.size()])); + loadTask.loadFile(progress.toArray(new GpxInfo[0])); } } } @@ -1029,7 +1029,7 @@ public class AvailableGPXFragment extends OsmandExpandableListFragment implement result.add(info); progress.add(info); if (progress.size() > 7) { - loadTask.loadFile(progress.toArray(new GpxInfo[progress.size()])); + loadTask.loadFile(progress.toArray(new GpxInfo[0])); progress.clear(); } } @@ -1475,7 +1475,7 @@ public class AvailableGPXFragment extends OsmandExpandableListFragment implement list.add(GPXDataSetType.SLOPE); } if (list.size() > 0) { - gpxItem.chartTypes = list.toArray(new GPXDataSetType[list.size()]); + gpxItem.chartTypes = list.toArray(new GPXDataSetType[0]); } final OsmandSettings settings = app.getSettings(); settings.setMapLocationToShow(gpxItem.locationStart.lat, gpxItem.locationStart.lon, diff --git a/OsmAnd/src/net/osmand/plus/myplaces/TrackSegmentFragment.java b/OsmAnd/src/net/osmand/plus/myplaces/TrackSegmentFragment.java index e53b51cf39..08c68ac3e8 100644 --- a/OsmAnd/src/net/osmand/plus/myplaces/TrackSegmentFragment.java +++ b/OsmAnd/src/net/osmand/plus/myplaces/TrackSegmentFragment.java @@ -410,7 +410,7 @@ public class TrackSegmentFragment extends OsmAndListFragment implements TrackBit tabTypeList.add(GPXTabItemType.GPX_TAB_ITEM_SPEED); } } - tabTypes = tabTypeList.toArray(new GPXTabItemType[tabTypeList.size()]); + tabTypes = tabTypeList.toArray(new GPXTabItemType[0]); Context context = tabs.getContext(); titles = new String[tabTypes.length]; diff --git a/OsmAnd/src/net/osmand/plus/osmedit/AddPOIAction.java b/OsmAnd/src/net/osmand/plus/osmedit/AddPOIAction.java index 1db6bd0542..a46ddb0ba1 100644 --- a/OsmAnd/src/net/osmand/plus/osmedit/AddPOIAction.java +++ b/OsmAnd/src/net/osmand/plus/osmedit/AddPOIAction.java @@ -222,8 +222,8 @@ public class AddPOIAction extends QuickAction { } addPoiToStringSet(getPoiTypes(activity).getOtherMapCategory(), tagKeys, valueKeys); tagKeys.addAll(EditPoiDialogFragment.BASIC_TAGS); - mAdapter.setTagData(tagKeys.toArray(new String[tagKeys.size()])); - mAdapter.setValueData(valueKeys.toArray(new String[valueKeys.size()])); + mAdapter.setTagData(tagKeys.toArray(new String[0])); + mAdapter.setValueData(valueKeys.toArray(new String[0])); Button addTagButton = (Button) view.findViewById(R.id.addTagButton); addTagButton.setOnClickListener(new View.OnClickListener() { @Override diff --git a/OsmAnd/src/net/osmand/plus/osmedit/AdvancedEditPoiFragment.java b/OsmAnd/src/net/osmand/plus/osmedit/AdvancedEditPoiFragment.java index b538ccd0c5..a99afa7a22 100644 --- a/OsmAnd/src/net/osmand/plus/osmedit/AdvancedEditPoiFragment.java +++ b/OsmAnd/src/net/osmand/plus/osmedit/AdvancedEditPoiFragment.java @@ -89,8 +89,8 @@ public class AdvancedEditPoiFragment extends BaseOsmAndFragment addPoiToStringSet(abstractPoiType, tagKeys, valueKeys); } addPoiToStringSet(mapPoiTypes.getOtherMapCategory(), tagKeys, valueKeys); - mAdapter.setTagData(tagKeys.toArray(new String[tagKeys.size()])); - mAdapter.setValueData(valueKeys.toArray(new String[valueKeys.size()])); + mAdapter.setTagData(tagKeys.toArray(new String[0])); + mAdapter.setValueData(valueKeys.toArray(new String[0])); Button addTagButton = (Button) view.findViewById(R.id.addTagButton); addTagButton.setOnClickListener(new View.OnClickListener() { @Override diff --git a/OsmAnd/src/net/osmand/plus/osmedit/OsmEditingPlugin.java b/OsmAnd/src/net/osmand/plus/osmedit/OsmEditingPlugin.java index 6382acb107..90da6cc65d 100644 --- a/OsmAnd/src/net/osmand/plus/osmedit/OsmEditingPlugin.java +++ b/OsmAnd/src/net/osmand/plus/osmedit/OsmEditingPlugin.java @@ -415,7 +415,7 @@ public class OsmEditingPlugin extends OsmandPlugin { public void onClick(DialogInterface dialog, int which) { List selectedItems = f.getSelectedItems(); sendGPXFiles(activity, f, - selectedItems.toArray(new GpxInfo[selectedItems.size()])); + selectedItems.toArray(new GpxInfo[0])); } }); return true; diff --git a/OsmAnd/src/net/osmand/plus/osmedit/OsmEditsFragment.java b/OsmAnd/src/net/osmand/plus/osmedit/OsmEditsFragment.java index 3c1733f7ac..e647c63f8f 100644 --- a/OsmAnd/src/net/osmand/plus/osmedit/OsmEditsFragment.java +++ b/OsmAnd/src/net/osmand/plus/osmedit/OsmEditsFragment.java @@ -296,7 +296,7 @@ public class OsmEditsFragment extends OsmAndListFragment implements ProgressDial item.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() { @Override public boolean onMenuItemClick(MenuItem item) { - uploadItems(osmEditsSelected.toArray(new OsmPoint[osmEditsSelected.size()])); + uploadItems(osmEditsSelected.toArray(new OsmPoint[0])); mode.finish(); return true; } @@ -594,7 +594,7 @@ public class OsmEditsFragment extends OsmAndListFragment implements ProgressDial public void onClick(int type) { List points = getPointsToExport(); new BackupOpenstreetmapPointAsyncTask(type, exportType).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, - points.toArray(new OsmPoint[points.size()])); + points.toArray(new OsmPoint[0])); } }; } diff --git a/OsmAnd/src/net/osmand/plus/osmedit/OsmEditsUploadListenerHelper.java b/OsmAnd/src/net/osmand/plus/osmedit/OsmEditsUploadListenerHelper.java index 1d09b522ab..4b6078265d 100644 --- a/OsmAnd/src/net/osmand/plus/osmedit/OsmEditsUploadListenerHelper.java +++ b/OsmAnd/src/net/osmand/plus/osmedit/OsmEditsUploadListenerHelper.java @@ -221,7 +221,7 @@ public class OsmEditsUploadListenerHelper implements OsmEditsUploadListener { new UploadingMultipleErrorDialogFragment(); Bundle bundle = new Bundle(); bundle.putSerializable(POINTS_WITH_ERRORS, - pointsWithErrors.toArray(new OsmPoint[pointsWithErrors.size()])); + pointsWithErrors.toArray(new OsmPoint[0])); bundle.putStringArray(POINT_NAMES, pointNames); bundle.putBooleanArray(HAS_ERROR, hasErrors); fragment.setArguments(bundle); diff --git a/OsmAnd/src/net/osmand/plus/osmedit/dialogs/PoiSubTypeDialogFragment.java b/OsmAnd/src/net/osmand/plus/osmedit/dialogs/PoiSubTypeDialogFragment.java index 53b9ce0677..4c75a384ae 100644 --- a/OsmAnd/src/net/osmand/plus/osmedit/dialogs/PoiSubTypeDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/osmedit/dialogs/PoiSubTypeDialogFragment.java @@ -36,7 +36,7 @@ public class PoiSubTypeDialogFragment extends DialogFragment { } else { addCategory(a, strings); } - final String[] subCats = strings.toArray(new String[strings.size()]); + final String[] subCats = strings.toArray(new String[0]); builder.setItems(subCats, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { diff --git a/OsmAnd/src/net/osmand/plus/osmedit/dialogs/PoiTypeDialogFragment.java b/OsmAnd/src/net/osmand/plus/osmedit/dialogs/PoiTypeDialogFragment.java index cdcf88fb0a..2278d8e8bd 100644 --- a/OsmAnd/src/net/osmand/plus/osmedit/dialogs/PoiTypeDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/osmedit/dialogs/PoiTypeDialogFragment.java @@ -31,7 +31,7 @@ public class PoiTypeDialogFragment extends DialogFragment { categories.add(category); } } - builder.setItems(vals.toArray(new String[vals.size()]), new Dialog.OnClickListener() { + builder.setItems(vals.toArray(new String[0]), new Dialog.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { PoiCategory aType = categories.get(which); diff --git a/OsmAnd/src/net/osmand/plus/resources/ResourceManager.java b/OsmAnd/src/net/osmand/plus/resources/ResourceManager.java index a87d5004bd..b70ded655b 100644 --- a/OsmAnd/src/net/osmand/plus/resources/ResourceManager.java +++ b/OsmAnd/src/net/osmand/plus/resources/ResourceManager.java @@ -1100,7 +1100,7 @@ public class ResourceManager { } } } - return readers.toArray(new BinaryMapIndexReader[readers.size()]); + return readers.toArray(new BinaryMapIndexReader[0]); } public BinaryMapIndexReader[] getTransportRoutingMapFiles() { @@ -1114,7 +1114,7 @@ public class ResourceManager { } } } - return readers.toArray(new BinaryMapIndexReader[readers.size()]); + return readers.toArray(new BinaryMapIndexReader[0]); } public BinaryMapIndexReader[] getQuickSearchFiles() { @@ -1129,7 +1129,7 @@ public class ResourceManager { } } } - return readers.toArray(new BinaryMapIndexReader[readers.size()]); + return readers.toArray(new BinaryMapIndexReader[0]); } public Map getIndexFileNames() { diff --git a/OsmAnd/src/net/osmand/plus/routing/RouteProvider.java b/OsmAnd/src/net/osmand/plus/routing/RouteProvider.java index a21b8898e6..37bb29d148 100644 --- a/OsmAnd/src/net/osmand/plus/routing/RouteProvider.java +++ b/OsmAnd/src/net/osmand/plus/routing/RouteProvider.java @@ -121,7 +121,7 @@ public class RouteProvider { list.add(r); } } - return list.toArray(new RouteService[list.size()]); + return list.toArray(new RouteService[0]); } } diff --git a/OsmAnd/src/net/osmand/plus/srtmplugin/SRTMPlugin.java b/OsmAnd/src/net/osmand/plus/srtmplugin/SRTMPlugin.java index 7035a18863..9e66f72f74 100644 --- a/OsmAnd/src/net/osmand/plus/srtmplugin/SRTMPlugin.java +++ b/OsmAnd/src/net/osmand/plus/srtmplugin/SRTMPlugin.java @@ -456,7 +456,7 @@ public class SRTMPlugin extends OsmandPlugin { List possibleValuesList = new ArrayList<>(Arrays.asList(p.getPossibleValues())); possibleValuesList.remove(CONTOUR_LINES_DISABLED_VALUE); - final String[] possibleValues = possibleValuesList.toArray(new String[possibleValuesList.size()]); + final String[] possibleValues = possibleValuesList.toArray(new String[0]); int i = possibleValuesList.indexOf(pref.get()); if (i >= 0) { diff --git a/OsmAnd/src/net/osmand/plus/views/layers/AidlMapLayer.java b/OsmAnd/src/net/osmand/plus/views/layers/AidlMapLayer.java index 580f0c3490..df110a14cb 100644 --- a/OsmAnd/src/net/osmand/plus/views/layers/AidlMapLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/layers/AidlMapLayer.java @@ -181,7 +181,7 @@ public class AidlMapLayer extends OsmandMapLayer implements IContextMenuProvider } if (imageRequests.size() > 0) { - executeTaskInBackground(new PointImageReaderTask(this), imageRequests.toArray(new String[imageRequests.size()])); + executeTaskInBackground(new PointImageReaderTask(this), imageRequests.toArray(new String[0])); } } mapTextLayer.putData(this, displayedPoints); diff --git a/OsmAnd/src/net/osmand/plus/views/layers/MapControlsLayer.java b/OsmAnd/src/net/osmand/plus/views/layers/MapControlsLayer.java index 6a4cf344c7..9a24d0aba6 100644 --- a/OsmAnd/src/net/osmand/plus/views/layers/MapControlsLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/layers/MapControlsLayer.java @@ -1387,7 +1387,7 @@ public class MapControlsLayer extends OsmandMapLayer { } bld.setTitle(R.string.map_magnifier); - bld.setSingleChoiceItems(values.toArray(new String[values.size()]), i, + bld.setSingleChoiceItems(values.toArray(new String[0]), i, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { diff --git a/OsmAnd/src/net/osmand/plus/voice/AbstractPrologCommandPlayer.java b/OsmAnd/src/net/osmand/plus/voice/AbstractPrologCommandPlayer.java index fe17c52ab5..b0b0be8baf 100644 --- a/OsmAnd/src/net/osmand/plus/voice/AbstractPrologCommandPlayer.java +++ b/OsmAnd/src/net/osmand/plus/voice/AbstractPrologCommandPlayer.java @@ -222,7 +222,7 @@ public abstract class AbstractPrologCommandPlayer implements CommandPlayer, Stat @Override public List execute(List listCmd){ - Struct list = new Struct(listCmd.toArray(new Term[listCmd.size()])); + Struct list = new Struct(listCmd.toArray(new Term[0])); Var result = new Var("RESULT"); //$NON-NLS-1$ List files = new ArrayList(); if(prologSystem == null) { diff --git a/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelDbHelper.java b/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelDbHelper.java index 8ed755cf50..df591f4020 100644 --- a/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelDbHelper.java +++ b/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelDbHelper.java @@ -216,7 +216,7 @@ public class TravelDbHelper { } query += ") "; if (params.size() > 0) { - SQLiteCursor cursor = conn.rawQuery(query, params.toArray(new String[params.size()])); + SQLiteCursor cursor = conn.rawQuery(query, params.toArray(new String[0])); if (cursor != null) { if (cursor.moveToFirst()) { do { @@ -468,7 +468,7 @@ public class TravelDbHelper { params.add(lang); } } - SQLiteCursor cursor = conn.rawQuery(query.toString(), params.toArray(new String[params.size()])); + SQLiteCursor cursor = conn.rawQuery(query.toString(), params.toArray(new String[0])); if (cursor != null && cursor.moveToFirst()) { do { WikivoyageSearchResult rs = new WikivoyageSearchResult(); diff --git a/OsmAnd/src/net/osmand/plus/wikivoyage/explore/ExploreTabFragment.java b/OsmAnd/src/net/osmand/plus/wikivoyage/explore/ExploreTabFragment.java index bedaa96810..88e814773b 100644 --- a/OsmAnd/src/net/osmand/plus/wikivoyage/explore/ExploreTabFragment.java +++ b/OsmAnd/src/net/osmand/plus/wikivoyage/explore/ExploreTabFragment.java @@ -341,7 +341,7 @@ public class ExploreTabFragment extends BaseOsmAndFragment implements DownloadEv res.add(item); } } - return res.toArray(new IndexItem[res.size()]); + return res.toArray(new IndexItem[0]); } @NonNull diff --git a/OsmAndCore-sample/src/net/osmand/core/samples/android/sample1/CurrentPositionHelper.java b/OsmAndCore-sample/src/net/osmand/core/samples/android/sample1/CurrentPositionHelper.java index e490925754..9be931434e 100644 --- a/OsmAndCore-sample/src/net/osmand/core/samples/android/sample1/CurrentPositionHelper.java +++ b/OsmAndCore-sample/src/net/osmand/core/samples/android/sample1/CurrentPositionHelper.java @@ -128,7 +128,7 @@ public class CurrentPositionHelper { } private void initCtx(SampleApplication app, List checkReaders) { - BinaryMapIndexReader[] rs = checkReaders.toArray(new BinaryMapIndexReader[checkReaders.size()]); + BinaryMapIndexReader[] rs = checkReaders.toArray(new BinaryMapIndexReader[0]); if (rs.length > 0) { RoutingConfiguration defCfg = RoutingConfiguration.getDefault().build("geocoding", 10, new HashMap()); From 6b161701688fb82cff942f2e5673f3844105e60c Mon Sep 17 00:00:00 2001 From: TacoTheDank Date: Thu, 19 Nov 2020 15:19:27 -0500 Subject: [PATCH 05/12] Performance: Iteration over 'keySet()' may be optimized --- .../osmand/binary/BinaryMapIndexReader.java | 5 +++-- .../java/net/osmand/map/TileSourceManager.java | 4 ++-- .../java/net/osmand/osm/MapRenderingTypes.java | 5 +++-- .../java/net/osmand/osm/edit/EntityParser.java | 5 +++-- .../java/net/osmand/osm/io/NetworkUtils.java | 4 ++-- .../render/RenderingRulesStoragePrinter.java | 12 ++++++------ .../net/osmand/util/GeoPointParserUtil.java | 4 ++-- OsmAnd/src/net/osmand/AndroidNetworkUtils.java | 4 ++-- .../osmand/plus/AppVersionUpgradeOnInit.java | 10 ++++++---- .../net/osmand/plus/FavouritesDbHelper.java | 10 ++++++---- .../plus/activities/SavingTrackHelper.java | 11 ++++++----- .../osmand/plus/api/FileSettingsAPIImpl.java | 6 +++--- ...WptCategoriesBottomSheetDialogFragment.java | 5 +++-- .../osmand/plus/osmedit/OsmEditsFragment.java | 6 +++--- .../osmedit/OsmEditsUploadListenerHelper.java | 9 +++++---- .../net/osmand/plus/poi/PoiFiltersHelper.java | 7 ++++--- .../src/net/osmand/plus/poi/PoiUIFilter.java | 18 +++++++++--------- .../plus/render/MapRenderRepositories.java | 5 +++-- .../osmand/plus/srtmplugin/TerrainLayer.java | 5 +++-- .../plus/views/layers/ContextMenuLayer.java | 10 ++++++---- .../osmand/plus/views/layers/MapTextLayer.java | 5 +++-- 21 files changed, 83 insertions(+), 67 deletions(-) diff --git a/OsmAnd-java/src/main/java/net/osmand/binary/BinaryMapIndexReader.java b/OsmAnd-java/src/main/java/net/osmand/binary/BinaryMapIndexReader.java index f9015ec48d..5e45a893ba 100644 --- a/OsmAnd-java/src/main/java/net/osmand/binary/BinaryMapIndexReader.java +++ b/OsmAnd-java/src/main/java/net/osmand/binary/BinaryMapIndexReader.java @@ -2501,8 +2501,9 @@ public class BinaryMapIndexReader { } } } - for (MapObject e : resMap.keySet()) { - Street s = resMap.get(e); + for (Entry entry : resMap.entrySet()) { + MapObject e = entry.getKey(); + Street s = entry.getValue(); if (e instanceof Building && MapUtils.getDistance(e.getLocation(), lat, lon) < 40) { Building b = (Building) e; System.out.println(b.getName() + " " + s); diff --git a/OsmAnd-java/src/main/java/net/osmand/map/TileSourceManager.java b/OsmAnd-java/src/main/java/net/osmand/map/TileSourceManager.java index 0bdcda71c9..d9924dc9c6 100644 --- a/OsmAnd-java/src/main/java/net/osmand/map/TileSourceManager.java +++ b/OsmAnd-java/src/main/java/net/osmand/map/TileSourceManager.java @@ -518,8 +518,8 @@ public class TileSourceManager { } if (override || !metainfo.exists()) { BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(metainfo))); - for (String key : properties.keySet()) { - writer.write("[" + key + "]\n" + properties.get(key) + "\n"); + for (Map.Entry entry : properties.entrySet()) { + writer.write("[" + entry.getKey() + "]\n" + entry.getValue() + "\n"); } writer.close(); } diff --git a/OsmAnd-java/src/main/java/net/osmand/osm/MapRenderingTypes.java b/OsmAnd-java/src/main/java/net/osmand/osm/MapRenderingTypes.java index d996678e44..bcbcbfc2b0 100644 --- a/OsmAnd-java/src/main/java/net/osmand/osm/MapRenderingTypes.java +++ b/OsmAnd-java/src/main/java/net/osmand/osm/MapRenderingTypes.java @@ -96,8 +96,9 @@ public abstract class MapRenderingTypes { Map common = new HashMap(); String ATTACHED_KEY = "seamark:attached"; String type = ""; - for (String s : tags.keySet()) { - String value = tags.get(s); + for (Entry entry : tags.entrySet()) { + String s = entry.getKey(); + String value = entry.getValue(); if (s.equals("seamark:type")) { type = value; common.put(ATTACHED_KEY, openSeaType(value)); diff --git a/OsmAnd-java/src/main/java/net/osmand/osm/edit/EntityParser.java b/OsmAnd-java/src/main/java/net/osmand/osm/edit/EntityParser.java index 8c3aef8163..9caa54b55c 100644 --- a/OsmAnd-java/src/main/java/net/osmand/osm/edit/EntityParser.java +++ b/OsmAnd-java/src/main/java/net/osmand/osm/edit/EntityParser.java @@ -33,9 +33,10 @@ public class EntityParser { if (mo.getEnName(false).length() == 0) { mo.setEnName(tags.get(OSMTagKey.NAME_EN.getValue())); } - for (String ts : tags.keySet()) { + for (Map.Entry entry : tags.entrySet()) { + String ts = entry.getKey(); if (ts.startsWith("name:") && !ts.equals(OSMTagKey.NAME_EN.getValue())) { - mo.setName(ts.substring(("name:").length()), tags.get(ts)); + mo.setName(ts.substring(("name:").length()), entry.getValue()); } } if (mo.getName().length() == 0) { diff --git a/OsmAnd-java/src/main/java/net/osmand/osm/io/NetworkUtils.java b/OsmAnd-java/src/main/java/net/osmand/osm/io/NetworkUtils.java index 28a1ec3fb9..e3d162826c 100644 --- a/OsmAnd-java/src/main/java/net/osmand/osm/io/NetworkUtils.java +++ b/OsmAnd-java/src/main/java/net/osmand/osm/io/NetworkUtils.java @@ -63,8 +63,8 @@ public class NetworkUtils { URL url; try { boolean firstPrm =!urlText.contains("?"); - for (String key : additionalMapData.keySet()) { - urlText += (firstPrm ? "?" : "&") + key + "=" + URLEncoder.encode(additionalMapData.get(key), "UTF-8"); + for (Map.Entry entry : additionalMapData.entrySet()) { + urlText += (firstPrm ? "?" : "&") + entry.getKey() + "=" + URLEncoder.encode(entry.getValue(), "UTF-8"); firstPrm = false; } log.info("Start uploading file to " + urlText + " " +fileToUpload.getName()); diff --git a/OsmAnd-java/src/main/java/net/osmand/render/RenderingRulesStoragePrinter.java b/OsmAnd-java/src/main/java/net/osmand/render/RenderingRulesStoragePrinter.java index 86d0c2cb73..3e36ae4e71 100644 --- a/OsmAnd-java/src/main/java/net/osmand/render/RenderingRulesStoragePrinter.java +++ b/OsmAnd-java/src/main/java/net/osmand/render/RenderingRulesStoragePrinter.java @@ -152,9 +152,9 @@ public class RenderingRulesStoragePrinter { for (int i = 0; i < 15; i++) { out.println("" + indent + ti + "RenderingRule rule" + i + " = null;"); } - for (String s : storage.renderingAttributes.keySet()) { - generateRenderingRule(storage, out, indent + ti, "rule", 0, storage.renderingAttributes.get(s)); - out.println("" + indent + ti + "storage.renderingAttributes.put(" + javaString(s) + ", rule0);"); + for (Entry entry : storage.renderingAttributes.entrySet()) { + generateRenderingRule(storage, out, indent + ti, "rule", 0, entry.getValue()); + out.println("" + indent + ti + "storage.renderingAttributes.put(" + javaString(entry.getKey()) + ", rule0);"); } out.println(""+indent +"}"); } @@ -242,9 +242,9 @@ public class RenderingRulesStoragePrinter { private void printJavaInitConstants(RenderingRulesStorage storage, PrintStream out, String indent, String ti) { out.println("\n" + indent + "public void initConstants() {"); - for (String s : storage.renderingConstants.keySet()) { - out.println("" + indent + ti + "storage.renderingConstants.put(" + javaString(s) + ", " - + javaString(storage.renderingConstants.get(s)) + ");"); + for (Entry entry : storage.renderingConstants.entrySet()) { + out.println("" + indent + ti + "storage.renderingConstants.put(" + javaString(entry.getKey()) + ", " + + javaString(entry.getValue()) + ");"); } out.println(""+indent +"}"); } diff --git a/OsmAnd-java/src/main/java/net/osmand/util/GeoPointParserUtil.java b/OsmAnd-java/src/main/java/net/osmand/util/GeoPointParserUtil.java index 1383f4ae4a..31605c33a2 100644 --- a/OsmAnd-java/src/main/java/net/osmand/util/GeoPointParserUtil.java +++ b/OsmAnd-java/src/main/java/net/osmand/util/GeoPointParserUtil.java @@ -803,10 +803,10 @@ public class GeoPointParserUtil { if (map.size() > 0) uriString += "?"; int i = 0; - for (String key : map.keySet()) { + for (Map.Entry entry : map.entrySet()) { if (i > 0) uriString += "&"; - uriString += key + "=" + map.get(key); + uriString += entry.getKey() + "=" + entry.getValue(); i++; } return uriString; diff --git a/OsmAnd/src/net/osmand/AndroidNetworkUtils.java b/OsmAnd/src/net/osmand/AndroidNetworkUtils.java index d1ca9aa7ab..f8710927ef 100644 --- a/OsmAnd/src/net/osmand/AndroidNetworkUtils.java +++ b/OsmAnd/src/net/osmand/AndroidNetworkUtils.java @@ -305,8 +305,8 @@ public class AndroidNetworkUtils { try { boolean firstPrm = !urlText.contains("?"); StringBuilder sb = new StringBuilder(urlText); - for (String key : additionalParams.keySet()) { - sb.append(firstPrm ? "?" : "&").append(key).append("=").append(URLEncoder.encode(additionalParams.get(key), "UTF-8")); + for (Map.Entry entry : additionalParams.entrySet()) { + sb.append(firstPrm ? "?" : "&").append(entry.getKey()).append("=").append(URLEncoder.encode(entry.getValue(), "UTF-8")); firstPrm = false; } urlText = sb.toString(); diff --git a/OsmAnd/src/net/osmand/plus/AppVersionUpgradeOnInit.java b/OsmAnd/src/net/osmand/plus/AppVersionUpgradeOnInit.java index 9eeec4542b..1a80997ab3 100644 --- a/OsmAnd/src/net/osmand/plus/AppVersionUpgradeOnInit.java +++ b/OsmAnd/src/net/osmand/plus/AppVersionUpgradeOnInit.java @@ -190,14 +190,15 @@ class AppVersionUpgradeOnInit { migrateEnumPreferences(); SharedPreferences globalSharedPreferences = (SharedPreferences) settings.getGlobalPreferences(); Map globalPrefsMap = globalSharedPreferences.getAll(); - for (String key : globalPrefsMap.keySet()) { + for (Map.Entry entry : globalPrefsMap.entrySet()) { + String key = entry.getKey(); OsmandPreference pref = settings.getPreference(key); if (pref instanceof CommonPreference) { CommonPreference commonPreference = (CommonPreference) pref; if (!commonPreference.isGlobal()) { for (ApplicationMode mode : ApplicationMode.allPossibleValues()) { if (!commonPreference.isSetForMode(mode) && !commonPreference.hasDefaultValueForMode(mode)) { - settings.setPreference(key, globalPrefsMap.get(key), mode); + settings.setPreference(key, entry.getValue(), mode); } } } @@ -205,12 +206,13 @@ class AppVersionUpgradeOnInit { } SharedPreferences defaultProfilePreferences = (SharedPreferences) settings.getProfilePreferences(ApplicationMode.DEFAULT); Map defaultPrefsMap = defaultProfilePreferences.getAll(); - for (String key : defaultPrefsMap.keySet()) { + for (Map.Entry entry : defaultPrefsMap.entrySet()) { + String key = entry.getKey(); OsmandPreference pref = settings.getPreference(key); if (pref instanceof CommonPreference) { CommonPreference commonPreference = (CommonPreference) pref; if (commonPreference.isGlobal() && !commonPreference.isSet()) { - settings.setPreference(key, defaultPrefsMap.get(key)); + settings.setPreference(key, entry.getValue()); } } } diff --git a/OsmAnd/src/net/osmand/plus/FavouritesDbHelper.java b/OsmAnd/src/net/osmand/plus/FavouritesDbHelper.java index c1db6114bc..2cd9a6ab4a 100644 --- a/OsmAnd/src/net/osmand/plus/FavouritesDbHelper.java +++ b/OsmAnd/src/net/osmand/plus/FavouritesDbHelper.java @@ -261,10 +261,11 @@ public class FavouritesDbHelper { private boolean merge(Map source, Map destination) { boolean changed = false; - for (String ks : source.keySet()) { + for (Map.Entry entry : source.entrySet()) { + String ks = entry.getKey(); if (!destination.containsKey(ks)) { changed = true; - destination.put(ks, source.get(ks)); + destination.put(ks, entry.getValue()); } } return changed; @@ -712,9 +713,10 @@ public class FavouritesDbHelper { public boolean isGroupVisible(String name) { String nameLowercase = name.toLowerCase(); - for (String groupName : flatGroups.keySet()) { + for (Map.Entry entry : flatGroups.entrySet()) { + String groupName = entry.getKey(); if (groupName.toLowerCase().equals(nameLowercase) || FavoriteGroup.getDisplayName(context, groupName).equals(name)) { - return flatGroups.get(groupName).isVisible(); + return entry.getValue().isVisible(); } } return false; diff --git a/OsmAnd/src/net/osmand/plus/activities/SavingTrackHelper.java b/OsmAnd/src/net/osmand/plus/activities/SavingTrackHelper.java index 5bf6c2b0a1..8b57c68e49 100644 --- a/OsmAnd/src/net/osmand/plus/activities/SavingTrackHelper.java +++ b/OsmAnd/src/net/osmand/plus/activities/SavingTrackHelper.java @@ -208,11 +208,12 @@ public class SavingTrackHelper extends SQLiteOpenHelper { Map data = collectRecordedData(); // save file - for (final String f : data.keySet()) { + for (final Map.Entry entry : data.entrySet()) { + final String f = entry.getKey(); log.debug("Filename: " + f); File fout = new File(dir, f + IndexConstants.GPX_FILE_EXT); - if (!data.get(f).isEmpty()) { - WptPt pt = data.get(f).findPointToShow(); + if (!entry.getValue().isEmpty()) { + WptPt pt = entry.getValue().findPointToShow(); String fileName = f + "_" + new SimpleDateFormat("HH-mm_EEE", Locale.US).format(new Date(pt.time)); //$NON-NLS-1$ Integer trackStorageDirectory = ctx.getSettings().TRACK_STORAGE_DIRECTORY.get(); if (!OsmandSettings.REC_DIRECTORY.equals(trackStorageDirectory)) { @@ -235,13 +236,13 @@ public class SavingTrackHelper extends SQLiteOpenHelper { } } - Exception warn = GPXUtilities.writeGpxFile(fout, data.get(f)); + Exception warn = GPXUtilities.writeGpxFile(fout, entry.getValue()); if (warn != null) { warnings.add(warn.getMessage()); return new SaveGpxResult(warnings, new ArrayList()); } - GPXFile gpx = data.get(f); + GPXFile gpx = entry.getValue(); GPXTrackAnalysis analysis = gpx.getAnalysis(fout.lastModified()); GpxDataItem item = new GpxDataItem(fout, analysis); ctx.getGpxDbHelper().add(item); diff --git a/OsmAnd/src/net/osmand/plus/api/FileSettingsAPIImpl.java b/OsmAnd/src/net/osmand/plus/api/FileSettingsAPIImpl.java index 6a8b8a1b06..ab30a9a102 100644 --- a/OsmAnd/src/net/osmand/plus/api/FileSettingsAPIImpl.java +++ b/OsmAnd/src/net/osmand/plus/api/FileSettingsAPIImpl.java @@ -25,9 +25,9 @@ public class FileSettingsAPIImpl implements SettingsAPI { Properties props = new Properties(); FileInputStream fis = new FileInputStream(file); props.load(fis); - for (Object key : props.keySet()) { - String k = key.toString(); - map.put(k, props.get(key)); + for (Entry entry : props.entrySet()) { + String k = entry.getKey().toString(); + map.put(k, entry.getValue()); } } } diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/SelectWptCategoriesBottomSheetDialogFragment.java b/OsmAnd/src/net/osmand/plus/mapmarkers/SelectWptCategoriesBottomSheetDialogFragment.java index d676372223..0c887488b7 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/SelectWptCategoriesBottomSheetDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/SelectWptCategoriesBottomSheetDialogFragment.java @@ -81,7 +81,8 @@ public class SelectWptCategoriesBottomSheetDialogFragment extends MenuBottomShee Map> pointsByCategories = gpxFile.getPointsByCategories(); - for (String category : pointsByCategories.keySet()) { + for (Map.Entry> entry : pointsByCategories.entrySet()) { + String category = entry.getKey(); final BottomSheetItemWithCompoundButton[] categoryItem = new BottomSheetItemWithCompoundButton[1]; categoryItem[0] = (BottomSheetItemWithCompoundButton) new BottomSheetItemWithCompoundButton.Builder() .setChecked(!isUpdateMode || (categories != null && categories.contains(category))) @@ -96,7 +97,7 @@ public class SelectWptCategoriesBottomSheetDialogFragment extends MenuBottomShee } }) .setCompoundButtonColorId(activeColorResId) - .setDescription(String.valueOf(pointsByCategories.get(category).size())) + .setDescription(String.valueOf(entry.getValue().size())) .setIcon(getContentIcon(R.drawable.ic_action_folder)) .setTitle(category.equals("") ? getString(R.string.shared_string_waypoints) : category) .setLayoutId(R.layout.bottom_sheet_item_with_descr_and_checkbox_56dp) diff --git a/OsmAnd/src/net/osmand/plus/osmedit/OsmEditsFragment.java b/OsmAnd/src/net/osmand/plus/osmedit/OsmEditsFragment.java index e647c63f8f..380eeb8850 100644 --- a/OsmAnd/src/net/osmand/plus/osmedit/OsmEditsFragment.java +++ b/OsmAnd/src/net/osmand/plus/osmedit/OsmEditsFragment.java @@ -684,9 +684,9 @@ public class OsmEditsFragment extends OsmAndListFragment implements ProgressDial @Override public void uploadEnded(Map loadErrorsMap) { super.uploadEnded(loadErrorsMap); - for (OsmPoint osmPoint : loadErrorsMap.keySet()) { - if (loadErrorsMap.get(osmPoint) == null) { - osmEdits.remove(osmPoint); + for (Map.Entry entry : loadErrorsMap.entrySet()) { + if (entry.getValue() == null) { + osmEdits.remove(entry.getKey()); } } recreateAdapterData(); diff --git a/OsmAnd/src/net/osmand/plus/osmedit/OsmEditsUploadListenerHelper.java b/OsmAnd/src/net/osmand/plus/osmedit/OsmEditsUploadListenerHelper.java index 4b6078265d..cbc37e1ea2 100644 --- a/OsmAnd/src/net/osmand/plus/osmedit/OsmEditsUploadListenerHelper.java +++ b/OsmAnd/src/net/osmand/plus/osmedit/OsmEditsUploadListenerHelper.java @@ -59,8 +59,8 @@ public class OsmEditsUploadListenerHelper implements OsmEditsUploadListener { } int uploaded = 0; int pointsNum = loadErrorsMap.keySet().size(); - for (OsmPoint point : loadErrorsMap.keySet()) { - if (loadErrorsMap.get(point) == null) { + for (String s : loadErrorsMap.values()) { + if (s == null) { uploaded++; } } @@ -200,13 +200,14 @@ public class OsmEditsUploadListenerHelper implements OsmEditsUploadListener { boolean[] hasErrors = new boolean[loadErrorsMap.keySet().size()]; ArrayList pointsWithErrors = new ArrayList<>(); int i = 0; - for (OsmPoint point : loadErrorsMap.keySet()) { + for (Map.Entry entry : loadErrorsMap.entrySet()) { + OsmPoint point = entry.getKey(); pointNames[i] = point.getGroup() == OsmPoint.Group.BUG ? ((OsmNotesPoint) point).getText() : ((OpenstreetmapPoint) point).getName(); pointNames[i] = TextUtils.isEmpty(pointNames[i]) ? "id:" + point.getId() : pointNames[i]; - hasErrors[i] = loadErrorsMap.get(point) != null; + hasErrors[i] = entry.getValue() != null; if (hasErrors[i]) { pointsWithErrors.add(point); } diff --git a/OsmAnd/src/net/osmand/plus/poi/PoiFiltersHelper.java b/OsmAnd/src/net/osmand/plus/poi/PoiFiltersHelper.java index d586516fc5..93871dfca4 100644 --- a/OsmAnd/src/net/osmand/plus/poi/PoiFiltersHelper.java +++ b/OsmAnd/src/net/osmand/plus/poi/PoiFiltersHelper.java @@ -751,14 +751,15 @@ public class PoiFiltersHelper { } Map> types = p.getAcceptedTypes(); SQLiteStatement insertCategories = db.compileStatement("INSERT INTO " + CATEGORIES_NAME + " VALUES (?, ?, ?)"); - for (PoiCategory a : types.keySet()) { - if (types.get(a) == null) { + for (Map.Entry> entry : types.entrySet()) { + PoiCategory a = entry.getKey(); + if (entry.getValue() == null) { insertCategories.bindString(1, p.getFilterId()); insertCategories.bindString(2, a.getKeyName()); insertCategories.bindNull(3); insertCategories.execute(); } else { - for (String s : types.get(a)) { + for (String s : entry.getValue()) { insertCategories.bindString(1, p.getFilterId()); insertCategories.bindString(2, a.getKeyName()); insertCategories.bindString(3, s); diff --git a/OsmAnd/src/net/osmand/plus/poi/PoiUIFilter.java b/OsmAnd/src/net/osmand/plus/poi/PoiUIFilter.java index 6629228696..1d3449640f 100644 --- a/OsmAnd/src/net/osmand/plus/poi/PoiUIFilter.java +++ b/OsmAnd/src/net/osmand/plus/poi/PoiUIFilter.java @@ -535,20 +535,19 @@ public class PoiUIFilter implements SearchPoiTypeFilter, Comparable return getName(); } StringBuilder res = new StringBuilder(); - for (PoiCategory p : acceptedTypes.keySet()) { - LinkedHashSet set = acceptedTypes.get(p); + for (Entry> entry : acceptedTypes.entrySet()) { + LinkedHashSet set = entry.getValue(); if (set == null) { if (res.length() > 0) { res.append(", "); } - res.append(p.getTranslation()); + res.append(entry.getKey().getTranslation()); } if (res.length() > chars) { return res.toString(); } } - for (PoiCategory p : acceptedTypes.keySet()) { - LinkedHashSet set = acceptedTypes.get(p); + for (LinkedHashSet set : acceptedTypes.values()) { if (set != null) { for (String st : set) { if (res.length() > 0) { @@ -616,8 +615,8 @@ public class PoiUIFilter implements SearchPoiTypeFilter, Comparable public boolean areAllTypesAccepted() { if (poiTypes.getCategories(false).size() == acceptedTypes.size()) { - for (PoiCategory a : acceptedTypes.keySet()) { - if (acceptedTypes.get(a) != null) { + for (LinkedHashSet strings : acceptedTypes.values()) { + if (strings != null) { return false; } } @@ -711,8 +710,9 @@ public class PoiUIFilter implements SearchPoiTypeFilter, Comparable } private void putAllAcceptedTypes(Map> types) { - for (PoiCategory category : types.keySet()) { - LinkedHashSet typesSet = types.get(category); + for (Entry> entry : types.entrySet()) { + PoiCategory category = entry.getKey(); + LinkedHashSet typesSet = entry.getValue(); if (acceptedTypes.containsKey(category)) { if (acceptedTypes.get(category) != null && typesSet != null) { acceptedTypes.get(category).addAll(typesSet); diff --git a/OsmAnd/src/net/osmand/plus/render/MapRenderRepositories.java b/OsmAnd/src/net/osmand/plus/render/MapRenderRepositories.java index 8bc8d1b51a..26985faa0a 100644 --- a/OsmAnd/src/net/osmand/plus/render/MapRenderRepositories.java +++ b/OsmAnd/src/net/osmand/plus/render/MapRenderRepositories.java @@ -311,8 +311,9 @@ public class MapRenderRepositories { } boolean containsJapanMapData = false; boolean useLive = context.getSettings().USE_OSM_LIVE_FOR_ROUTING.get(); - for (String mapName : files.keySet()) { - BinaryMapIndexReader fr = files.get(mapName); + for (Map.Entry entry : files.entrySet()) { + String mapName = entry.getKey(); + BinaryMapIndexReader fr = entry.getValue(); if (fr != null && (fr.containsMapData(leftX, topY, rightX, bottomY, zoom) || fr.containsRouteData(leftX, topY, rightX, bottomY, zoom))) { if (!nativeFiles.contains(mapName)) { diff --git a/OsmAnd/src/net/osmand/plus/srtmplugin/TerrainLayer.java b/OsmAnd/src/net/osmand/plus/srtmplugin/TerrainLayer.java index b58dc807a8..4ffab5f7c7 100644 --- a/OsmAnd/src/net/osmand/plus/srtmplugin/TerrainLayer.java +++ b/OsmAnd/src/net/osmand/plus/srtmplugin/TerrainLayer.java @@ -114,12 +114,13 @@ public class TerrainLayer extends MapTileLayer { } private void indexNonCachedResources(Map fileModified, Map rs) { - for(String filename : fileModified.keySet()) { + for(Map.Entry entry : fileModified.entrySet()) { + String filename = entry.getKey(); try { log.info("Indexing " + type + " file " + filename); ContentValues cv = new ContentValues(); cv.put("filename", filename); - cv.put("date_modified", fileModified.get(filename)); + cv.put("date_modified", entry.getValue()); SQLiteTileSource ts = rs.get(filename); QuadRect rt = ts.getRectBoundary(ZOOM_BOUNDARY, 1); if (rt != null) { diff --git a/OsmAnd/src/net/osmand/plus/views/layers/ContextMenuLayer.java b/OsmAnd/src/net/osmand/plus/views/layers/ContextMenuLayer.java index 7a8690fe2d..9ba3ee5f46 100644 --- a/OsmAnd/src/net/osmand/plus/views/layers/ContextMenuLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/layers/ContextMenuLayer.java @@ -232,20 +232,22 @@ public class ContextMenuLayer extends OsmandMapLayer { if (!pressedLatLonSmall.isEmpty() || !pressedLatLonFull.isEmpty()) { textScale = activity.getMyApplication().getSettings().TEXT_SCALE.get(); } - for (LatLon latLon : pressedLatLonSmall.keySet()) { + for (Entry entry : pressedLatLonSmall.entrySet()) { + LatLon latLon = entry.getKey(); int x = (int) box.getPixXFromLatLon(latLon.getLatitude(), latLon.getLongitude()); int y = (int) box.getPixYFromLatLon(latLon.getLatitude(), latLon.getLongitude()); - BackgroundType background = pressedLatLonSmall.get(latLon); + BackgroundType background = entry.getValue(); Bitmap pressedBitmapSmall = background.getTouchBackground(activity, true); Rect destRect = getIconDestinationRect( x, y, pressedBitmapSmall.getWidth(), pressedBitmapSmall.getHeight(), textScale); canvas.drawBitmap(pressedBitmapSmall, null, destRect, paint); } - for (LatLon latLon : pressedLatLonFull.keySet()) { + for (Entry entry : pressedLatLonFull.entrySet()) { + LatLon latLon = entry.getKey(); int x = (int) box.getPixXFromLatLon(latLon.getLatitude(), latLon.getLongitude()); int y = (int) box.getPixYFromLatLon(latLon.getLatitude(), latLon.getLongitude()); - BackgroundType background = pressedLatLonFull.get(latLon); + BackgroundType background = entry.getValue(); Bitmap pressedBitmap = background.getTouchBackground(activity, false); int offsetY = background.getOffsetY(activity, textScale); Rect destRect = getIconDestinationRect( diff --git a/OsmAnd/src/net/osmand/plus/views/layers/MapTextLayer.java b/OsmAnd/src/net/osmand/plus/views/layers/MapTextLayer.java index 991bed0d55..fe9d82fe99 100644 --- a/OsmAnd/src/net/osmand/plus/views/layers/MapTextLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/layers/MapTextLayer.java @@ -61,7 +61,8 @@ public class MapTextLayer extends OsmandMapLayer { @Override public void onPrepareBufferImage(Canvas canvas, RotatedTileBox tileBox, DrawSettings settings) { TIntHashSet set = new TIntHashSet(); - for (OsmandMapLayer l : textObjects.keySet()) { + for (Map.Entry> entry : textObjects.entrySet()) { + OsmandMapLayer l = entry.getKey(); MapTextProvider provider = (MapTextProvider) l; if (!view.isLayerVisible(l) || !provider.isTextVisible()) { continue; @@ -69,7 +70,7 @@ public class MapTextLayer extends OsmandMapLayer { updateTextSize(); paintTextIcon.setFakeBoldText(provider.isFakeBoldText()); - for (Object o : textObjects.get(l)) { + for (Object o : entry.getValue()) { LatLon loc = provider.getTextLocation(o); String name = provider.getText(o); if (loc == null || TextUtils.isEmpty(name)) { From 901827458f14156b9df036f171595f1a1754a636 Mon Sep 17 00:00:00 2001 From: TacoTheDank Date: Thu, 19 Nov 2020 15:20:30 -0500 Subject: [PATCH 06/12] Performance: 'List.remove()' called in loop --- .../java/net/osmand/router/TransportStopsRouteReader.java | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/OsmAnd-java/src/main/java/net/osmand/router/TransportStopsRouteReader.java b/OsmAnd-java/src/main/java/net/osmand/router/TransportStopsRouteReader.java index 7428196332..13da3748bb 100644 --- a/OsmAnd-java/src/main/java/net/osmand/router/TransportStopsRouteReader.java +++ b/OsmAnd-java/src/main/java/net/osmand/router/TransportStopsRouteReader.java @@ -325,9 +325,7 @@ public class TransportStopsRouteReader { // merge first part if (commonStopFirst < commonStopSecond || (commonStopFirst == commonStopSecond && firstSegment.get(0).isMissingStop())) { - for (int i = 0; i <= commonStopFirst; i++) { - firstSegment.remove(0); - } + firstSegment.subList(0, commonStopFirst + 1).clear(); for (int i = commonStopSecond; i >= 0; i--) { firstSegment.add(0, segmentToMerge.get(i)); } From 6f60a6298ce80b2b72db5f9c56dde482caa370a1 Mon Sep 17 00:00:00 2001 From: TacoTheDank Date: Thu, 19 Nov 2020 15:20:51 -0500 Subject: [PATCH 07/12] Performance: HashMap replaceable with EnumMap --- .../osmand/plus/settings/backend/backup/SettingsHelper.java | 5 +++-- .../plus/settings/fragments/ImportSettingsFragment.java | 3 ++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/settings/backend/backup/SettingsHelper.java b/OsmAnd/src/net/osmand/plus/settings/backend/backup/SettingsHelper.java index 424bf42ad3..c07fe0f892 100644 --- a/OsmAnd/src/net/osmand/plus/settings/backend/backup/SettingsHelper.java +++ b/OsmAnd/src/net/osmand/plus/settings/backend/backup/SettingsHelper.java @@ -55,6 +55,7 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.Comparator; +import java.util.EnumMap; import java.util.HashMap; import java.util.LinkedHashMap; import java.util.List; @@ -473,7 +474,7 @@ public class SettingsHelper { public List getFilteredSettingsItems(List settingsTypes, boolean globalExport) { Map> dataList = getAdditionalData(globalExport); - Map> typesMap = new HashMap<>(); + Map> typesMap = new EnumMap<>(ExportSettingsType.class); for (List objects : dataList.values()) { for (ExportDataObject exportObject : objects) { typesMap.put(exportObject.getType(), exportObject.getItems()); @@ -828,7 +829,7 @@ public class SettingsHelper { } public static Map> getSettingsToOperate(List settingsItems, boolean importComplete) { - Map> settingsToOperate = new HashMap<>(); + Map> settingsToOperate = new EnumMap<>(ExportSettingsType.class); List profiles = new ArrayList<>(); List quickActions = new ArrayList<>(); List poiUIFilters = new ArrayList<>(); diff --git a/OsmAnd/src/net/osmand/plus/settings/fragments/ImportSettingsFragment.java b/OsmAnd/src/net/osmand/plus/settings/fragments/ImportSettingsFragment.java index 816d5517dc..f45abf6d18 100644 --- a/OsmAnd/src/net/osmand/plus/settings/fragments/ImportSettingsFragment.java +++ b/OsmAnd/src/net/osmand/plus/settings/fragments/ImportSettingsFragment.java @@ -76,6 +76,7 @@ import org.apache.commons.logging.Log; import java.io.File; import java.lang.ref.WeakReference; import java.util.ArrayList; +import java.util.EnumMap; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -200,7 +201,7 @@ public class ImportSettingsFragment extends BaseOsmAndFragment { } adapter = new ExportImportSettingsAdapter(app, nightMode, true); - Map> itemsMap = new HashMap<>(); + Map> itemsMap = new EnumMap<>(ExportSettingsType.class); if (settingsItems != null) { itemsMap = SettingsHelper.getSettingsToOperate(settingsItems, false); adapter.updateSettingsList(itemsMap); From 0fa24bdc8e71d34653ba555eb5f4ba9708742ab4 Mon Sep 17 00:00:00 2001 From: TacoTheDank Date: Thu, 19 Nov 2020 15:22:11 -0500 Subject: [PATCH 08/12] Performance: Redundant 'Collection.addAll()' call --- OsmAnd-java/src/main/java/com/google/protobuf/FieldSet.java | 3 +-- .../com/wdtinc/mapbox_vector_tile/adapt/jts/JtsAdapter.java | 3 +-- .../src/main/java/net/osmand/render/RenderingRulesStorage.java | 3 +-- OsmAnd/src/net/osmand/plus/TargetPointsHelper.java | 3 +-- OsmAnd/src/net/osmand/plus/mapcontextmenu/MenuBuilder.java | 3 +-- OsmAnd/src/net/osmand/plus/osmedit/EditPoiDialogFragment.java | 3 +-- OsmAnd/src/net/osmand/plus/poi/PoiFiltersHelper.java | 3 +-- 7 files changed, 7 insertions(+), 14 deletions(-) diff --git a/OsmAnd-java/src/main/java/com/google/protobuf/FieldSet.java b/OsmAnd-java/src/main/java/com/google/protobuf/FieldSet.java index 2663694fc3..02ec66309e 100644 --- a/OsmAnd-java/src/main/java/com/google/protobuf/FieldSet.java +++ b/OsmAnd-java/src/main/java/com/google/protobuf/FieldSet.java @@ -242,8 +242,7 @@ final class FieldSet nextPolyGeom = new ArrayList<>(); boolean valid = true; // Add exterior ring @@ -362,7 +361,7 @@ public final class JtsAdapter { CoordinateArrays.reverse(exteriorRing.getCoordinates()); } - nextPolyGeom.addAll(linesToGeomCmds(exteriorRing, mvtClosePath, cursor, 2)); + final List nextPolyGeom = new ArrayList<>(linesToGeomCmds(exteriorRing, mvtClosePath, cursor, 2)); // Add interior rings diff --git a/OsmAnd-java/src/main/java/net/osmand/render/RenderingRulesStorage.java b/OsmAnd-java/src/main/java/net/osmand/render/RenderingRulesStorage.java index 11ac95cbd5..cf97dd520c 100644 --- a/OsmAnd-java/src/main/java/net/osmand/render/RenderingRulesStorage.java +++ b/OsmAnd-java/src/main/java/net/osmand/render/RenderingRulesStorage.java @@ -432,8 +432,7 @@ public class RenderingRulesStorage { for(RenderingRule ch : caseChildren) { List apply = applyRules; if(!renderingRule.getIfChildren().isEmpty()) { - apply = new ArrayList(); - apply.addAll(renderingRule.getIfChildren()); + apply = new ArrayList<>(renderingRule.getIfChildren()); if(applyRules != null) { apply.addAll(applyRules); } diff --git a/OsmAnd/src/net/osmand/plus/TargetPointsHelper.java b/OsmAnd/src/net/osmand/plus/TargetPointsHelper.java index 01ee06e16f..4221ffa308 100644 --- a/OsmAnd/src/net/osmand/plus/TargetPointsHelper.java +++ b/OsmAnd/src/net/osmand/plus/TargetPointsHelper.java @@ -345,8 +345,7 @@ public class TargetPointsHelper { } public List getIntermediatePointsWithTarget() { - List res = new ArrayList<>(); - res.addAll(this.intermediatePoints); + List res = new ArrayList<>(this.intermediatePoints); if(pointToNavigate != null) { res.add(pointToNavigate); } diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/MenuBuilder.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/MenuBuilder.java index 1aa35b8589..9d8030f0a2 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/MenuBuilder.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/MenuBuilder.java @@ -367,8 +367,7 @@ public class MenuBuilder { @Override public void onFinish(List cardList) { if (!isHidden()) { - List cards = new ArrayList<>(); - cards.addAll(cardList); + List cards = new ArrayList(cardList); if (cardList.size() == 0) { cards.add(new NoImagesCard(mapActivity)); } diff --git a/OsmAnd/src/net/osmand/plus/osmedit/EditPoiDialogFragment.java b/OsmAnd/src/net/osmand/plus/osmedit/EditPoiDialogFragment.java index ecdc776c78..fbf1ae9b96 100644 --- a/OsmAnd/src/net/osmand/plus/osmedit/EditPoiDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/osmedit/EditPoiDialogFragment.java @@ -427,8 +427,7 @@ public class EditPoiDialogFragment extends BaseOsmAndDialogFragment { f.setArguments(args); f.show(getChildFragmentManager(), "exceedDialog"); } else if (TextUtils.isEmpty(poiTypeEditText.getText())) { - HashSet tagsCopy = new HashSet<>(); - tagsCopy.addAll(editPoiData.getTagValues().keySet()); + new HashSet<>(editPoiData.getTagValues().keySet()); if (Algorithms.isEmpty(editPoiData.getTag(OSMSettings.OSMTagKey.ADDR_HOUSE_NUMBER.getValue()))) { SaveExtraValidationDialogFragment f = new SaveExtraValidationDialogFragment(); Bundle args = new Bundle(); diff --git a/OsmAnd/src/net/osmand/plus/poi/PoiFiltersHelper.java b/OsmAnd/src/net/osmand/plus/poi/PoiFiltersHelper.java index 93871dfca4..2e9e11c5c3 100644 --- a/OsmAnd/src/net/osmand/plus/poi/PoiFiltersHelper.java +++ b/OsmAnd/src/net/osmand/plus/poi/PoiFiltersHelper.java @@ -231,9 +231,8 @@ public class PoiFiltersHelper { public List getTopDefinedPoiFilters(boolean includeDeleted) { List top = this.cacheTopStandardFilters; if (top == null) { - top = new ArrayList<>(); // user defined - top.addAll(getUserDefinedPoiFilters(true)); + top = new ArrayList<>(getUserDefinedPoiFilters(true)); // default MapPoiTypes poiTypes = application.getPoiTypes(); for (AbstractPoiType t : poiTypes.getTopVisibleFilters()) { From 0f9573e22e959bc16c24ebb0bded2323c0f9fb2a Mon Sep 17 00:00:00 2001 From: TacoTheDank Date: Thu, 19 Nov 2020 15:22:27 -0500 Subject: [PATCH 09/12] Performance: Redundant call to 'String.format()' --- OsmAnd-java/src/main/java/net/osmand/TspHeldKarp.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/OsmAnd-java/src/main/java/net/osmand/TspHeldKarp.java b/OsmAnd-java/src/main/java/net/osmand/TspHeldKarp.java index 8c2a4baf32..e4862d3bfe 100644 --- a/OsmAnd-java/src/main/java/net/osmand/TspHeldKarp.java +++ b/OsmAnd-java/src/main/java/net/osmand/TspHeldKarp.java @@ -68,7 +68,7 @@ public class TspHeldKarp { } break; } - System.err.printf("."); + System.err.print("."); PriorityQueue children = new PriorityQueue(11, new NodeComparator()); children.add(exclude(currentNode, i, currentNode.parent[i])); for (int j = 0; j < n; j++) { From 8a7f50f3a6f1569d68bde3303930b0cc188a9e23 Mon Sep 17 00:00:00 2001 From: TacoTheDank Date: Thu, 19 Nov 2020 15:22:46 -0500 Subject: [PATCH 10/12] Performance: Set replaceable with EnumSet --- .../src/main/java/net/osmand/util/OpeningHoursParser.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/OsmAnd-java/src/main/java/net/osmand/util/OpeningHoursParser.java b/OsmAnd-java/src/main/java/net/osmand/util/OpeningHoursParser.java index 01fee5cd9e..f87a1d4d4e 100644 --- a/OsmAnd-java/src/main/java/net/osmand/util/OpeningHoursParser.java +++ b/OsmAnd-java/src/main/java/net/osmand/util/OpeningHoursParser.java @@ -6,6 +6,7 @@ import java.text.DateFormatSymbols; import java.util.ArrayList; import java.util.Arrays; import java.util.Calendar; +import java.util.EnumSet; import java.util.HashMap; import java.util.HashSet; import java.util.List; @@ -1812,7 +1813,7 @@ public class OpeningHoursParser { TokenType currentParse = TokenType.TOKEN_UNKNOWN; TokenType currentParseParent = TokenType.TOKEN_UNKNOWN; List listOfPairs = new ArrayList<>(); - Set presentTokens = new HashSet<>(); + Set presentTokens = EnumSet.noneOf(TokenType.class); Token[] currentPair = new Token[2]; listOfPairs.add(currentPair); Token prevToken = null; From 608d93a8fa8000003d3579d3810cb5b651a94f56 Mon Sep 17 00:00:00 2001 From: TacoTheDank Date: Thu, 19 Nov 2020 15:23:35 -0500 Subject: [PATCH 11/12] Performance: Replace '.equals("")' with '.isEmpty' --- .../main/java/net/osmand/binary/RouteDataObject.java | 4 ++-- .../osmand/render/RenderingRulesStoragePrinter.java | 2 +- .../net/osmand/render/RenderingRulesTransformer.java | 2 +- .../java/net/osmand/util/GeoPointParserUtil.java | 2 +- OsmAnd/src/net/osmand/plus/FavouritesDbHelper.java | 10 +++++----- OsmAnd/src/net/osmand/plus/OsmandApplication.java | 12 ++++++------ .../src/net/osmand/plus/activities/HelpActivity.java | 2 +- .../plus/activities/actions/StartGPSStatus.java | 2 +- .../net/osmand/plus/dialogs/ConfigureMapMenu.java | 4 ++-- .../osmand/plus/helpers/MapMarkerDialogHelper.java | 2 +- .../net/osmand/plus/importfiles/ImportHelper.java | 2 +- .../plus/mapillary/MapillaryFiltersFragment.java | 10 +++++----- .../osmand/plus/mapillary/MapillaryVectorLayer.java | 2 +- ...SelectWptCategoriesBottomSheetDialogFragment.java | 2 +- .../mapmarkers/adapters/MapMarkersActiveAdapter.java | 2 +- .../mapmarkers/adapters/MapMarkersGroupsAdapter.java | 4 ++-- .../adapters/MapMarkersHistoryAdapter.java | 2 +- .../mapmarkers/adapters/MapMarkersListAdapter.java | 2 +- .../mapmarkers/adapters/TracksGroupsAdapter.java | 2 +- .../osmedit/dialogs/SendPoiBottomSheetFragment.java | 2 +- .../plus/osmedit/dialogs/SendPoiDialogFragment.java | 4 ++-- .../osmand/plus/render/MapRenderRepositories.java | 2 +- OsmAnd/src/net/osmand/plus/render/TextRenderer.java | 2 +- .../net/osmand/plus/resources/ResourceManager.java | 2 +- .../AddPointBottomSheetDialog.java | 2 +- .../bottomsheets/BooleanPreferenceBottomSheet.java | 4 ++-- .../bottomsheets/SelectFolderBottomSheet.java | 2 +- .../plus/settings/fragments/DataStorageFragment.java | 2 +- .../fragments/ProfileAppearanceFragment.java | 2 +- .../src/net/osmand/plus/srtmplugin/SRTMPlugin.java | 4 ++-- .../plus/views/AddGpxPointBottomSheetHelper.java | 2 +- 31 files changed, 50 insertions(+), 50 deletions(-) diff --git a/OsmAnd-java/src/main/java/net/osmand/binary/RouteDataObject.java b/OsmAnd-java/src/main/java/net/osmand/binary/RouteDataObject.java index bfe638d394..38fe091e89 100644 --- a/OsmAnd-java/src/main/java/net/osmand/binary/RouteDataObject.java +++ b/OsmAnd-java/src/main/java/net/osmand/binary/RouteDataObject.java @@ -329,7 +329,7 @@ public class RouteDataObject { public String getDestinationName(String lang, boolean transliterate, boolean direction){ //Issue #3289: Treat destination:ref like a destination, not like a ref String destRef = ((getDestinationRef(direction) == null) || getDestinationRef(direction).equals(getRef(lang, transliterate, direction))) ? "" : getDestinationRef(direction); - String destRef1 = ("".equals(destRef)) ? "" : destRef + ", "; + String destRef1 = (destRef != null && destRef.isEmpty()) ? "" : destRef + ", "; if(names != null) { int[] kt = names.keys(); @@ -373,7 +373,7 @@ public class RouteDataObject { return destRef1 + ((transliterate) ? TransliterationHelper.transliterate(destinationDefault) : destinationDefault); } } - return "".equals(destRef) ? null : destRef; + return destRef != null && destRef.isEmpty() ? null : destRef; } public int getPoint31XTile(int i) { diff --git a/OsmAnd-java/src/main/java/net/osmand/render/RenderingRulesStoragePrinter.java b/OsmAnd-java/src/main/java/net/osmand/render/RenderingRulesStoragePrinter.java index 3e36ae4e71..3acdeade26 100644 --- a/OsmAnd-java/src/main/java/net/osmand/render/RenderingRulesStoragePrinter.java +++ b/OsmAnd-java/src/main/java/net/osmand/render/RenderingRulesStoragePrinter.java @@ -221,7 +221,7 @@ public class RenderingRulesStoragePrinter { mp+=", "; } } - if(mp.equals("")) { + if(mp.isEmpty()) { mp = "java.util.Collections.EMPTY_MAP"; } else { mp = "createMap(" +mp +")"; diff --git a/OsmAnd-java/src/main/java/net/osmand/render/RenderingRulesTransformer.java b/OsmAnd-java/src/main/java/net/osmand/render/RenderingRulesTransformer.java index b41a741909..cd18ad958f 100644 --- a/OsmAnd-java/src/main/java/net/osmand/render/RenderingRulesTransformer.java +++ b/OsmAnd-java/src/main/java/net/osmand/render/RenderingRulesTransformer.java @@ -80,7 +80,7 @@ public class RenderingRulesTransformer { for (int i = 0; i < nl.getLength();) { Element app = (Element) nl.item(i); String pt = app.getAttribute("pattern"); - if (!pt.equals("")) { + if (!pt.isEmpty()) { if (!patterns.containsKey(pt)) { throw new IllegalStateException("Pattern '" + pt + "' is not defined"); } diff --git a/OsmAnd-java/src/main/java/net/osmand/util/GeoPointParserUtil.java b/OsmAnd-java/src/main/java/net/osmand/util/GeoPointParserUtil.java index 31605c33a2..951ae870e2 100644 --- a/OsmAnd-java/src/main/java/net/osmand/util/GeoPointParserUtil.java +++ b/OsmAnd-java/src/main/java/net/osmand/util/GeoPointParserUtil.java @@ -62,7 +62,7 @@ public class GeoPointParserUtil { private static Map getQueryParameters(String query) { final LinkedHashMap map = new LinkedHashMap(); - if (query != null && !query.equals("")) { + if (query != null && !query.isEmpty()) { String[] params = query.split("[&/]"); for (String p : params) { String[] keyValue = p.split("="); diff --git a/OsmAnd/src/net/osmand/plus/FavouritesDbHelper.java b/OsmAnd/src/net/osmand/plus/FavouritesDbHelper.java index 2cd9a6ab4a..992a0e42c6 100644 --- a/OsmAnd/src/net/osmand/plus/FavouritesDbHelper.java +++ b/OsmAnd/src/net/osmand/plus/FavouritesDbHelper.java @@ -361,7 +361,7 @@ public class FavouritesDbHelper { } public boolean addFavourite(FavouritePoint p, boolean saveImmediately) { - if (p.getName().equals("") && flatGroups.containsKey(p.getCategory())) { + if (p.getName().isEmpty() && flatGroups.containsKey(p.getCategory())) { return true; } if (!p.isAddressSpecified()) { @@ -370,7 +370,7 @@ public class FavouritesDbHelper { context.getSettings().SHOW_FAVORITES.set(true); FavoriteGroup group = getOrCreateGroup(p, 0); - if (!p.getName().equals("")) { + if (!p.getName().isEmpty()) { p.setVisible(group.visible); if (FavouritePoint.SpecialPointType.PARKING.equals(p.getSpecialPointType())) { p.setColor(ContextCompat.getColor(context, R.color.parking_icon_background)); @@ -970,7 +970,7 @@ public class FavouritesDbHelper { p.setName(name); p.setCategory(cat); FavoriteGroup group = getOrCreateGroup(p, 0); - if (!name.equals("")) { + if (!name.isEmpty()) { p.setLatitude(query.getDouble(2)); p.setLongitude(query.getDouble(3)); group.points.add(p); @@ -1014,7 +1014,7 @@ public class FavouritesDbHelper { public boolean addFavouriteDB(FavouritePoint p) { - if (p.getName().equals("") && flatGroups.containsKey(p.getCategory())) { + if (p.getName().isEmpty() && flatGroups.containsKey(p.getCategory())) { return true; } SQLiteConnection db = openConnection(false); @@ -1024,7 +1024,7 @@ public class FavouritesDbHelper { "INSERT INTO " + FAVOURITE_TABLE_NAME + " (" + FAVOURITE_COL_NAME + ", " + FAVOURITE_COL_CATEGORY + ", " + FAVOURITE_COL_LAT + ", " + FAVOURITE_COL_LON + ")" + " VALUES (?, ?, ?, ?)", new Object[]{p.getName(), p.getCategory(), p.getLatitude(), p.getLongitude()}); //$NON-NLS-1$ //$NON-NLS-2$ FavoriteGroup group = getOrCreateGroup(p, 0); - if (!p.getName().equals("")) { + if (!p.getName().isEmpty()) { p.setVisible(group.visible); p.setColor(group.color); group.points.add(p); diff --git a/OsmAnd/src/net/osmand/plus/OsmandApplication.java b/OsmAnd/src/net/osmand/plus/OsmandApplication.java index 97cfeb662a..1a80d43b1f 100644 --- a/OsmAnd/src/net/osmand/plus/OsmandApplication.java +++ b/OsmAnd/src/net/osmand/plus/OsmandApplication.java @@ -412,8 +412,8 @@ public class OsmandApplication extends MultiDexApplication { if (defaultLocale == null) { defaultLocale = Locale.getDefault(); } - if (!"".equals(lang)) { - if (!"".equals(country)) { + if (lang != null && !lang.isEmpty()) { + if (country != null && !country.isEmpty()) { preferredLocale = new Locale(lang, country); } else { preferredLocale = new Locale(lang); @@ -421,9 +421,9 @@ public class OsmandApplication extends MultiDexApplication { } Locale selectedLocale = null; - if (!"".equals(lang) && !config.locale.equals(preferredLocale)) { + if (lang != null && !lang.isEmpty() && !config.locale.equals(preferredLocale)) { selectedLocale = preferredLocale; - } else if ("".equals(lang) && defaultLocale != null && Locale.getDefault() != defaultLocale) { + } else if (lang != null && lang.isEmpty() && defaultLocale != null && Locale.getDefault() != defaultLocale) { selectedLocale = defaultLocale; preferredLocale = null; } @@ -812,12 +812,12 @@ public class OsmandApplication extends MultiDexApplication { if (preferredLocale != null) { Configuration config = context.getResources().getConfiguration(); String lang = preferredLocale.getLanguage(); - if (!"".equals(lang) && !config.locale.getLanguage().equals(lang)) { + if (!lang.isEmpty() && !config.locale.getLanguage().equals(lang)) { preferredLocale = new Locale(lang); Locale.setDefault(preferredLocale); config.locale = preferredLocale; context.getResources().updateConfiguration(config, context.getResources().getDisplayMetrics()); - } else if("".equals(lang) && defaultLocale != null && Locale.getDefault() != defaultLocale) { + } else if(lang.isEmpty() && defaultLocale != null && Locale.getDefault() != defaultLocale) { Locale.setDefault(defaultLocale); config.locale = defaultLocale; getBaseContext().getResources().updateConfiguration(config, getBaseContext().getResources().getDisplayMetrics()); diff --git a/OsmAnd/src/net/osmand/plus/activities/HelpActivity.java b/OsmAnd/src/net/osmand/plus/activities/HelpActivity.java index b7b3044f97..7eb21d4ee8 100644 --- a/OsmAnd/src/net/osmand/plus/activities/HelpActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/HelpActivity.java @@ -176,7 +176,7 @@ public class HelpActivity extends OsmandActionBarActivity implements AdapterView "feature_articles/osmand-3-8-released.html")); String releasedate = ""; - if (!this.getString(R.string.app_edition).equals("")) { + if (!this.getString(R.string.app_edition).isEmpty()) { releasedate = ", " + this.getString(R.string.shared_string_release).toLowerCase() + ": " + this.getString(R.string.app_edition); } String version = Version.getFullVersion(getMyApplication()) + releasedate; diff --git a/OsmAnd/src/net/osmand/plus/activities/actions/StartGPSStatus.java b/OsmAnd/src/net/osmand/plus/activities/actions/StartGPSStatus.java index 0c64258825..79abd4190a 100644 --- a/OsmAnd/src/net/osmand/plus/activities/actions/StartGPSStatus.java +++ b/OsmAnd/src/net/osmand/plus/activities/actions/StartGPSStatus.java @@ -165,7 +165,7 @@ public class StartGPSStatus extends OsmAndAction { // if (g.activity.length() == 0) { PackageManager pm = mapActivity.getPackageManager(); try { - String appName = !g.paidAppName.equals("") && + String appName = !g.paidAppName.isEmpty() && g.installed(mapActivity, g.paidAppName) ? g.paidAppName : g.appName; intent = pm.getLaunchIntentForPackage(appName); } catch (RuntimeException e) { diff --git a/OsmAnd/src/net/osmand/plus/dialogs/ConfigureMapMenu.java b/OsmAnd/src/net/osmand/plus/dialogs/ConfigureMapMenu.java index 6e3b7fba8a..ca7382dd6e 100644 --- a/OsmAnd/src/net/osmand/plus/dialogs/ConfigureMapMenu.java +++ b/OsmAnd/src/net/osmand/plus/dialogs/ConfigureMapMenu.java @@ -481,7 +481,7 @@ public class ConfigureMapMenu { .createItem()); String localeDescr = activity.getMyApplication().getSettings().MAP_PREFERRED_LOCALE.get(); - localeDescr = localeDescr == null || localeDescr.equals("") ? activity.getString(R.string.local_map_names) + localeDescr = localeDescr == null || localeDescr.isEmpty() ? activity.getString(R.string.local_map_names) : localeDescr; adapter.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.map_locale, activity) .setId(MAP_LANGUAGE_ID) @@ -570,7 +570,7 @@ public class ConfigureMapMenu { txtIds[index]); refreshMapComplete(activity); String localeDescr = txtIds[index]; - localeDescr = localeDescr == null || localeDescr.equals("") ? activity + localeDescr = localeDescr == null || localeDescr.isEmpty() ? activity .getString(R.string.local_map_names) : localeDescr; adapter.getItem(pos).setDescription(localeDescr); ad.notifyDataSetInvalidated(); diff --git a/OsmAnd/src/net/osmand/plus/helpers/MapMarkerDialogHelper.java b/OsmAnd/src/net/osmand/plus/helpers/MapMarkerDialogHelper.java index a90247e644..ab40f14407 100644 --- a/OsmAnd/src/net/osmand/plus/helpers/MapMarkerDialogHelper.java +++ b/OsmAnd/src/net/osmand/plus/helpers/MapMarkerDialogHelper.java @@ -101,7 +101,7 @@ public class MapMarkerDialogHelper { String desc = OsmAndFormatter.getFormattedDate(app, marker.creationDate); String markerGroupName = marker.groupName; if (markerGroupName != null) { - if (markerGroupName.equals("")) { + if (markerGroupName.isEmpty()) { markerGroupName = app.getString(R.string.shared_string_favorites); } desc += " • " + markerGroupName; diff --git a/OsmAnd/src/net/osmand/plus/importfiles/ImportHelper.java b/OsmAnd/src/net/osmand/plus/importfiles/ImportHelper.java index 16fb083f13..8190570c2a 100644 --- a/OsmAnd/src/net/osmand/plus/importfiles/ImportHelper.java +++ b/OsmAnd/src/net/osmand/plus/importfiles/ImportHelper.java @@ -513,7 +513,7 @@ public class ImportHelper { private File getFileToSave(final String fileName, final File importDir, final WptPt pt) { final StringBuilder builder = new StringBuilder(fileName); - if ("".equals(fileName)) { + if (fileName != null && fileName.isEmpty()) { builder.append("import_").append(new SimpleDateFormat("HH-mm_EEE", Locale.US).format(new Date(pt.time))).append(GPX_FILE_EXT); //$NON-NLS-1$ } if (fileName.endsWith(KML_SUFFIX)) { diff --git a/OsmAnd/src/net/osmand/plus/mapillary/MapillaryFiltersFragment.java b/OsmAnd/src/net/osmand/plus/mapillary/MapillaryFiltersFragment.java index 60abf651ba..6b03cd3a6a 100644 --- a/OsmAnd/src/net/osmand/plus/mapillary/MapillaryFiltersFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapillary/MapillaryFiltersFragment.java @@ -123,7 +123,7 @@ public class MapillaryFiltersFragment extends BaseOsmAndFragment { final DelayAutoCompleteTextView textView = (DelayAutoCompleteTextView) view.findViewById(R.id.auto_complete_text_view); textView.setAdapter(new MapillaryAutoCompleteAdapter(getContext(), R.layout.auto_complete_suggestion, getMyApplication())); String selectedUsername = settings.MAPILLARY_FILTER_USERNAME.get(); - if (!selectedUsername.equals("") && settings.USE_MAPILLARY_FILTER.get()) { + if (!selectedUsername.isEmpty() && settings.USE_MAPILLARY_FILTER.get()) { textView.setText(selectedUsername); textView.setSelection(selectedUsername.length()); } @@ -261,16 +261,16 @@ public class MapillaryFiltersFragment extends BaseOsmAndFragment { String dateFrom = dateFromEt.getText().toString(); String dateTo = dateToEt.getText().toString(); - if (!settings.MAPILLARY_FILTER_USERNAME.get().equals("") || !dateFrom.equals("") || !dateTo.equals("") || settings.MAPILLARY_FILTER_PANO.get()) { + if (!settings.MAPILLARY_FILTER_USERNAME.get().isEmpty() || !dateFrom.isEmpty() || !dateTo.isEmpty() || settings.MAPILLARY_FILTER_PANO.get()) { settings.USE_MAPILLARY_FILTER.set(true); } - if (dateFrom.equals("")) { + if (dateFrom.isEmpty()) { settings.MAPILLARY_FILTER_FROM_DATE.set(0L); } - if (dateTo.equals("")) { + if (dateTo.isEmpty()) { settings.MAPILLARY_FILTER_TO_DATE.set(0L); } - if (!username.equals("") && settings.MAPILLARY_FILTER_USERNAME.get().equals("")) { + if (!username.isEmpty() && settings.MAPILLARY_FILTER_USERNAME.get().isEmpty()) { view.findViewById(R.id.warning_linear_layout).setVisibility(View.VISIBLE); } else { mapActivity.getDashboard().hideDashboard(); diff --git a/OsmAnd/src/net/osmand/plus/mapillary/MapillaryVectorLayer.java b/OsmAnd/src/net/osmand/plus/mapillary/MapillaryVectorLayer.java index 512281a079..51c12f07aa 100644 --- a/OsmAnd/src/net/osmand/plus/mapillary/MapillaryVectorLayer.java +++ b/OsmAnd/src/net/osmand/plus/mapillary/MapillaryVectorLayer.java @@ -205,7 +205,7 @@ class MapillaryVectorLayer extends MapTileLayer implements MapillaryLayer, ICont long to = settings.MAPILLARY_FILTER_TO_DATE.get(); boolean pano = settings.MAPILLARY_FILTER_PANO.get(); - if (!userKey.equals("")) { + if (!userKey.isEmpty()) { String key = (String) userData.get("userkey"); if (!userKey.equals(key)) { return true; diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/SelectWptCategoriesBottomSheetDialogFragment.java b/OsmAnd/src/net/osmand/plus/mapmarkers/SelectWptCategoriesBottomSheetDialogFragment.java index 0c887488b7..08db4d40fc 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/SelectWptCategoriesBottomSheetDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/SelectWptCategoriesBottomSheetDialogFragment.java @@ -99,7 +99,7 @@ public class SelectWptCategoriesBottomSheetDialogFragment extends MenuBottomShee .setCompoundButtonColorId(activeColorResId) .setDescription(String.valueOf(entry.getValue().size())) .setIcon(getContentIcon(R.drawable.ic_action_folder)) - .setTitle(category.equals("") ? getString(R.string.shared_string_waypoints) : category) + .setTitle(category.isEmpty() ? getString(R.string.shared_string_waypoints) : category) .setLayoutId(R.layout.bottom_sheet_item_with_descr_and_checkbox_56dp) .setTag(category) .setOnClickListener(new View.OnClickListener() { diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersActiveAdapter.java b/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersActiveAdapter.java index c1e85387b3..2fa206d08f 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersActiveAdapter.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersActiveAdapter.java @@ -131,7 +131,7 @@ public class MapMarkersActiveAdapter extends RecyclerView.Adapter it = categories.iterator(); while (it.hasNext()) { String category = it.next(); - if (category.equals("")) { + if (category.isEmpty()) { category = app.getResources().getString(R.string.shared_string_waypoints); } sb.append(category); diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersHistoryAdapter.java b/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersHistoryAdapter.java index 87d8e54303..ba407b23f9 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersHistoryAdapter.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersHistoryAdapter.java @@ -145,7 +145,7 @@ public class MapMarkersHistoryAdapter extends RecyclerView.Adapter it = categories.iterator(); while (it.hasNext()) { String category = it.next(); - if (!category.equals("")) { + if (!category.isEmpty()) { sb.append(category); if (it.hasNext()) { sb.append(", "); diff --git a/OsmAnd/src/net/osmand/plus/osmedit/dialogs/SendPoiBottomSheetFragment.java b/OsmAnd/src/net/osmand/plus/osmedit/dialogs/SendPoiBottomSheetFragment.java index 748d9504f0..159f64fad4 100644 --- a/OsmAnd/src/net/osmand/plus/osmedit/dialogs/SendPoiBottomSheetFragment.java +++ b/OsmAnd/src/net/osmand/plus/osmedit/dialogs/SendPoiBottomSheetFragment.java @@ -234,7 +234,7 @@ public class SendPoiBottomSheetFragment extends MenuBottomSheetDialogFragment { if (modifiedItemsOutOfLimit != 0) { comment = comment.concat("; ").concat(modifiedItemsOutOfLimit + " ") .concat(getString(R.string.items_modified)).concat("."); - } else if (!comment.equals("")) { + } else if (!comment.isEmpty()) { comment = comment.concat("."); } return comment; diff --git a/OsmAnd/src/net/osmand/plus/osmedit/dialogs/SendPoiDialogFragment.java b/OsmAnd/src/net/osmand/plus/osmedit/dialogs/SendPoiDialogFragment.java index d402cdfe49..adfb8a2b60 100644 --- a/OsmAnd/src/net/osmand/plus/osmedit/dialogs/SendPoiDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/osmedit/dialogs/SendPoiDialogFragment.java @@ -84,7 +84,7 @@ public class SendPoiDialogFragment extends DialogFragment { messageLabel.setVisibility(hasPOI ? View.VISIBLE : View.GONE); messageEditText.setVisibility(hasPOI ? View.VISIBLE : View.GONE); closeChangeSetCheckBox.setVisibility(hasPOI ? View.VISIBLE : View.GONE); - closeChangeSetCheckBox.setChecked(hasPOI && !defaultChangeSet.equals("")); + closeChangeSetCheckBox.setChecked(hasPOI && !defaultChangeSet.isEmpty()); view.findViewById(R.id.osm_note_header).setVisibility(hasPOI ? View.GONE : View.VISIBLE); uploadAnonymously.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override @@ -233,7 +233,7 @@ public class SendPoiDialogFragment extends DialogFragment { } if (modifiedItemsOutOfLimit != 0) { comment = comment.concat("; ").concat(modifiedItemsOutOfLimit + " ").concat(getString(R.string.items_modified)).concat("."); - } else if (!comment.equals("")){ + } else if (!comment.isEmpty()){ comment = comment.concat("."); } return comment; diff --git a/OsmAnd/src/net/osmand/plus/render/MapRenderRepositories.java b/OsmAnd/src/net/osmand/plus/render/MapRenderRepositories.java index 26985faa0a..0b07a41c4f 100644 --- a/OsmAnd/src/net/osmand/plus/render/MapRenderRepositories.java +++ b/OsmAnd/src/net/osmand/plus/render/MapRenderRepositories.java @@ -728,7 +728,7 @@ public class MapRenderRepositories { currentRenderingContext.height = requestedBox.getPixHeight(); currentRenderingContext.nightMode = nightMode; if(requestedBox.getZoom() <= zoomToOverviewLocalNames && - "".equals(prefs.MAP_PREFERRED_LOCALE.get())) { + prefs.MAP_PREFERRED_LOCALE.get() != null && prefs.MAP_PREFERRED_LOCALE.get().isEmpty()) { currentRenderingContext.preferredLocale = app.getLanguage(); currentRenderingContext.transliterate = !languagesNotTransliterateOnBasemap.contains(app.getLanguage()); diff --git a/OsmAnd/src/net/osmand/plus/render/TextRenderer.java b/OsmAnd/src/net/osmand/plus/render/TextRenderer.java index 9e338d08ec..f7bb2cd349 100644 --- a/OsmAnd/src/net/osmand/plus/render/TextRenderer.java +++ b/OsmAnd/src/net/osmand/plus/render/TextRenderer.java @@ -438,7 +438,7 @@ public class TextRenderer { String nameTag = isName ? "" : obj.getMapIndex().decodeType(tag).tag; boolean skip = false; // not completely correct we should check "name"+rc.preferredLocale - if (isName && !rc.preferredLocale.equals("") && + if (isName && !rc.preferredLocale.isEmpty() && map.containsKey(obj.getMapIndex().nameEnEncodingType)) { skip = true; } diff --git a/OsmAnd/src/net/osmand/plus/resources/ResourceManager.java b/OsmAnd/src/net/osmand/plus/resources/ResourceManager.java index b70ded655b..8e7857b33a 100644 --- a/OsmAnd/src/net/osmand/plus/resources/ResourceManager.java +++ b/OsmAnd/src/net/osmand/plus/resources/ResourceManager.java @@ -486,7 +486,7 @@ public class ResourceManager { try { progress.startTask(context.getString(R.string.installing_new_resources), -1); AssetManager assetManager = context.getAssets(); - boolean isFirstInstall = context.getSettings().PREVIOUS_INSTALLED_VERSION.get().equals(""); + boolean isFirstInstall = context.getSettings().PREVIOUS_INSTALLED_VERSION.get().isEmpty(); unpackBundledAssets(assetManager, applicationDataDir, progress, isFirstInstall || forceUpdate); context.getSettings().PREVIOUS_INSTALLED_VERSION.set(fv); copyRegionsBoundaries(); diff --git a/OsmAnd/src/net/osmand/plus/routepreparationmenu/AddPointBottomSheetDialog.java b/OsmAnd/src/net/osmand/plus/routepreparationmenu/AddPointBottomSheetDialog.java index 7257e2ec00..7c70ba8dfb 100644 --- a/OsmAnd/src/net/osmand/plus/routepreparationmenu/AddPointBottomSheetDialog.java +++ b/OsmAnd/src/net/osmand/plus/routepreparationmenu/AddPointBottomSheetDialog.java @@ -651,7 +651,7 @@ public class AddPointBottomSheetDialog extends MenuBottomSheetDialogFragment { ((FavouritePoint) item).getSpecialPointType().getIconId(app), iconColor)); favoriteViewHolder.description.setText(point.getDescription()); } else { - if (point.getCategory().equals("")) { + if (point.getCategory().isEmpty()) { favoriteViewHolder.description.setText(R.string.shared_string_favorites); } else { favoriteViewHolder.description.setText(point.getCategory()); diff --git a/OsmAnd/src/net/osmand/plus/settings/bottomsheets/BooleanPreferenceBottomSheet.java b/OsmAnd/src/net/osmand/plus/settings/bottomsheets/BooleanPreferenceBottomSheet.java index f34d6938fb..3730833d4d 100644 --- a/OsmAnd/src/net/osmand/plus/settings/bottomsheets/BooleanPreferenceBottomSheet.java +++ b/OsmAnd/src/net/osmand/plus/settings/bottomsheets/BooleanPreferenceBottomSheet.java @@ -59,9 +59,9 @@ public class BooleanPreferenceBottomSheet extends BasePreferenceBottomSheet { final BooleanPreference pref = (BooleanPreference) preference; CharSequence summaryOn = switchPreference.getSummaryOn(); CharSequence summaryOff = switchPreference.getSummaryOff(); - final String on = summaryOn == null || summaryOn.toString().equals("") + final String on = summaryOn == null || summaryOn.toString().isEmpty() ? getString(R.string.shared_string_enabled) : summaryOn.toString(); - final String off = summaryOff == null || summaryOff.toString().equals("") + final String off = summaryOff == null || summaryOff.toString().isEmpty() ? getString(R.string.shared_string_disabled) : summaryOff.toString(); final int activeColor = AndroidUtils.resolveAttribute(themedCtx, R.attr.active_color_basic); final int disabledColor = AndroidUtils.resolveAttribute(themedCtx, android.R.attr.textColorSecondary); diff --git a/OsmAnd/src/net/osmand/plus/settings/bottomsheets/SelectFolderBottomSheet.java b/OsmAnd/src/net/osmand/plus/settings/bottomsheets/SelectFolderBottomSheet.java index 6a3cc193b2..10c09021b9 100644 --- a/OsmAnd/src/net/osmand/plus/settings/bottomsheets/SelectFolderBottomSheet.java +++ b/OsmAnd/src/net/osmand/plus/settings/bottomsheets/SelectFolderBottomSheet.java @@ -158,7 +158,7 @@ public class SelectFolderBottomSheet extends BasePreferenceBottomSheet { Fragment fragment = getTargetFragment(); if (fragment instanceof BaseSettingsFragment) { String newPath = editText.getText().toString().trim(); - if (!newPath.equals("")) { + if (!newPath.isEmpty()) { boolean pathChanged = !newPath.equals(currentPath); Bundle bundle = new Bundle(); bundle.putBoolean(TAG, true); diff --git a/OsmAnd/src/net/osmand/plus/settings/fragments/DataStorageFragment.java b/OsmAnd/src/net/osmand/plus/settings/fragments/DataStorageFragment.java index 842b53e2fa..de95eaeade 100644 --- a/OsmAnd/src/net/osmand/plus/settings/fragments/DataStorageFragment.java +++ b/OsmAnd/src/net/osmand/plus/settings/fragments/DataStorageFragment.java @@ -241,7 +241,7 @@ public class DataStorageFragment extends BaseSettingsFragment implements DataSto divider.setVisibility(View.VISIBLE); secondPart.setVisibility(View.VISIBLE); String space = getSpaceDescription(item.getDirectory()); - if (!space.equals("")) { + if (!space.isEmpty()) { space = space.replaceAll(" • ", " • "); tvSummary.setText(space); tvSummary.setVisibility(View.VISIBLE); diff --git a/OsmAnd/src/net/osmand/plus/settings/fragments/ProfileAppearanceFragment.java b/OsmAnd/src/net/osmand/plus/settings/fragments/ProfileAppearanceFragment.java index bc3092d963..8e4dfc14c0 100644 --- a/OsmAnd/src/net/osmand/plus/settings/fragments/ProfileAppearanceFragment.java +++ b/OsmAnd/src/net/osmand/plus/settings/fragments/ProfileAppearanceFragment.java @@ -897,7 +897,7 @@ public class ProfileAppearanceFragment extends BaseSettingsFragment { } private boolean nameIsEmpty() { - return changedProfile.name.trim().equals(""); + return changedProfile.name.trim().isEmpty(); } private void disableSaveButtonWithErrorMessage(String errorMessage) { diff --git a/OsmAnd/src/net/osmand/plus/srtmplugin/SRTMPlugin.java b/OsmAnd/src/net/osmand/plus/srtmplugin/SRTMPlugin.java index 9e66f72f74..a8dc02135b 100644 --- a/OsmAnd/src/net/osmand/plus/srtmplugin/SRTMPlugin.java +++ b/OsmAnd/src/net/osmand/plus/srtmplugin/SRTMPlugin.java @@ -137,9 +137,9 @@ public class SRTMPlugin extends OsmandPlugin { public boolean init(@NonNull final OsmandApplication app, Activity activity) { OsmandSettings settings = app.getSettings(); CommonPreference pref = settings.getCustomRenderProperty("contourLines"); - if (pref.get().equals("")) { + if (pref.get().isEmpty()) { for (ApplicationMode m : ApplicationMode.allPossibleValues()) { - if (pref.getModeValue(m).equals("")) { + if (pref.getModeValue(m).isEmpty()) { pref.setModeValue(m, "13"); } } diff --git a/OsmAnd/src/net/osmand/plus/views/AddGpxPointBottomSheetHelper.java b/OsmAnd/src/net/osmand/plus/views/AddGpxPointBottomSheetHelper.java index b43cab4492..9408ec5537 100644 --- a/OsmAnd/src/net/osmand/plus/views/AddGpxPointBottomSheetHelper.java +++ b/OsmAnd/src/net/osmand/plus/views/AddGpxPointBottomSheetHelper.java @@ -86,7 +86,7 @@ public class AddGpxPointBottomSheetHelper implements OnDismissListener { } public void setTitle(String title) { - if (title.equals("")) { + if (title.isEmpty()) { if (pointDescription.isWpt()) { title = mapActivity.getString(R.string.waypoint_one); } else if (pointDescription.isRte()) { From 9056c7e97b2b9ab15868e2c5238282894117bf5b Mon Sep 17 00:00:00 2001 From: Vitaliy Date: Mon, 23 Nov 2020 03:27:09 +0200 Subject: [PATCH 12/12] Minor fixes --- .../java/net/osmand/binary/RouteDataObject.java | 4 ++-- OsmAnd/src/net/osmand/plus/OsmandApplication.java | 14 +++++++------- .../osmand/plus/activities/SavingTrackHelper.java | 8 ++++---- .../net/osmand/plus/importfiles/ImportHelper.java | 5 ++--- .../osmand/plus/osmedit/EditPoiDialogFragment.java | 1 - 5 files changed, 15 insertions(+), 17 deletions(-) diff --git a/OsmAnd-java/src/main/java/net/osmand/binary/RouteDataObject.java b/OsmAnd-java/src/main/java/net/osmand/binary/RouteDataObject.java index 38fe091e89..bc81ca667e 100644 --- a/OsmAnd-java/src/main/java/net/osmand/binary/RouteDataObject.java +++ b/OsmAnd-java/src/main/java/net/osmand/binary/RouteDataObject.java @@ -329,7 +329,7 @@ public class RouteDataObject { public String getDestinationName(String lang, boolean transliterate, boolean direction){ //Issue #3289: Treat destination:ref like a destination, not like a ref String destRef = ((getDestinationRef(direction) == null) || getDestinationRef(direction).equals(getRef(lang, transliterate, direction))) ? "" : getDestinationRef(direction); - String destRef1 = (destRef != null && destRef.isEmpty()) ? "" : destRef + ", "; + String destRef1 = Algorithms.isEmpty(destRef) ? "" : destRef + ", "; if(names != null) { int[] kt = names.keys(); @@ -373,7 +373,7 @@ public class RouteDataObject { return destRef1 + ((transliterate) ? TransliterationHelper.transliterate(destinationDefault) : destinationDefault); } } - return destRef != null && destRef.isEmpty() ? null : destRef; + return Algorithms.isEmpty(destRef) ? null : destRef; } public int getPoint31XTile(int i) { diff --git a/OsmAnd/src/net/osmand/plus/OsmandApplication.java b/OsmAnd/src/net/osmand/plus/OsmandApplication.java index 1a80d43b1f..00bdd97e2d 100644 --- a/OsmAnd/src/net/osmand/plus/OsmandApplication.java +++ b/OsmAnd/src/net/osmand/plus/OsmandApplication.java @@ -412,8 +412,8 @@ public class OsmandApplication extends MultiDexApplication { if (defaultLocale == null) { defaultLocale = Locale.getDefault(); } - if (lang != null && !lang.isEmpty()) { - if (country != null && !country.isEmpty()) { + if (!Algorithms.isEmpty(lang)) { + if (!Algorithms.isEmpty(country)) { preferredLocale = new Locale(lang, country); } else { preferredLocale = new Locale(lang); @@ -421,9 +421,9 @@ public class OsmandApplication extends MultiDexApplication { } Locale selectedLocale = null; - if (lang != null && !lang.isEmpty() && !config.locale.equals(preferredLocale)) { + if (!Algorithms.isEmpty(lang) && !config.locale.equals(preferredLocale)) { selectedLocale = preferredLocale; - } else if (lang != null && lang.isEmpty() && defaultLocale != null && Locale.getDefault() != defaultLocale) { + } else if (Algorithms.isEmpty(lang) && defaultLocale != null && Locale.getDefault() != defaultLocale) { selectedLocale = defaultLocale; preferredLocale = null; } @@ -807,17 +807,17 @@ public class OsmandApplication extends MultiDexApplication { } return s; } - + public void setLanguage(Context context) { if (preferredLocale != null) { Configuration config = context.getResources().getConfiguration(); String lang = preferredLocale.getLanguage(); - if (!lang.isEmpty() && !config.locale.getLanguage().equals(lang)) { + if (!Algorithms.isEmpty(lang) && !config.locale.getLanguage().equals(lang)) { preferredLocale = new Locale(lang); Locale.setDefault(preferredLocale); config.locale = preferredLocale; context.getResources().updateConfiguration(config, context.getResources().getDisplayMetrics()); - } else if(lang.isEmpty() && defaultLocale != null && Locale.getDefault() != defaultLocale) { + } else if (Algorithms.isEmpty(lang) && defaultLocale != null && Locale.getDefault() != defaultLocale) { Locale.setDefault(defaultLocale); config.locale = defaultLocale; getBaseContext().getResources().updateConfiguration(config, getBaseContext().getResources().getDisplayMetrics()); diff --git a/OsmAnd/src/net/osmand/plus/activities/SavingTrackHelper.java b/OsmAnd/src/net/osmand/plus/activities/SavingTrackHelper.java index 8b57c68e49..ff7039702e 100644 --- a/OsmAnd/src/net/osmand/plus/activities/SavingTrackHelper.java +++ b/OsmAnd/src/net/osmand/plus/activities/SavingTrackHelper.java @@ -210,10 +210,11 @@ public class SavingTrackHelper extends SQLiteOpenHelper { // save file for (final Map.Entry entry : data.entrySet()) { final String f = entry.getKey(); + GPXFile gpx = entry.getValue(); log.debug("Filename: " + f); File fout = new File(dir, f + IndexConstants.GPX_FILE_EXT); - if (!entry.getValue().isEmpty()) { - WptPt pt = entry.getValue().findPointToShow(); + if (!gpx.isEmpty()) { + WptPt pt = gpx.findPointToShow(); String fileName = f + "_" + new SimpleDateFormat("HH-mm_EEE", Locale.US).format(new Date(pt.time)); //$NON-NLS-1$ Integer trackStorageDirectory = ctx.getSettings().TRACK_STORAGE_DIRECTORY.get(); if (!OsmandSettings.REC_DIRECTORY.equals(trackStorageDirectory)) { @@ -236,13 +237,12 @@ public class SavingTrackHelper extends SQLiteOpenHelper { } } - Exception warn = GPXUtilities.writeGpxFile(fout, entry.getValue()); + Exception warn = GPXUtilities.writeGpxFile(fout, gpx); if (warn != null) { warnings.add(warn.getMessage()); return new SaveGpxResult(warnings, new ArrayList()); } - GPXFile gpx = entry.getValue(); GPXTrackAnalysis analysis = gpx.getAnalysis(fout.lastModified()); GpxDataItem item = new GpxDataItem(fout, analysis); ctx.getGpxDbHelper().add(item); diff --git a/OsmAnd/src/net/osmand/plus/importfiles/ImportHelper.java b/OsmAnd/src/net/osmand/plus/importfiles/ImportHelper.java index 8190570c2a..09d2064284 100644 --- a/OsmAnd/src/net/osmand/plus/importfiles/ImportHelper.java +++ b/OsmAnd/src/net/osmand/plus/importfiles/ImportHelper.java @@ -513,10 +513,9 @@ public class ImportHelper { private File getFileToSave(final String fileName, final File importDir, final WptPt pt) { final StringBuilder builder = new StringBuilder(fileName); - if (fileName != null && fileName.isEmpty()) { + if (Algorithms.isEmpty(fileName)) { builder.append("import_").append(new SimpleDateFormat("HH-mm_EEE", Locale.US).format(new Date(pt.time))).append(GPX_FILE_EXT); //$NON-NLS-1$ - } - if (fileName.endsWith(KML_SUFFIX)) { + } else if (fileName.endsWith(KML_SUFFIX)) { builder.replace(builder.length() - KML_SUFFIX.length(), builder.length(), GPX_FILE_EXT); } else if (fileName.endsWith(KMZ_SUFFIX)) { builder.replace(builder.length() - KMZ_SUFFIX.length(), builder.length(), GPX_FILE_EXT); diff --git a/OsmAnd/src/net/osmand/plus/osmedit/EditPoiDialogFragment.java b/OsmAnd/src/net/osmand/plus/osmedit/EditPoiDialogFragment.java index fbf1ae9b96..55b24b7ed4 100644 --- a/OsmAnd/src/net/osmand/plus/osmedit/EditPoiDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/osmedit/EditPoiDialogFragment.java @@ -427,7 +427,6 @@ public class EditPoiDialogFragment extends BaseOsmAndDialogFragment { f.setArguments(args); f.show(getChildFragmentManager(), "exceedDialog"); } else if (TextUtils.isEmpty(poiTypeEditText.getText())) { - new HashSet<>(editPoiData.getTagValues().keySet()); if (Algorithms.isEmpty(editPoiData.getTag(OSMSettings.OSMTagKey.ADDR_HOUSE_NUMBER.getValue()))) { SaveExtraValidationDialogFragment f = new SaveExtraValidationDialogFragment(); Bundle args = new Bundle();