Skip to content

Commit

Permalink
Replace size() == 0 check with isEmpty() check
Browse files Browse the repository at this point in the history
  • Loading branch information
MewX committed Dec 21, 2024
1 parent e26e6a9 commit 27e2646
Show file tree
Hide file tree
Showing 15 changed files with 34 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@

import java.io.File;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

Expand Down Expand Up @@ -88,7 +87,7 @@ else if (menuItem.getItemId() == R.id.action_find) {
i.putExtra(FilePickerActivity.EXTRA_ALLOW_CREATE_DIR, true);
i.putExtra(FilePickerActivity.EXTRA_MODE, FilePickerActivity.MODE_FILE);
i.putExtra(FilePickerActivity.EXTRA_START_PATH,
GlobalConfig.pathPickedSave == null || GlobalConfig.pathPickedSave.length() == 0 ?
GlobalConfig.pathPickedSave == null || GlobalConfig.pathPickedSave.isEmpty() ?
Environment.getExternalStorageDirectory().getPath() : GlobalConfig.pathPickedSave);
startActivityForResult(i, 0);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -603,7 +603,7 @@ protected Integer doInBackground(Integer... params) {
novelFullIntro = new String(byteNovelFullInfo, "UTF-8"); // save
}
mNovelItemMeta.fullIntro = novelFullIntro;
if(mNovelItemMeta.fullIntro.length() == 0) return -1;
if(mNovelItemMeta.fullIntro.isEmpty()) return -1;
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
return -2;
Expand Down Expand Up @@ -815,11 +815,11 @@ protected Wenku8Error.ErrorCode doInBackground(Integer... params) {
// load from local first
if (!isLoading) return Wenku8Error.ErrorCode.USER_CANCELLED_TASK; // calcel
String xml = GlobalConfig.loadFullFileFromSaveFolder("novel", tempCi.cid + ".xml"); // prevent empty file
if (xml.length() == 0 || operationType == 2) {
if (xml.isEmpty() || operationType == 2) {
byte[] tempXml = LightNetwork.LightHttpPostConnection(Wenku8API.BASE_URL, cv);
if (tempXml == null) return Wenku8Error.ErrorCode.NETWORK_ERROR; // network error
xml = new String(tempXml, "UTF-8");
if(xml.trim().length() == 0) return Wenku8Error.ErrorCode.SERVER_RETURN_NOTHING;
if(xml.trim().isEmpty()) return Wenku8Error.ErrorCode.SERVER_RETURN_NOTHING;
GlobalConfig.writeFullFileIntoSaveFolder("novel", tempCi.cid + ".xml", xml);
}

Expand Down Expand Up @@ -1027,11 +1027,11 @@ protected Wenku8Error.ErrorCode doInBackground(Integer[]... params) {
// load from local first
if (!loading) return Wenku8Error.ErrorCode.USER_CANCELLED_TASK; // cancel
String xml = GlobalConfig.loadFullFileFromSaveFolder("novel", tempCi.cid + ".xml"); // prevent empty file
if (xml.length() == 0) {
if (xml.isEmpty()) {
byte[] tempXml = LightNetwork.LightHttpPostConnection(Wenku8API.BASE_URL, cv);
if (tempXml == null) return Wenku8Error.ErrorCode.NETWORK_ERROR; // network error
xml = new String(tempXml, "UTF-8");
if(xml.trim().length() == 0) return Wenku8Error.ErrorCode.SERVER_RETURN_NOTHING;
if(xml.trim().isEmpty()) return Wenku8Error.ErrorCode.SERVER_RETURN_NOTHING;
GlobalConfig.writeFullFileIntoSaveFolder("novel", tempCi.cid + ".xml", xml);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,8 @@ public boolean onOptionsItemSelected(MenuItem menuItem) {
public void onBackPressed() {
// TODO: save draft

if (etTitle.getText().toString().trim().length() != 0 ||
etContent.getText().toString().trim().length() != 0) {
if (!etTitle.getText().toString().trim().isEmpty() ||
!etContent.getText().toString().trim().isEmpty()) {
new MaterialDialog.Builder(this)
.theme(Theme.LIGHT)
.title(R.string.system_warning)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ protected void onCreate(Bundle savedInstanceState) {
toolbarSearchView.setOnEditorActionListener((v, actionId, event) -> {
// purify
String temp = toolbarSearchView.getText().toString().trim();
if(temp.length()==0) return false;
if(temp.isEmpty()) return false;

// real action
//Toast.makeText(MyApp.getContext(), temp, Toast.LENGTH_SHORT).show();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ protected void onCreate(Bundle savedInstanceState) {

// listeners
tvLogin.setOnClickListener(v -> {
if(etUserNameOrEmail.getText().toString().length() == 0 || etUserNameOrEmail.getText().toString().length() > 30
|| etPassword.getText().toString().length() == 0 || etPassword.getText().toString().length() > 30) {
if(etUserNameOrEmail.getText().toString().isEmpty() || etUserNameOrEmail.getText().toString().length() > 30
|| etPassword.getText().toString().isEmpty() || etPassword.getText().toString().length() > 30) {
Toast.makeText(UserLoginActivity.this, getResources().getString(R.string.system_info_fill_not_complete), Toast.LENGTH_SHORT).show();
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ protected Integer doInBackground(ContentValues... params) {
}

nc = OldNovelContentParser.parseNovelContent(xml, pDialog);
if (nc == null || nc.size() == 0) {
if (nc == null || nc.isEmpty()) {
Log.e("MewX-Main", "getNullFromParser (NovelContentParser.parseNovelContent(xml);)");

// network error or parse failed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ public void onClick(View v) {
i.putExtra(FilePickerActivity.EXTRA_ALLOW_CREATE_DIR, true);
i.putExtra(FilePickerActivity.EXTRA_MODE, FilePickerActivity.MODE_DIR);
i.putExtra(FilePickerActivity.EXTRA_START_PATH,
GlobalConfig.pathPickedSave == null || GlobalConfig.pathPickedSave.length() == 0 ?
GlobalConfig.pathPickedSave == null || GlobalConfig.pathPickedSave.isEmpty() ?
Environment.getExternalStorageDirectory().getPath() : GlobalConfig.pathPickedSave);
startActivityForResult(i, 0);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ protected Wenku8Error.ErrorCode doInBackground(Integer... params) {
listDiff.clear();
listDiff.addAll(hs);
}
if(listDiff.size() == 0 && localOnly.size() == 0) {
if(listDiff.isEmpty() && localOnly.isEmpty()) {
// equal, so exit
return Wenku8Error.ErrorCode.SYSTEM_1_SUCCEEDED;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -739,7 +739,7 @@ public static void loadAllSetting() {
String[] sets = h.split("\\|\\|\\|\\|");
for(String set : sets) {
String[] temp = set.split("::::");
if(temp.length != 2 || temp[0] == null || temp[0].length() == 0 || temp[1] == null || temp[1].length() == 0) continue;
if(temp.length != 2 || temp[0] == null || temp[0].isEmpty() || temp[1] == null || temp[1].isEmpty()) continue;

allSetting.put(temp[0], temp[1]);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,10 @@ public static UserInfo parseUserInfo(@NonNull String xml) {
} else if ("item".equals(xmlPullParser.getName())) {
if ("uname".equals(xmlPullParser.getAttributeValue(0))) {
ui.username = xmlPullParser.nextText();
Log.d("MewX", ui.username.length() == 0 ? GlobalConfig.UNKNOWN : ui.username);
Log.d("MewX", ui.username.isEmpty() ? GlobalConfig.UNKNOWN : ui.username);
} else if ("nickname".equals(xmlPullParser.getAttributeValue(0))) {
ui.nickyname = xmlPullParser.nextText();
Log.d("MewX", ui.nickyname.length() == 0 ? GlobalConfig.UNKNOWN : ui.nickyname);
Log.d("MewX", ui.nickyname.isEmpty() ? GlobalConfig.UNKNOWN : ui.nickyname);
} else if ("score".equals(xmlPullParser.getAttributeValue(0))) {
ui.score = Integer.valueOf(xmlPullParser.nextText());
Log.d("MewX", "score:" + ui.score);
Expand All @@ -65,7 +65,7 @@ public static UserInfo parseUserInfo(@NonNull String xml) {
Log.d("MewX", "experience:" + ui.experience);
} else if ("rank".equals(xmlPullParser.getAttributeValue(0))) {
ui.rank = xmlPullParser.nextText();
Log.d("MewX", ui.rank.length() == 0 ? GlobalConfig.UNKNOWN : ui.rank);
Log.d("MewX", ui.rank.isEmpty() ? GlobalConfig.UNKNOWN : ui.rank);
}
}
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public class VolumeList implements Serializable {
public void cleanLocalCache() {
for (ChapterInfo tempCi : this.chapterList) {
String xml = GlobalConfig.loadFullFileFromSaveFolder("novel", tempCi.cid + ".xml");
if (xml.length() == 0) {
if (xml.isEmpty()) {
return;
}
List<OldNovelContentParser.NovelContent> nc = OldNovelContentParser.NovelContentParser_onlyImage(xml);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ protected void onCreate(Bundle savedInstanceState) {
cid = getIntent().getIntExtra("cid", 1);
from = getIntent().getStringExtra("from");
forcejump = getIntent().getStringExtra("forcejump");
if(forcejump == null || forcejump.length() == 0) forcejump = "no";
if(forcejump == null || forcejump.isEmpty()) forcejump = "no";
// tempNavBarHeight = LightTool.getNavigationBarSize(this).y;

// Analysis.
Expand Down Expand Up @@ -247,8 +247,8 @@ public boolean dispatchKeyEvent(@NonNull KeyEvent event) {
}

class SlidingPageAdapter extends SlidingAdapter<WenkuReaderPageView> {
int firstLineIndex = 0; // line index of first index of this page
int firstWordIndex = 0; // first index of this page
int firstLineIndex; // line index of first index of this page
int firstWordIndex; // first index of this page
int lastLineIndex = 0; // line index of last index of this page
int lastWordIndex = 0; // last index of this page

Expand Down Expand Up @@ -424,8 +424,8 @@ protected Wenku8Error.ErrorCode doInBackground(ContentValues... params) {
}

nc = OldNovelContentParser.parseNovelContent(xml, null);
if (nc.size() == 0)
return xml.length() == 0 ? Wenku8Error.ErrorCode.SERVER_RETURN_NOTHING : Wenku8Error.ErrorCode.XML_PARSE_FAILED;
if (nc.isEmpty())
return xml.isEmpty() ? Wenku8Error.ErrorCode.SERVER_RETURN_NOTHING : Wenku8Error.ErrorCode.XML_PARSE_FAILED;

return Wenku8Error.ErrorCode.SYSTEM_1_SUCCEEDED;
} catch (UnsupportedEncodingException e) {
Expand Down Expand Up @@ -668,7 +668,7 @@ public void onStopTrackingTouch(DiscreteSeekBar discreteSeekBar) {
i.putExtra(FilePickerActivity.EXTRA_ALLOW_CREATE_DIR, true);
i.putExtra(FilePickerActivity.EXTRA_MODE, FilePickerActivity.MODE_FILE);
i.putExtra(FilePickerActivity.EXTRA_START_PATH,
GlobalConfig.pathPickedSave == null || GlobalConfig.pathPickedSave.length() == 0 ?
GlobalConfig.pathPickedSave == null || GlobalConfig.pathPickedSave.isEmpty() ?
Environment.getExternalStorageDirectory().getPath() : GlobalConfig.pathPickedSave);
startActivityForResult(i, REQUEST_FONT_PICKER_LEGACY);
}
Expand Down Expand Up @@ -704,7 +704,7 @@ public void onStopTrackingTouch(DiscreteSeekBar discreteSeekBar) {
i.putExtra(FilePickerActivity.EXTRA_ALLOW_CREATE_DIR, true);
i.putExtra(FilePickerActivity.EXTRA_MODE, FilePickerActivity.MODE_FILE);
i.putExtra(FilePickerActivity.EXTRA_START_PATH,
GlobalConfig.pathPickedSave == null || GlobalConfig.pathPickedSave.length() == 0 ?
GlobalConfig.pathPickedSave == null || GlobalConfig.pathPickedSave.isEmpty() ?
Environment.getExternalStorageDirectory().getPath() : GlobalConfig.pathPickedSave);
startActivityForResult(i, REQUEST_IMAGE_PICKER_LEGACY);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ private void calcFromFirst() {
tempText = new StringBuilder("  ");
}
else if(mLoader.getCurrentType() == WenkuReaderLoader.ElementType.IMAGE_DEPENDENT) {
if(lineInfoList.size() != 0) {
if(!lineInfoList.isEmpty()) {
// end a page first
lastLineIndex = mLoader.getCurrentIndex() - 1;
mLoader.setCurrentIndex(lastLineIndex);
Expand Down Expand Up @@ -439,7 +439,7 @@ private void calcFromLast() {
String curString = mLoader.getCurrentAsString();

// special to image
if(curType == WenkuReaderLoader.ElementType.IMAGE_DEPENDENT && lineInfoList.size() != 0) {
if(curType == WenkuReaderLoader.ElementType.IMAGE_DEPENDENT && !lineInfoList.isEmpty()) {
Log.d("MewX", "jump 1");
firstLineIndex = curLineIndex + 1;
firstWordIndex = 0;
Expand Down Expand Up @@ -719,7 +719,7 @@ protected void onPostExecute(Wenku8Error.ErrorCode errorCode) {
}

public void watchImageDetailed(Activity activity) {
if(bitmapInfoList == null || bitmapInfoList.size() == 0 || bitmapInfoList.get(0).bm == null) {
if(bitmapInfoList == null || bitmapInfoList.isEmpty() || bitmapInfoList.get(0).bm == null) {
Toast.makeText(getContext(), getResources().getString(R.string.reader_view_image_no_image), Toast.LENGTH_SHORT).show();
}
else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public static byte[] LightHttpPostConnection(String u, ContentValues values, boo
http = (HttpURLConnection) url.openConnection();
http.setRequestMethod("POST");
http.setRequestProperty("Accept-Encoding", "gzip"); // set gzip
if(withSession && LightUserSession.getSession().length() != 0) {
if(withSession && !LightUserSession.getSession().isEmpty()) {
http.setRequestProperty("Cookie", "PHPSESSID=" + LightUserSession.getSession());
}
http.setConnectTimeout(3000);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public class LightUserSession {

// no null returned
public static String getLoggedAs() {
return ( logStatus && SESSION != null && SESSION.length() != 0 && isUserInfoSet()) ? usernameOrEmail : "";
return ( logStatus && SESSION != null && !SESSION.isEmpty() && isUserInfoSet()) ? usernameOrEmail : "";
}

public static String getUsernameOrEmail() {
Expand All @@ -50,7 +50,7 @@ public static String getSession() {
}

public static void setSession(String s) {
if(s != null && s.length() != 0) SESSION = s;
if(s != null && !s.isEmpty()) SESSION = s;
}

public static boolean getLogStatus() {
Expand Down Expand Up @@ -190,7 +190,7 @@ public static Wenku8Error.ErrorCode heartbeatLogin() {
* @return true is okay.
*/
public static boolean isUserInfoSet() {
return usernameOrEmail != null && password != null && usernameOrEmail.length() != 0 && password.length() != 0;
return usernameOrEmail != null && password != null && !usernameOrEmail.isEmpty() && !password.isEmpty();
}

public static void setUserInfo(String username, String password) {
Expand All @@ -205,7 +205,7 @@ public static void setUserInfo(String username, String password) {
public static void decAndSetUserFile(String raw) {
try {
String[] a = raw.split("\\|"); // a[0]: username; a[1]: password;
if (a.length != 2 || a[0].length() == 0 || a[1].length() == 0) {
if (a.length != 2 || a[0].isEmpty() || a[1].isEmpty()) {
setUserInfo("", "");
return; // fetch error to return
}
Expand Down

0 comments on commit 27e2646

Please sign in to comment.