Skip to content

Commit

Permalink
Merge pull request thunderbird#3588 from k9mail/simplify_if_statements
Browse files Browse the repository at this point in the history
[Cleanup] Simplify if statements
  • Loading branch information
cketti authored Sep 2, 2018
2 parents 9c9b3e3 + dbea2ca commit ae76f07
Show file tree
Hide file tree
Showing 12 changed files with 19 additions and 68 deletions.
5 changes: 1 addition & 4 deletions app/core/src/main/java/com/fsck/k9/Account.java
Original file line number Diff line number Diff line change
Expand Up @@ -1047,10 +1047,7 @@ public synchronized boolean setFolderSyncMode(FolderMode syncMode) {
if (syncMode == FolderMode.NONE && oldSyncMode != FolderMode.NONE) {
return true;
}
if (syncMode != FolderMode.NONE && oldSyncMode == FolderMode.NONE) {
return true;
}
return false;
return syncMode != FolderMode.NONE && oldSyncMode == FolderMode.NONE;
}

public synchronized FolderMode getFolderPushMode() {
Expand Down
10 changes: 2 additions & 8 deletions app/core/src/main/java/com/fsck/k9/QuietTimeChecker.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,9 @@ public boolean isQuietTime() {
int minutesSinceMidnight = (calendar.get(Calendar.HOUR_OF_DAY) * 60) + calendar.get(Calendar.MINUTE);

if (quietTimeStart > quietTimeEnd) {
if (minutesSinceMidnight >= quietTimeStart || minutesSinceMidnight <= quietTimeEnd) {
return true;
}
return minutesSinceMidnight >= quietTimeStart || minutesSinceMidnight <= quietTimeEnd;
} else {
if (minutesSinceMidnight >= quietTimeStart && minutesSinceMidnight <= quietTimeEnd) {
return true;
}
return minutesSinceMidnight >= quietTimeStart && minutesSinceMidnight <= quietTimeEnd;
}

return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,7 @@ public boolean equals(Object o) {
if (!Arrays.equals(keyData, that.keyData)) {
return false;
}
if (!addr.equals(that.addr)) {
return false;
}

return true;
return addr.equals(that.addr);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2733,11 +2733,7 @@ public boolean shouldNotifyForMessage(Account account, LocalFolder localFolder,
return false;
}

if (account.isNotifyContactsMailOnly() && !contacts.isAnyInContacts(message.getFrom())) {
return false;
}

return true;
return !account.isNotifyContactsMailOnly() || contacts.isAnyInContacts(message.getFrom());
}

public void deleteAccount(Account account) {
Expand Down
20 changes: 4 additions & 16 deletions app/core/src/main/java/com/fsck/k9/helper/MergeCursor.java
Original file line number Diff line number Diff line change
Expand Up @@ -224,20 +224,14 @@ public void setExtras(Bundle extras) {
@Override
public boolean isAfterLast() {
int count = getCount();
if (count == 0) {
return true;
}
return count == 0 || mPosition == count;

return (mPosition == count);
}

@Override
public boolean isBeforeFirst() {
if (getCount() == 0) {
return true;
}
return getCount() == 0 || mPosition == -1;

return (mPosition == -1);
}

@Override
Expand All @@ -247,21 +241,15 @@ public boolean isClosed() {

@Override
public boolean isFirst() {
if (getCount() == 0) {
return false;
}
return getCount() != 0 && mPosition == 0;

return (mPosition == 0);
}

@Override
public boolean isLast() {
int count = getCount();
if (count == 0) {
return false;
}
return count != 0 && mPosition == count - 1;

return (mPosition == (count - 1));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,11 +128,9 @@ public String toHumanString() {
public boolean equals(Object o) {
if (o instanceof SearchCondition) {
SearchCondition tmp = (SearchCondition) o;
if (tmp.attribute == attribute &&
return tmp.attribute == attribute &&
tmp.field == field &&
tmp.value.equals(value)) {
return true;
}
tmp.value.equals(value);
}

return false;
Expand Down
6 changes: 2 additions & 4 deletions app/ui/src/main/java/com/fsck/k9/activity/MessageCompose.java
Original file line number Diff line number Diff line change
Expand Up @@ -1055,10 +1055,8 @@ private boolean draftIsNotEmpty() {
if (!attachmentPresenter.createAttachmentList().isEmpty()) {
return true;
}
if (subjectView.getText().length() != 0) {
return true;
}
return !recipientPresenter.getToAddresses().isEmpty() ||
return subjectView.getText().length() != 0 ||
!recipientPresenter.getToAddresses().isEmpty() ||
!recipientPresenter.getCcAddresses().isEmpty() ||
!recipientPresenter.getBccAddresses().isEmpty();
}
Expand Down
5 changes: 1 addition & 4 deletions app/ui/src/main/java/com/fsck/k9/view/MessageHeader.java
Original file line number Diff line number Diff line change
Expand Up @@ -354,10 +354,7 @@ public static boolean shouldShowSender(Message message) {
Address[] from = message.getFrom();
Address[] sender = message.getSender();

if (sender == null || sender.length == 0) {
return false;
}
return !Arrays.equals(from, sender);
return sender != null && sender.length != 0 && !Arrays.equals(from, sender);
}

public void hideCryptoStatus() {
Expand Down
5 changes: 1 addition & 4 deletions mail/common/src/main/java/com/fsck/k9/mail/Message.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,7 @@ public boolean olderThan(Date earliestDate) {
if (myDate == null) {
myDate = getInternalDate();
}
if (myDate != null) {
return myDate.before(earliestDate);
}
return false;
return myDate != null && myDate.before(earliestDate);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,6 @@ private static boolean isInDomain(String address, String domain) {
}

char c = address.charAt(index);
if (c != '@' && c != '.') {
return false;
}

return address.endsWith(domain);
return (c == '@' || c == '.') && address.endsWith(domain);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -450,11 +450,8 @@ private static Boolean isPartTextualBody(Part part) throws MessagingException {
}

boolean isAttachmentDisposition = "attachment".equalsIgnoreCase(dispositionType) || dispositionFilename != null;
if (isAttachmentDisposition) {
return false;
}

return part.isMimeType("text/html") || part.isMimeType("text/plain") || part.isMimeType("application/pgp");
return !isAttachmentDisposition &&
(part.isMimeType("text/html") || part.isMimeType("text/plain") || part.isMimeType("application/pgp"));

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -473,11 +473,8 @@ private boolean isStatusResponse(String symbol) {
}

public static boolean equalsIgnoreCase(Object token, String symbol) {
if (token == null || !(token instanceof String)) {
return false;
}
return token instanceof String && symbol.equalsIgnoreCase((String) token);

return symbol.equalsIgnoreCase((String) token);
}

private void checkTokenIsString(Object token) throws IOException {
Expand Down

0 comments on commit ae76f07

Please sign in to comment.