Replace "if(" with "if ("

This commit is contained in:
agnostic-apollo
2021-04-12 14:32:02 +05:00
parent 0cd7cb8162
commit 24a5493ea5
11 changed files with 107 additions and 105 deletions

View File

@@ -104,9 +104,9 @@ public class FileAttributes {
}
public String file() {
if(filePath != null)
if (filePath != null)
return filePath;
else if(fileDescriptor != null)
else if (fileDescriptor != null)
return fileDescriptor.toString();
else
return null;
@@ -397,7 +397,7 @@ public class FileAttributes {
logString.append("\n").append(fileAttributes.getInodeString());
logString.append("\n").append(fileAttributes.getLinksString());
if(fileAttributes.isBlock() || fileAttributes.isCharacter())
if (fileAttributes.isBlock() || fileAttributes.isCharacter())
logString.append("\n").append(fileAttributes.getDeviceTypeString());
logString.append("\n").append(fileAttributes.getOwnerString());

View File

@@ -104,7 +104,7 @@ public class FileUtilsTests {
errmsg = FileUtils.clearDirectory(context, label, testRootDirectoryPath);
assertEqual("Failed to create " + label + " directory file", null, errmsg);
if(!FileUtils.directoryFileExists(testRootDirectoryPath, false))
if (!FileUtils.directoryFileExists(testRootDirectoryPath, false))
throwException("The " + label + " directory file does not exist as expected after creation");
@@ -124,30 +124,30 @@ public class FileUtilsTests {
label = dir1__sub_dir1_label; path = dir1__sub_dir1_path;
errmsg = FileUtils.createDirectoryFile(context, label, path);
assertEqual("Failed to create " + label + " directory file", null, errmsg);
if(!FileUtils.directoryFileExists(path, false))
if (!FileUtils.directoryFileExists(path, false))
throwException("The " + label + " directory file does not exist as expected after creation");
// Create dir1/sub_reg1 regular file
label = dir1__sub_reg1_label; path = dir1__sub_reg1_path;
errmsg = FileUtils.createRegularFile(context, label, path);
assertEqual("Failed to create " + label + " regular file", null, errmsg);
if(!FileUtils.regularFileExists(path, false))
if (!FileUtils.regularFileExists(path, false))
throwException("The " + label + " regular file does not exist as expected after creation");
// Create dir1/sub_sym1 -> dir2 absolute symlink file
label = dir1__sub_sym1_label; path = dir1__sub_sym1_path;
errmsg = FileUtils.createSymlinkFile(context, label, dir2_path, path);
assertEqual("Failed to create " + label + " symlink file", null, errmsg);
if(!FileUtils.symlinkFileExists(path))
if (!FileUtils.symlinkFileExists(path))
throwException("The " + label + " symlink file does not exist as expected after creation");
// Copy dir1/sub_sym1 symlink file to dir1/sub_sym2
label = dir1__sub_sym2_label; path = dir1__sub_sym2_path;
errmsg = FileUtils.copySymlinkFile(context, label, dir1__sub_sym1_path, path, false);
assertEqual("Failed to copy " + dir1__sub_sym1_label + " symlink file to " + label, null, errmsg);
if(!FileUtils.symlinkFileExists(path))
if (!FileUtils.symlinkFileExists(path))
throwException("The " + label + " symlink file does not exist as expected after copying it from " + dir1__sub_sym1_label);
if(!new File(path).getCanonicalPath().equals(dir2_path))
if (!new File(path).getCanonicalPath().equals(dir2_path))
throwException("The " + label + " symlink file does not point to " + dir2_label);
@@ -158,7 +158,7 @@ public class FileUtilsTests {
label = dir2__sub_reg1_label; path = dir2__sub_reg1_path;
errmsg = FileUtils.writeStringToFile(context, label, path, Charset.defaultCharset(), "line1", false);
assertEqual("Failed to write string to " + label + " file with append mode false", null, errmsg);
if(!FileUtils.regularFileExists(path, false))
if (!FileUtils.regularFileExists(path, false))
throwException("The " + label + " file does not exist as expected after writing to it with append mode false");
// Write "line2" to dir2/sub_reg1 regular file
@@ -175,7 +175,7 @@ public class FileUtilsTests {
label = dir2__sub_reg2_label; path = dir2__sub_reg2_path;
errmsg = FileUtils.copyRegularFile(context, label, dir2__sub_reg1_path, path, false);
assertEqual("Failed to copy " + dir2__sub_reg1_label + " regular file to " + label, null, errmsg);
if(!FileUtils.regularFileExists(path, false))
if (!FileUtils.regularFileExists(path, false))
throwException("The " + label + " regular file does not exist as expected after copying it from " + dir2__sub_reg1_label);
@@ -186,21 +186,21 @@ public class FileUtilsTests {
label = dir3_label; path = dir3_path;
errmsg = FileUtils.copyDirectoryFile(context, label, dir2_path, path, false);
assertEqual("Failed to copy " + dir2_label + " directory file to " + label, null, errmsg);
if(!FileUtils.directoryFileExists(path, false))
if (!FileUtils.directoryFileExists(path, false))
throwException("The " + label + " directory file does not exist as expected after copying it from " + dir2_label);
// Copy dir1 directory file to dir3 again to test overwrite
label = dir3_label; path = dir3_path;
errmsg = FileUtils.copyDirectoryFile(context, label, dir2_path, path, false);
assertEqual("Failed to copy " + dir2_label + " directory file to " + label, null, errmsg);
if(!FileUtils.directoryFileExists(path, false))
if (!FileUtils.directoryFileExists(path, false))
throwException("The " + label + " directory file does not exist as expected after copying it from " + dir2_label);
// Move dir3 directory file to dir4
label = dir4_label; path = dir4_path;
errmsg = FileUtils.moveDirectoryFile(context, label, dir3_path, path, false);
assertEqual("Failed to move " + dir3_label + " directory file to " + label, null, errmsg);
if(!FileUtils.directoryFileExists(path, false))
if (!FileUtils.directoryFileExists(path, false))
throwException("The " + label + " directory file does not exist as expected after copying it from " + dir3_label);
@@ -211,7 +211,7 @@ public class FileUtilsTests {
label = dir1__sub_sym3_label; path = dir1__sub_sym3_path;
errmsg = FileUtils.createSymlinkFile(context, label, "../dir4", path);
assertEqual("Failed to create " + label + " symlink file", null, errmsg);
if(!FileUtils.symlinkFileExists(path))
if (!FileUtils.symlinkFileExists(path))
throwException("The " + label + " symlink file does not exist as expected after creation");
// Create dir1/sub_sym3 -> dirX relative dangling symlink file
@@ -219,7 +219,7 @@ public class FileUtilsTests {
label = dir1__sub_sym3_label; path = dir1__sub_sym3_path;
errmsg = FileUtils.createSymlinkFile(context, label, "../dirX", path);
assertEqual("Failed to create " + label + " symlink file", null, errmsg);
if(!FileUtils.symlinkFileExists(path))
if (!FileUtils.symlinkFileExists(path))
throwException("The " + label + " dangling symlink file does not exist as expected after creation");
@@ -230,13 +230,13 @@ public class FileUtilsTests {
label = dir1__sub_sym2_label; path = dir1__sub_sym2_path;
errmsg = FileUtils.deleteSymlinkFile(context, label, path, false);
assertEqual("Failed to delete " + label + " symlink file", null, errmsg);
if(FileUtils.fileExists(path, false))
if (FileUtils.fileExists(path, false))
throwException("The " + label + " symlink file still exist after deletion");
// Check if dir2 directory file still exists after deletion of dir1/sub_sym2 since it was a symlink to dir2
// When deleting a symlink file, its target must not be deleted
label = dir2_label; path = dir2_path;
if(!FileUtils.directoryFileExists(path, false))
if (!FileUtils.directoryFileExists(path, false))
throwException("The " + label + " directory file has unexpectedly been deleted after deletion of " + dir1__sub_sym2_label);
@@ -247,7 +247,7 @@ public class FileUtilsTests {
label = dir1_label; path = dir1_path;
errmsg = FileUtils.deleteDirectoryFile(context, label, path, false);
assertEqual("Failed to delete " + label + " directory file", null, errmsg);
if(FileUtils.fileExists(path, false))
if (FileUtils.fileExists(path, false))
throwException("The " + label + " directory file still exist after deletion");
@@ -255,10 +255,10 @@ public class FileUtilsTests {
// dir1 since there was a dir1/sub_sym1 symlink to dir2 in it
// When deleting a directory, any targets of symlinks must not be deleted when deleting symlink files
label = dir2_label; path = dir2_path;
if(!FileUtils.directoryFileExists(path, false))
if (!FileUtils.directoryFileExists(path, false))
throwException("The " + label + " directory file has unexpectedly been deleted after deletion of " + dir1_label);
label = dir2__sub_reg1_label; path = dir2__sub_reg1_path;
if(!FileUtils.fileExists(path, false))
if (!FileUtils.fileExists(path, false))
throwException("The " + label + " regular file has unexpectedly been deleted after deletion of " + dir1_label);
@@ -269,7 +269,7 @@ public class FileUtilsTests {
label = dir2__sub_reg1_label; path = dir2__sub_reg1_path;
errmsg = FileUtils.deleteRegularFile(context, label, path, false);
assertEqual("Failed to delete " + label + " regular file", null, errmsg);
if(FileUtils.fileExists(path, false))
if (FileUtils.fileExists(path, false))
throwException("The " + label + " regular file still exist after deletion");
FileUtils.getFileType("/dev/ptmx", false);

View File

@@ -32,15 +32,15 @@ public class Logger {
public static void logMessage(int logLevel, String tag, String message) {
if(logLevel == Log.ERROR && CURRENT_LOG_LEVEL >= LOG_LEVEL_NORMAL)
if (logLevel == Log.ERROR && CURRENT_LOG_LEVEL >= LOG_LEVEL_NORMAL)
Log.e(getFullTag(tag), message);
else if(logLevel == Log.WARN && CURRENT_LOG_LEVEL >= LOG_LEVEL_NORMAL)
else if (logLevel == Log.WARN && CURRENT_LOG_LEVEL >= LOG_LEVEL_NORMAL)
Log.w(getFullTag(tag), message);
else if(logLevel == Log.INFO && CURRENT_LOG_LEVEL >= LOG_LEVEL_NORMAL)
else if (logLevel == Log.INFO && CURRENT_LOG_LEVEL >= LOG_LEVEL_NORMAL)
Log.i(getFullTag(tag), message);
else if(logLevel == Log.DEBUG && CURRENT_LOG_LEVEL >= LOG_LEVEL_DEBUG)
else if (logLevel == Log.DEBUG && CURRENT_LOG_LEVEL >= LOG_LEVEL_DEBUG)
Log.d(getFullTag(tag), message);
else if(logLevel == Log.VERBOSE && CURRENT_LOG_LEVEL >= LOG_LEVEL_VERBOSE)
else if (logLevel == Log.VERBOSE && CURRENT_LOG_LEVEL >= LOG_LEVEL_VERBOSE)
Log.v(getFullTag(tag), message);
}
@@ -99,7 +99,7 @@ public class Logger {
public static void logErrorAndShowToast(Context context, String tag, String message) {
if (context == null) return;
if(CURRENT_LOG_LEVEL >= LOG_LEVEL_NORMAL) {
if (CURRENT_LOG_LEVEL >= LOG_LEVEL_NORMAL) {
logError(tag, message);
showToast(context, message, true);
}
@@ -114,7 +114,7 @@ public class Logger {
public static void logDebugAndShowToast(Context context, String tag, String message) {
if (context == null) return;
if(CURRENT_LOG_LEVEL >= LOG_LEVEL_DEBUG) {
if (CURRENT_LOG_LEVEL >= LOG_LEVEL_DEBUG) {
logDebug(tag, message);
showToast(context, message, true);
}
@@ -127,7 +127,7 @@ public class Logger {
public static void logStackTraceWithMessage(String tag, String message, Throwable throwable) {
if(CURRENT_LOG_LEVEL >= LOG_LEVEL_NORMAL)
if (CURRENT_LOG_LEVEL >= LOG_LEVEL_NORMAL)
Log.e(getFullTag(tag), getMessageAndStackTraceString(message, throwable));
}
@@ -144,12 +144,12 @@ public class Logger {
}
public static void logStackTracesWithMessage(String tag, String message, List<Throwable> throwableList) {
if(CURRENT_LOG_LEVEL >= LOG_LEVEL_NORMAL)
if (CURRENT_LOG_LEVEL >= LOG_LEVEL_NORMAL)
Log.e(getFullTag(tag), getMessageAndStackTracesString(message, throwableList));
}
public static String getMessageAndStackTraceString(String message, Throwable throwable) {
if(message == null && throwable == null)
if (message == null && throwable == null)
return null;
else if(message != null && throwable != null)
return message + ":\n" + getStackTraceString(throwable);

View File

@@ -131,10 +131,10 @@ public class ExecutionCommand {
public ExecutionCommand(){
public ExecutionCommand() {
}
public ExecutionCommand(Integer id){
public ExecutionCommand(Integer id) {
this.id = id;
}

View File

@@ -52,7 +52,7 @@ public class SharedPreferenceUtils {
* default if failed to read a valid value, like in case of an exception.
*/
public static boolean getBoolean(SharedPreferences sharedPreferences, String key, boolean def) {
if(sharedPreferences == null) {
if (sharedPreferences == null) {
Logger.logError(LOG_TAG, "Error getting boolean value for the \"" + key + "\" key from null shared preferences. Returning default value \"" + def + "\".");
return def;
}
@@ -78,12 +78,12 @@ public class SharedPreferenceUtils {
*/
@SuppressLint("ApplySharedPref")
public static void setBoolean(SharedPreferences sharedPreferences, String key, boolean value, boolean commitToFile) {
if(sharedPreferences == null) {
if (sharedPreferences == null) {
Logger.logError(LOG_TAG, "Ignoring setting boolean value \"" + value + "\" for the \"" + key + "\" key into null shared preferences.");
return;
}
if(commitToFile)
if (commitToFile)
sharedPreferences.edit().putBoolean(key, value).commit();
else
sharedPreferences.edit().putBoolean(key, value).apply();
@@ -102,7 +102,7 @@ public class SharedPreferenceUtils {
* default if failed to read a valid value, like in case of an exception.
*/
public static float getFloat(SharedPreferences sharedPreferences, String key, float def) {
if(sharedPreferences == null) {
if (sharedPreferences == null) {
Logger.logError(LOG_TAG, "Error getting float value for the \"" + key + "\" key from null shared preferences. Returning default value \"" + def + "\".");
return def;
}
@@ -128,12 +128,12 @@ public class SharedPreferenceUtils {
*/
@SuppressLint("ApplySharedPref")
public static void setFloat(SharedPreferences sharedPreferences, String key, float value, boolean commitToFile) {
if(sharedPreferences == null) {
if (sharedPreferences == null) {
Logger.logError(LOG_TAG, "Ignoring setting float value \"" + value + "\" for the \"" + key + "\" key into null shared preferences.");
return;
}
if(commitToFile)
if (commitToFile)
sharedPreferences.edit().putFloat(key, value).commit();
else
sharedPreferences.edit().putFloat(key, value).apply();
@@ -151,7 +151,7 @@ public class SharedPreferenceUtils {
* default if failed to read a valid value, like in case of an exception.
*/
public static int getInt(SharedPreferences sharedPreferences, String key, int def) {
if(sharedPreferences == null) {
if (sharedPreferences == null) {
Logger.logError(LOG_TAG, "Error getting int value for the \"" + key + "\" key from null shared preferences. Returning default value \"" + def + "\".");
return def;
}
@@ -177,12 +177,12 @@ public class SharedPreferenceUtils {
*/
@SuppressLint("ApplySharedPref")
public static void setInt(SharedPreferences sharedPreferences, String key, int value, boolean commitToFile) {
if(sharedPreferences == null) {
if (sharedPreferences == null) {
Logger.logError(LOG_TAG, "Ignoring setting int value \"" + value + "\" for the \"" + key + "\" key into null shared preferences.");
return;
}
if(commitToFile)
if (commitToFile)
sharedPreferences.edit().putInt(key, value).commit();
else
sharedPreferences.edit().putInt(key, value).apply();
@@ -200,7 +200,7 @@ public class SharedPreferenceUtils {
* default if failed to read a valid value, like in case of an exception.
*/
public static long getLong(SharedPreferences sharedPreferences, String key, long def) {
if(sharedPreferences == null) {
if (sharedPreferences == null) {
Logger.logError(LOG_TAG, "Error getting long value for the \"" + key + "\" key from null shared preferences. Returning default value \"" + def + "\".");
return def;
}
@@ -226,12 +226,12 @@ public class SharedPreferenceUtils {
*/
@SuppressLint("ApplySharedPref")
public static void setLong(SharedPreferences sharedPreferences, String key, long value, boolean commitToFile) {
if(sharedPreferences == null) {
if (sharedPreferences == null) {
Logger.logError(LOG_TAG, "Ignoring setting long value \"" + value + "\" for the \"" + key + "\" key into null shared preferences.");
return;
}
if(commitToFile)
if (commitToFile)
sharedPreferences.edit().putLong(key, value).commit();
else
sharedPreferences.edit().putLong(key, value).apply();
@@ -249,7 +249,7 @@ public class SharedPreferenceUtils {
* default if failed to read a valid value, like in case of an exception.
*/
public static String getString(SharedPreferences sharedPreferences, String key, String def) {
if(sharedPreferences == null) {
if (sharedPreferences == null) {
Logger.logError(LOG_TAG, "Error getting String value for the \"" + key + "\" key from null shared preferences. Returning default value \"" + def + "\".");
return def;
}
@@ -275,12 +275,12 @@ public class SharedPreferenceUtils {
*/
@SuppressLint("ApplySharedPref")
public static void setString(SharedPreferences sharedPreferences, String key, String value, boolean commitToFile) {
if(sharedPreferences == null) {
if (sharedPreferences == null) {
Logger.logError(LOG_TAG, "Ignoring setting String value \"" + value + "\" for the \"" + key + "\" key into null shared preferences.");
return;
}
if(commitToFile)
if (commitToFile)
sharedPreferences.edit().putString(key, value).commit();
else
sharedPreferences.edit().putString(key, value).apply();
@@ -298,7 +298,7 @@ public class SharedPreferenceUtils {
* default if failed to read a valid value, like in case of an exception.
*/
public static Set<String> getStringSet(SharedPreferences sharedPreferences, String key, Set<String> def) {
if(sharedPreferences == null) {
if (sharedPreferences == null) {
Logger.logError(LOG_TAG, "Error getting Set<String> value for the \"" + key + "\" key from null shared preferences. Returning default value \"" + def + "\".");
return def;
}
@@ -324,12 +324,12 @@ public class SharedPreferenceUtils {
*/
@SuppressLint("ApplySharedPref")
public static void setStringSet(SharedPreferences sharedPreferences, String key, Set<String> value, boolean commitToFile) {
if(sharedPreferences == null) {
if (sharedPreferences == null) {
Logger.logError(LOG_TAG, "Ignoring setting Set<String> value \"" + value + "\" for the \"" + key + "\" key into null shared preferences.");
return;
}
if(commitToFile)
if (commitToFile)
sharedPreferences.edit().putStringSet(key, value).commit();
else
sharedPreferences.edit().putStringSet(key, value).apply();
@@ -348,7 +348,7 @@ public class SharedPreferenceUtils {
* like in case of an exception.
*/
public static int getIntStoredAsString(SharedPreferences sharedPreferences, String key, int def) {
if(sharedPreferences == null) {
if (sharedPreferences == null) {
Logger.logError(LOG_TAG, "Error getting int value for the \"" + key + "\" key from null shared preferences. Returning default value \"" + def + "\".");
return def;
}
@@ -358,7 +358,7 @@ public class SharedPreferenceUtils {
try {
stringValue = sharedPreferences.getString(key, Integer.toString(def));
if(stringValue != null)
if (stringValue != null)
intValue = Integer.parseInt(stringValue);
else
intValue = def;
@@ -381,12 +381,12 @@ public class SharedPreferenceUtils {
*/
@SuppressLint("ApplySharedPref")
public static void setIntStoredAsString(SharedPreferences sharedPreferences, String key, int value, boolean commitToFile) {
if(sharedPreferences == null) {
if (sharedPreferences == null) {
Logger.logError(LOG_TAG, "Ignoring setting int value \"" + value + "\" for the \"" + key + "\" key into null shared preferences.");
return;
}
if(commitToFile)
if (commitToFile)
sharedPreferences.edit().putString(key, Integer.toString(value)).commit();
else
sharedPreferences.edit().putString(key, Integer.toString(value)).apply();

View File

@@ -38,7 +38,7 @@ public class TermuxTaskerAppSharedPreferences {
public int getLogLevel(boolean readFromFfile) {
if(readFromFfile)
if (readFromFfile)
return SharedPreferenceUtils.getInt(mMultiProcessSharedPreferences, TERMUX_TASKER_APP.KEY_LOG_LEVEL, Logger.DEFAULT_LOG_LEVEL);
else
return SharedPreferenceUtils.getInt(mSharedPreferences, TERMUX_TASKER_APP.KEY_LOG_LEVEL, Logger.DEFAULT_LOG_LEVEL);

View File

@@ -145,7 +145,7 @@ public class TermuxUtils {
String termuxPackageName = null;
String termuxAppName = null;
if(termuxPackageContext != null) {
if (termuxPackageContext != null) {
termuxPackageName = PackageUtils.getPackageNameForPackage(termuxPackageContext);
termuxAppName = PackageUtils.getAppNameForPackage(termuxPackageContext);
}
@@ -156,13 +156,13 @@ public class TermuxUtils {
boolean isTermuxPackage = (termuxPackageName != null && termuxPackageName.equals(currentPackageName));
if(returnTermuxPackageInfoToo && !isTermuxPackage)
if (returnTermuxPackageInfoToo && !isTermuxPackage)
markdownString.append("## ").append(currentAppName).append(" App Info (Current)\n");
else
markdownString.append("## ").append(currentAppName).append(" App Info\n");
markdownString.append(getAppInfoMarkdownStringInner(currentPackageContext));
if(returnTermuxPackageInfoToo && !isTermuxPackage) {
if (returnTermuxPackageInfoToo && !isTermuxPackage) {
markdownString.append("\n\n## ").append(termuxAppName).append(" App Info\n");
markdownString.append(getAppInfoMarkdownStringInner(termuxPackageContext));
}
@@ -284,6 +284,8 @@ public class TermuxUtils {
return markdownString.toString();
}
public static Properties getSystemProperties() {
Properties systemProperties = new Properties();
@@ -311,7 +313,7 @@ public class TermuxUtils {
if (matcher.matches()) {
key = matcher.group(1);
value = matcher.group(2);
if(key != null && value != null && !key.isEmpty() && !value.isEmpty())
if (key != null && value != null && !key.isEmpty() && !value.isEmpty())
systemProperties.put(key, value);
}
}
@@ -340,8 +342,8 @@ public class TermuxUtils {
}
private static void appendPropertyToMarkdownIfSet(StringBuilder markdownString, String label, Object value) {
if(value == null) return;
if(value instanceof String && (((String) value).isEmpty()) || "REL".equals(value)) return;
if (value == null) return;
if (value instanceof String && (((String) value).isEmpty()) || "REL".equals(value)) return;
markdownString.append("\n").append(getPropertyMarkdown(label, value));
}