0
0
mirror of https://github.com/ankidroid/Anki-Android.git synced 2024-09-20 20:03:05 +02:00

nf: Use isEmpty in place of checking size to be zero when possible

This commit is contained in:
Nicola Dardanis 2021-07-05 01:06:10 +02:00 committed by Mike Hardy
parent 51ac9055db
commit e546c9ac7b
27 changed files with 60 additions and 60 deletions

View File

@ -1303,7 +1303,7 @@ public class CardBrowser extends NavigationDrawerActivity implements
return super.onOptionsItemSelected(item);
} else if (itemId == R.id.action_view_card_info) {
List<Long> selectedCardIds = getSelectedCardIds();
if (selectedCardIds.size() > 0) {
if (!selectedCardIds.isEmpty()) {
Intent intent = new Intent(this, CardInfo.class);
intent.putExtra("cardId", selectedCardIds.get(0));
startActivityWithAnimation(intent, FADE);
@ -2114,7 +2114,7 @@ public class CardBrowser extends NavigationDrawerActivity implements
List<Long> cardsIdsToHide = value.second;
if (cardsIdsToHide != null) {
try {
if (cardsIdsToHide.size() > 0) {
if (!cardsIdsToHide.isEmpty()) {
Timber.i("Removing %d invalid cards from view", cardsIdsToHide.size());
browser.removeNotesView(cardsIdsToHide, true);
}

View File

@ -260,7 +260,7 @@ public class DeckPicker extends NavigationDrawerActivity implements
private final OnClickListener mDeckExpanderClickListener = view -> {
Long did = (Long) view.getTag();
if (getCol().getDecks().children(did).size() > 0) {
if (!getCol().getDecks().children(did).isEmpty()) {
getCol().getDecks().collapse(did);
__renderPage();
dismissAllDialogFragments();
@ -2661,7 +2661,7 @@ public class DeckPicker extends NavigationDrawerActivity implements
if (cids == null) {
return;
}
if (cids.size() == 0) {
if (cids.isEmpty()) {
deckPicker.showSimpleMessageDialog(deckPicker.getResources().getString(R.string.empty_cards_none));
} else {
String msg = String.format(deckPicker.getResources().getString(R.string.empty_cards_count), cids.size());

View File

@ -603,7 +603,7 @@ public class NoteEditor extends AnkiActivity implements
if (mAedictIntent && (mEditFields.size() == 3) && mSourceText[1].contains("[")) {
contents = mSourceText[1].replaceFirst("\\[", "\u001f" + mSourceText[0] + "\u001f");
contents = contents.substring(0, contents.length() - 1);
} else if (mEditFields.size() > 0) {
} else if (!mEditFields.isEmpty()) {
mEditFields.get(0).setText(mSourceText[0]);
if (mEditFields.size() > 1) {
mEditFields.get(1).setText(mSourceText[1]);

View File

@ -98,7 +98,7 @@ public class ReadText {
if (availableTtsLocales.isEmpty()) {
buildAvailableLanguages();
}
if (availableTtsLocales.size() == 0) {
if (availableTtsLocales.isEmpty()) {
Timber.w("ReadText.textToSpeech() no TTS languages available");
builder.content(res.getString(R.string.no_tts_available_message))
.iconAttr(R.attr.dialogErrorIcon)
@ -276,7 +276,7 @@ public class ReadText {
if (status == TextToSpeech.SUCCESS) {
// build list of available languages
buildAvailableLanguages();
if (availableTtsLocales.size() > 0) {
if (!availableTtsLocales.isEmpty()) {
// notify the reviewer that TTS has been initialized
Timber.d("TTS initialized and available languages found");
((AbstractFlashcardViewer) mReviewer.get()).ttsInitialized();

View File

@ -27,7 +27,7 @@ public final class TtsParser {
Element elem = Jsoup.parseBodyFragment(html).body();
parseTtsElements(elem, textsToRead);
if (textsToRead.size() == 0) {
if (textsToRead.isEmpty()) {
// No <tts service="android"> elements found: return the text of the whole HTML fragment
textsToRead.add(new LocalisedText(elem.text().replace(TemplateFilters.CLOZE_DELETION_REPLACEMENT, clozeReplacement)));
}

View File

@ -539,7 +539,7 @@ public class Whiteboard extends View {
}
public boolean empty() {
return mList.size() == 0;
return mList.isEmpty();
}
}

View File

@ -118,7 +118,7 @@ public class CardBrowserMySearchesDialog extends AnalyticsDialogFragment {
mButtonItemAdapter.remove(searchName);
mButtonItemAdapter.notifyAdapterDataSetChanged();
dialog.dismiss();
if (mSavedFilters.size() == 0) {
if (mSavedFilters.isEmpty()) {
getDialog().dismiss();
}
}).show();

View File

@ -90,7 +90,7 @@ public class ImportDialog extends AsyncDialogFragment {
case DIALOG_IMPORT_SELECT: {
// Allow user to choose from the list of available APKG files
List<File> fileList = Utils.getImportableDecks(getActivity());
if (fileList.size() == 0) {
if (fileList.isEmpty()) {
UIUtils.showThemedToast(getActivity(),
getResources().getString(R.string.upgrade_import_no_file_found, "'.apkg'"), false);
return builder.showListener(DialogInterface::cancel).show();

View File

@ -79,16 +79,16 @@ public class MediaCheckDialog extends AsyncDialogFragment {
final ArrayList<String> invalid = getArguments().getStringArrayList("invalid");
// Generate report
final StringBuilder report = new StringBuilder();
if (invalid.size() > 0) {
if (!invalid.isEmpty()) {
report.append(String.format(res().getString(R.string.check_media_invalid), invalid.size()));
}
if (unused.size() > 0) {
if (!unused.isEmpty()) {
if (report.length() > 0) {
report.append("\n");
}
report.append(String.format(res().getString(R.string.check_media_unused), unused.size()));
}
if (nohave.size() > 0) {
if (!nohave.isEmpty()) {
if (report.length() > 0) {
report.append("\n");
}

View File

@ -358,7 +358,7 @@ public class CustomStudyDialog extends AnalyticsDialogFragment implements
break;
}
List<String> arr = new ArrayList<>(selectedTags.size());
if (selectedTags.size() > 0) {
if (!selectedTags.isEmpty()) {
for (String tag : selectedTags) {
arr.add(String.format("tag:'%s'", tag));
}

View File

@ -313,7 +313,7 @@ public class TranslationActivity extends FragmentActivity implements DialogInter
mPossibleTranslations = parseJson(resp, mLangCodeTo);
if (mPossibleTranslations.size() == 0) {
if (mPossibleTranslations.isEmpty()) {
if (!mSource.toLowerCase(Locale.getDefault()).contentEquals(mSource)) {
showToastLong(gtxt(R.string.multimedia_editor_word_search_try_lower_case));
}

View File

@ -312,7 +312,7 @@ public class BasicTextFieldController extends FieldControllerBase implements IFi
private static boolean isIntentAvailable(Context context, Intent intent) {
final PackageManager packageManager = context.getPackageManager();
List<?> list = packageManager.queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY);
return list.size() > 0;
return !list.isEmpty();
}

View File

@ -280,7 +280,7 @@ public class OverviewStatsBuilder {
// Fill in the overview stats
oStats.forecastTotalReviews = tot;
oStats.forecastAverageReviews = totd.size() == 0 ? 0 : (double) tot / (totd.size() * chunk);
oStats.forecastAverageReviews = totd.isEmpty() ? 0 : (double) tot / (totd.size() * chunk);
oStats.forecastDueTomorrow = mCol.getDb().queryScalar(
"select count() from cards where did in " + _limit() + " and queue in (" + Consts.QUEUE_TYPE_REV + "," + Consts.QUEUE_TYPE_DAY_LEARN_RELEARN + ") " +
"and due = ?", mCol.getSched().getToday() + 1);

View File

@ -354,7 +354,7 @@ public class DeckAdapter<T extends AbstractDeckTreeNode<T>> extends RecyclerView
}
// If the deck is not in our list, we search again using the immediate parent
List<Deck> parents = mCol.getDecks().parents(did);
if (parents.size() == 0) {
if (parents.isEmpty()) {
return 0;
} else {
return findDeckPosition(parents.get(parents.size() - 1).optLong("id", 0));

View File

@ -117,7 +117,7 @@ public class CustomTabsHelper {
List<ResolveInfo> handlers = pm.queryIntentActivities(
intent,
PackageManager.GET_RESOLVED_FILTER);
if (handlers == null || handlers.size() == 0) {
if (handlers == null || handlers.isEmpty()) {
return false;
}
for (ResolveInfo resolveInfo : handlers) {

View File

@ -626,7 +626,7 @@ public class Collection implements CollectionGetter {
// check we have card models available, then save
ArrayList<JSONObject> cms = findTemplates(note, allowEmpty);
// Todo: upstream, we accept to add a not even if it generates no card. Should be ported to ankidroid
if (cms.size() == 0) {
if (cms.isEmpty()) {
return 0;
}
note.flush();
@ -653,7 +653,7 @@ public class Collection implements CollectionGetter {
* Bulk delete notes by ID. Don't call this directly.
*/
public void _remNotes(java.util.Collection<Long> ids) {
if (ids.size() == 0) {
if (ids.isEmpty()) {
return;
}
String strids = Utils.ids2str(ids);
@ -981,7 +981,7 @@ public class Collection implements CollectionGetter {
}
public void remCards(java.util.Collection<Long> ids, boolean notes) {
if (ids.size() == 0) {
if (ids.isEmpty()) {
return;
}
String sids = Utils.ids2str(ids);
@ -1142,7 +1142,7 @@ public class Collection implements CollectionGetter {
d.put(type, html);
// empty cloze?
if ("q".equals(type) && model.isCloze()) {
if (Models._availClozeOrds(model, flist, false).size() == 0) {
if (Models._availClozeOrds(model, flist, false).isEmpty()) {
String link = String.format("<a href=\"%s\">%s</a>", mContext.getResources().getString(R.string.link_ankiweb_docs_cloze_deletion), "help");
System.out.println(link);
d.put("q", mContext.getString(R.string.empty_cloze_warning, link));
@ -1302,7 +1302,7 @@ public class Collection implements CollectionGetter {
/** Undo menu item name, or "" if undo unavailable. */
@VisibleForTesting
public @Nullable UndoAction undoType() {
if (mUndo.size() > 0) {
if (!mUndo.isEmpty()) {
return mUndo.getLast();
}
return null;
@ -1317,7 +1317,7 @@ public class Collection implements CollectionGetter {
public boolean undoAvailable() {
Timber.d("undoAvailable() undo size: %s", mUndo.size());
return mUndo.size() > 0;
return !mUndo.isEmpty();
}
public @Nullable Card undo() {
@ -1658,7 +1658,7 @@ public class Collection implements CollectionGetter {
// reviews should have a reasonable due #
ArrayList<Long> ids = mDb.queryLongList("SELECT id FROM cards WHERE queue = " + Consts.QUEUE_TYPE_REV + " AND due > 100000");
notifyProgress.run();
if (ids.size() > 0) {
if (!ids.isEmpty()) {
problems.add("Reviews had incorrect due date.");
mDb.execute("UPDATE cards SET due = ?, ivl = 1, mod = ?, usn = ? WHERE id IN " + Utils.ids2str(ids), mSched.getToday(), getTime().intTime(), usn());
}
@ -1857,7 +1857,7 @@ public class Collection implements CollectionGetter {
}
Timber.i("deleteNotesWithWrongFieldCounts - completed successfully");
notifyProgress.run();
if (ids.size() > 0) {
if (!ids.isEmpty()) {
problems.add("Deleted " + ids.size() + " note(s) with wrong field count.");
_remNotes(ids);
}
@ -1880,7 +1880,7 @@ public class Collection implements CollectionGetter {
ArrayList<Long> ids = mDb.queryLongList(
"SELECT id FROM cards WHERE ord NOT IN " + Utils.ids2str(ords) + " AND nid IN ( " +
"SELECT id FROM notes WHERE mid = ?)", m.getLong("id"));
if (ids.size() > 0) {
if (!ids.isEmpty()) {
problems.add("Deleted " + ids.size() + " card(s) with missing template.");
remCards(ids);
}
@ -1933,9 +1933,9 @@ public class Collection implements CollectionGetter {
*/
private void logProblems(List<String> integrityCheckProblems) {
if (integrityCheckProblems.size() > 0) {
if (!integrityCheckProblems.isEmpty()) {
StringBuffer additionalInfo = new StringBuffer();
for (int i = 0; ((i < 10) && (integrityCheckProblems.size() > i)); i++) {
for (int i = 0; ((i < 10) && (integrityCheckProblems.size()) > i); i++) {
additionalInfo.append(integrityCheckProblems.get(i)).append("\n");
// log analytics event so we can see trends if user allows it
UsageAnalytics.sendAnalyticsEvent("DatabaseCorruption", integrityCheckProblems.get(i));
@ -2393,7 +2393,7 @@ public class Collection implements CollectionGetter {
}
public boolean hasProblems() {
return mProblems.size() > 0;
return !mProblems.isEmpty();
}

View File

@ -208,7 +208,7 @@ public class Finder {
} else if (c == '-') {
if (token.length() != 0) {
token += c;
} else if (tokens.size() == 0 || !"-".equals(tokens.get(tokens.size() - 1))) {
} else if (tokens.isEmpty() || !"-".equals(tokens.get(tokens.size() - 1))) {
tokens.add("-");
}
// normal character
@ -698,7 +698,7 @@ public class Finder {
}
}
}
if (ids == null || ids.size() == 0) {
if (ids == null || ids.isEmpty()) {
return null;
}
String sids = Utils.ids2str(ids);

View File

@ -957,7 +957,7 @@ public class Media {
media.add(new Object[] {name, csum, _mtime(destPath), 0});
cnt += 1;
}
if (media.size() > 0) {
if (!media.isEmpty()) {
mDb.executeMany("insert or replace into media values (?,?,?,?)", media);
}
return cnt;

View File

@ -248,7 +248,7 @@ public class Tags extends TagManager {
/** {@inheritDoc} */
@NonNull
public String join(@NonNull java.util.Collection<String> tags) {
if (tags.size() == 0) {
if (tags.isEmpty()) {
return "";
} else {
String joined = TextUtils.join(" ", tags);

View File

@ -857,7 +857,7 @@ public class Utils {
final Intent intent = new Intent(action);
intent.setComponent(componentName);
List<ResolveInfo> list = packageManager.queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY);
return list.size() > 0;
return !list.isEmpty();
}
/**

View File

@ -334,7 +334,7 @@ public class Anki2Importer extends Importer {
if (dupes > 0) {
mLog.add(getRes().getString(R.string.import_update_details, totalUpdateCount, dupes));
if (dupesIgnored.size() > 0) {
if (!dupesIgnored.isEmpty()) {
mLog.add(getRes().getString(R.string.import_update_ignored));
}
}

View File

@ -80,7 +80,7 @@ public class TextImporter extends NoteImporter {
}
List<String> rowAsString = new ArrayList<>(row);
if (rowAsString.size() != mNumFields) {
if (rowAsString.size() > 0) {
if (!rowAsString.isEmpty()) {
String formatted = getString(R.string.csv_importer_error_invalid_field_count,
TextUtils.join(" ", rowAsString),
rowAsString.size(),
@ -208,7 +208,7 @@ public class TextImporter extends NoteImporter {
try {
while (true) {
List<String> row = reader.next();
if (row.size() > 0) {
if (!row.isEmpty()) {
mNumFields = row.size();
break;
}

View File

@ -283,7 +283,7 @@ public class CsvSniffer {
double consistency = 1.0;
// minimum consistency threshold
double threshold = 0.9;
while (delims.size() == 0 && consistency >= threshold) {
while (delims.isEmpty() && consistency >= threshold) {
for (Map.Entry<Character, Tuple> entry : modeList) {
Tuple value = entry.getValue();
if (value.first > 0 && value.second > 0) {

View File

@ -274,7 +274,7 @@ public class AdvancedStatistics {
metaInfo.setmSeriesList(seriesList);
metaInfo.setDataAvailable(dues.size() > 0);
metaInfo.setDataAvailable(!dues.isEmpty());
return metaInfo;
}
@ -336,7 +336,7 @@ public class AdvancedStatistics {
}
// small adjustment for a proper chartbuilding
if (dues.size() == 0 || dues.get(0)[0] > 0) {
if (dues.isEmpty() || dues.get(0)[0] > 0) {
dues.add(0, new int[] { 0, 0, 0, 0, 0 });
}
if (type == Stats.AxisType.TYPE_LIFE && dues.size() < 2) {

View File

@ -459,7 +459,7 @@ public class Stats {
}
}
// small adjustment for a proper chartbuilding with achartengine
if (dues.size() == 0 || dues.get(0)[0] > 0) {
if (dues.isEmpty() || dues.get(0)[0] > 0) {
dues.add(0, new int[] { 0, 0, 0 });
}
if (end == -1 && dues.size() < 2) {
@ -517,7 +517,7 @@ public class Stats {
if (mMaxCards == 0) {
mMaxCards = 10;
}
return dues.size() > 0;
return !dues.isEmpty();
}
@ -574,7 +574,7 @@ public class Stats {
if (lim.length() > 0) {
lims.add(lim);
}
if (lims.size() > 0) {
if (!lims.isEmpty()) {
lim = "WHERE ";
while (lims.size() > 1) {
lim += lims.remove(0) + " AND ";
@ -624,9 +624,9 @@ public class Stats {
// small adjustment for a proper chartbuilding with achartengine
if (type != AxisType.TYPE_LIFE && (list.size() == 0 || list.get(0)[0] > -num)) {
if (type != AxisType.TYPE_LIFE && (list.isEmpty() || list.get(0)[0] > -num)) {
list.add(0, new double[] { -num, 0, 0, 0, 0, 0 });
} else if (type == AxisType.TYPE_LIFE && list.size() == 0) {
} else if (type == AxisType.TYPE_LIFE && list.isEmpty()) {
list.add(0, new double[] { -12, 0, 0, 0, 0, 0 });
}
if (list.get(list.size() - 1)[0] < 0) {
@ -712,7 +712,7 @@ public class Stats {
mFirstElement = -10;
mLastElement = 0;
}
return list.size() > 0;
return !list.isEmpty();
}
@ -792,7 +792,7 @@ public class Stats {
}
// small adjustment for a proper chartbuilding with achartengine
if (list.size() == 0 || list.get(0)[0] > 0) {
if (list.isEmpty() || list.get(0)[0] > 0) {
list.add(0, new double[] { 0, 0, 0 });
}
if (num == -1 && list.size() < 2) {
@ -850,7 +850,7 @@ public class Stats {
if (mMaxCards == 0) {
mMaxCards = 10;
}
return list.size() > 0;
return !list.isEmpty();
}
/**
@ -898,7 +898,7 @@ public class Stats {
//TODO adjust for breakdown, for now only copied from intervals
//small adjustment for a proper chartbuilding with achartengine
if (list.size() == 0) {
if (list.isEmpty()) {
list.add(0, new double[] { 0, 0, 0 });
}
@ -972,7 +972,7 @@ public class Stats {
if (mMaxCards == 0) {
mMaxCards = 10;
}
return list.size() > 0;
return !list.isEmpty();
}
/**
@ -1020,7 +1020,7 @@ public class Stats {
//TODO adjust for breakdown, for now only copied from intervals
// small adjustment for a proper chartbuilding with achartengine
if (list.size() == 0 ) {
if (list.isEmpty() ) {
list.add(0, new double[] { 0, 0, 0 });
}
@ -1082,7 +1082,7 @@ public class Stats {
if (mMaxCards == 0) {
mMaxCards = 10;
}
return list.size() > 0;
return !list.isEmpty();
}
@ -1102,7 +1102,7 @@ public class Stats {
//TODO adjust for AnswerButton, for now only copied from intervals
// small adjustment for a proper chartbuilding with achartengine
if (list.size() == 0) {
if (list.isEmpty()) {
list.add(0, new double[]{0, 1, 0});
}
@ -1134,7 +1134,7 @@ public class Stats {
if(mMaxCards == 0) {
mMaxCards = 10;
}
return list.size() > 0;
return !list.isEmpty();
}

View File

@ -189,7 +189,7 @@ public class MediaSyncer {
File zip = changesZip.first;
try {
List<String> fnames = changesZip.second;
if (fnames.size() == 0) {
if (fnames.isEmpty()) {
break;
}
@ -239,7 +239,7 @@ public class MediaSyncer {
private void _downloadFiles(List<String> fnames) {
mCol.log(fnames.size() + " files to fetch");
while (fnames.size() > 0) {
while (!fnames.isEmpty()) {
try {
List<String> top = fnames.subList(0, Math.min(fnames.size(), Consts.SYNC_ZIP_COUNT));
mCol.log("fetch " + top);

View File

@ -46,7 +46,7 @@ public class ParsedNodes extends ParsedNode {
* @return The list of node, as compactly as possible.
*/
public static @NonNull ParsedNode create(List<ParsedNode> nodes) {
if (nodes.size() == 0) {
if (nodes.isEmpty()) {
return new EmptyNode();
} else if (nodes.size() == 1) {
return nodes.get(0);