Performance: Replace '.equals("")' with '.isEmpty'

This commit is contained in:
TacoTheDank 2020-11-19 15:23:35 -05:00
parent 8a7f50f3a6
commit 608d93a8fa
31 changed files with 50 additions and 50 deletions

View file

@ -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) {

View file

@ -221,7 +221,7 @@ public class RenderingRulesStoragePrinter {
mp+=", ";
}
}
if(mp.equals("")) {
if(mp.isEmpty()) {
mp = "java.util.Collections.EMPTY_MAP";
} else {
mp = "createMap(" +mp +")";

View file

@ -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");
}

View file

@ -62,7 +62,7 @@ public class GeoPointParserUtil {
private static Map<String, String> getQueryParameters(String query) {
final LinkedHashMap<String, String> map = new LinkedHashMap<String, String>();
if (query != null && !query.equals("")) {
if (query != null && !query.isEmpty()) {
String[] params = query.split("[&/]");
for (String p : params) {
String[] keyValue = p.split("=");

View file

@ -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);

View file

@ -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());

View file

@ -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;

View file

@ -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) {

View file

@ -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();

View file

@ -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;

View file

@ -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)) {

View file

@ -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();

View file

@ -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;

View file

@ -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() {

View file

@ -131,7 +131,7 @@ public class MapMarkersActiveAdapter extends RecyclerView.Adapter<MapMarkerItemV
String descr;
if ((descr = marker.groupName) != null) {
if (descr.equals("")) {
if (descr.isEmpty()) {
descr = mapActivity.getString(R.string.shared_string_favorites);
}
} else {

View file

@ -403,7 +403,7 @@ public class MapMarkersGroupsAdapter extends RecyclerView.Adapter<RecyclerView.V
final GroupHeader groupHeader = (GroupHeader) header;
final MapMarkersGroup group = groupHeader.getGroup();
String groupName = group.getName();
if (groupName.equals("")) {
if (groupName.isEmpty()) {
groupName = app.getString(R.string.shared_string_favorites);
} else if (group.getType() == MapMarkersGroup.GPX_TYPE) {
groupName = groupName.replace(IndexConstants.GPX_FILE_EXT, "").replace("/", " ").replace("_", " ");
@ -579,7 +579,7 @@ public class MapMarkersGroupsAdapter extends RecyclerView.Adapter<RecyclerView.V
Iterator<String> 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);

View file

@ -145,7 +145,7 @@ public class MapMarkersHistoryAdapter extends RecyclerView.Adapter<RecyclerView.
String desc = app.getString(R.string.passed, OsmAndFormatter.getFormattedDate(app, marker.visitedDate));
String markerGroupName = marker.groupName;
if (markerGroupName != null) {
if (markerGroupName.equals("")) {
if (markerGroupName.isEmpty()) {
markerGroupName = app.getString(R.string.shared_string_favorites);
}
desc += "" + markerGroupName;

View file

@ -197,7 +197,7 @@ public class MapMarkersListAdapter extends RecyclerView.Adapter<MapMarkerItemVie
String descr;
if ((descr = marker.groupName) != null) {
if (descr.equals("")) {
if (descr.isEmpty()) {
descr = mapActivity.getString(R.string.shared_string_favorites);
}
} else {

View file

@ -57,7 +57,7 @@ public class TracksGroupsAdapter extends GroupsAdapter {
Iterator<String> it = categories.iterator();
while (it.hasNext()) {
String category = it.next();
if (!category.equals("")) {
if (!category.isEmpty()) {
sb.append(category);
if (it.hasNext()) {
sb.append(", ");

View file

@ -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;

View file

@ -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;

View file

@ -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());

View file

@ -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;
}

View file

@ -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();

View file

@ -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());

View file

@ -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);

View file

@ -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);

View file

@ -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);

View file

@ -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) {

View file

@ -137,9 +137,9 @@ public class SRTMPlugin extends OsmandPlugin {
public boolean init(@NonNull final OsmandApplication app, Activity activity) {
OsmandSettings settings = app.getSettings();
CommonPreference<String> 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");
}
}

View file

@ -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()) {