Skip to content

Commit

Permalink
Fix some code style with empty strings.
Browse files Browse the repository at this point in the history
  • Loading branch information
ikarus23 committed Aug 31, 2024
1 parent 0473549 commit 16b7efe
Show file tree
Hide file tree
Showing 10 changed files with 22 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public void onConvert(View view) {
* @param hex The hex string to be converted into different formats.
*/
private void convertData(String hex) {
if (hex == null || hex.equals("")) {
if (hex == null || hex.isEmpty()) {
Toast.makeText(this, R.string.info_convert_error,
Toast.LENGTH_SHORT).show();
return;
Expand Down Expand Up @@ -126,7 +126,7 @@ private boolean isBin(String bin, Context context) {
*/
public void onOpenGenericConverter(View view) {
String hex = mHex.getText().toString();
if (!hex.equals("") && !Common.isHex(hex, this)) {
if (!hex.isEmpty() && !Common.isHex(hex, this)) {
return;
}
String url = "https://hexconverter.scadacore.com/?HexString=" + hex;
Expand Down Expand Up @@ -154,7 +154,7 @@ public void onOpenMultiPurposeConverter(View view) {
*/
public void onOpenCyberChef(View view) {
String hex = mHex.getText().toString();
if (!hex.equals("") && !Common.isHex(hex, this)) {
if (!hex.isEmpty() && !Common.isHex(hex, this)) {
return;
}
String base64 = Base64.encodeToString(hex.getBytes(), Base64.DEFAULT);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,7 @@ private void saveFile(final String[] data, final String fileName,
.setPositiveButton(R.string.action_save,
(dialog, whichButton) -> {
if (input.getText() != null
&& !input.getText().toString().equals("")
&& !input.getText().toString().isEmpty()
&& !input.getText().toString().contains("/")) {
File file = new File(path.getPath(),
input.getText().toString());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ private void onNewFile() {
.setPositiveButton(R.string.action_ok,
(dialog, whichButton) -> {
if (input.getText() != null
&& !input.getText().toString().equals("")
&& !input.getText().toString().isEmpty()
&& !input.getText().toString().contains("/")) {
File file = new File(mDir.getPath(),
input.getText().toString());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -599,7 +599,7 @@ private String[] convertDump(String[] source, FileType srcType,
return null;
}
for (int i = 0; i < source.length; i++) {
if (source[i].equals("")) {
if (source[i].isEmpty()) {
// Error. Empty line in .eml file.
Toast.makeText(this, R.string.info_incomplete_dump,
Toast.LENGTH_LONG).show();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ private File saveKeysToTemp() {
// Save key file to to a temporary file which will be
// attached for sharing (and stored in the tmp folder).
String fileName;
if (mFileName.equals("")) {
if (mFileName.isEmpty()) {
// The key file has no name. Use date and time as name.
GregorianCalendar calendar = new GregorianCalendar();
SimpleDateFormat fmt = new SimpleDateFormat("yyyy-MM-dd_HH-mm-ss",
Expand Down Expand Up @@ -342,7 +342,7 @@ private void onSave() {
* File, String[], boolean, Context, IActivityThatReactsToSave)
*/
private void saveFile(String fileName, File path) {
if (fileName == null || fileName.equals("") || fileName.contains("/")) {
if (fileName == null || fileName.isEmpty() || fileName.contains("/")) {
Toast.makeText(this, R.string.info_invalid_file_name,
Toast.LENGTH_LONG).show();
return;
Expand All @@ -365,7 +365,7 @@ private void removeDuplicates() {
ArrayList<String> newLines = new ArrayList<>();
for (String line : mLines) {
line = line.trim();
if (line.equals("") || line.startsWith("#")) {
if (line.isEmpty() || line.startsWith("#")) {
// Add comments for sure.
newLines.add(line);
continue;
Expand Down Expand Up @@ -435,7 +435,7 @@ private int checkDumpAndUpdateLines() {
}
line = line.split("#")[0];
line = line.trim();
if (line.equals("")) {
if (line.isEmpty()) {
mLines[i] = lines[i];
continue;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,10 +176,10 @@ public void onCreate(Bundle savedInstanceState) {
String from = sharedPref.getString("default_mapping_range_from", "");
String to = sharedPref.getString("default_mapping_range_to", "");
// Are there default values?
if (!from.equals("")) {
if (!from.isEmpty()) {
custom = true;
}
if (!to.equals("")) {
if (!to.isEmpty()) {
custom = true;
}
// Are there given values?
Expand Down Expand Up @@ -606,12 +606,12 @@ public void onChangeSectorRange(View view) {
String txtFrom = "" + DEFAULT_SECTOR_RANGE_FROM;
String txtTo = "" + DEFAULT_SECTOR_RANGE_TO;
boolean noFrom = false;
if (!from.getText().toString().equals("")) {
if (!from.getText().toString().isEmpty()) {
txtFrom = from.getText().toString();
} else {
noFrom = true;
}
if (!to.getText().toString().equals("")) {
if (!to.getText().toString().isEmpty()) {
txtTo = to.getText().toString();
} else if (noFrom) {
// No values provided. Read all sectors.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public void onDecode(View view) {
public void onEncode(View view) {
String vbText = mVBasInt.getText().toString();
String addrText = mAddr.getText().toString();
if (vbText.equals("")){
if (vbText.isEmpty()){
// Error. There is no integer to encode.
Toast.makeText(this, R.string.info_no_int_to_encode,
Toast.LENGTH_LONG).show();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -346,8 +346,8 @@ public void onWriteBlock(View view) {
* @return True if both values are okay. False otherwise.
*/
private boolean checkSectorAndBlock(EditText sector, EditText block) {
if (sector.getText().toString().equals("")
|| block.getText().toString().equals("")) {
if (sector.getText().toString().isEmpty()
|| block.getText().toString().isEmpty()) {
// Error, location not fully set.
Toast.makeText(this, R.string.info_data_location_not_set,
Toast.LENGTH_LONG).show();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,7 @@ private static String[] readLineByLine(BufferedReader reader,
line = line.trim();
// Remove comments if readAll is false.
if (!readAll) {
if (line.startsWith("#") || line.equals("")) {
if (line.startsWith("#") || line.isEmpty()) {
continue;
}
// Look for content (ignore the comment).
Expand Down Expand Up @@ -1513,7 +1513,7 @@ public static int isValidKeyFile(String[] lines) {
line = line.trim();

// Ignore empty lines.
if (line.equals("")) {
if (line.isEmpty()) {
continue;
}

Expand Down Expand Up @@ -1852,7 +1852,7 @@ public static String hex2Ascii(String hex) {
* @return Converted hex string.
*/
public static String ascii2Hex(String ascii) {
if (!(ascii != null && !ascii.equals(""))) {
if (!(ascii != null && !ascii.isEmpty())) {
return null;
}
char[] chars = ascii.toCharArray();
Expand Down Expand Up @@ -1932,7 +1932,7 @@ public static int getThemeAccentColor (final Context context) {
*/
public static void copyToClipboard(String text, Context context,
boolean showMsg) {
if (!text.equals("")) {
if (!text.isEmpty()) {
android.content.ClipboardManager clipboard =
(android.content.ClipboardManager)
context.getSystemService(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -831,7 +831,7 @@ public int setKeyFile(File[] keyFiles, Context context) {
String[] lines = Common.readFileLineByLine(file, false, context);
if (lines != null) {
for (String line : lines) {
if (!line.equals("") && line.length() == 12
if (!line.isEmpty() && line.length() == 12
&& line.matches("[0-9A-Fa-f]+")) {
try {
keys.add(line);
Expand Down

0 comments on commit 16b7efe

Please sign in to comment.